diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-12 19:23:12 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-03-12 19:26:41 +0100 |
commit | f487f592fdc85fbdb95856abb7f4281dd4353da9 (patch) | |
tree | c8c6527220b213c38dacd9cb111894dc68938cb4 /test/main.cpp | |
parent | 1b06ca716eaa23dfa2d521aebb2a4098e4dc8a46 (diff) | |
download | justbuild-f487f592fdc85fbdb95856abb7f4281dd4353da9.tar.gz |
catch2 main: ensure proper build root
Some of our C-tests under catch2 may rely on the local build root
to get a proper tmp directory; ensure this is set properly to avoid
falling back to the user's home directory.
Diffstat (limited to 'test/main.cpp')
-rw-r--r-- | test/main.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/main.cpp b/test/main.cpp index bb431de2..1c685447 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include <cstdlib> +#include <filesystem> + #include "catch2/catch_session.hpp" #include "src/buildtool/file_system/git_context.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/utils/logging/log_config.hpp" auto main(int argc, char* argv[]) -> int { @@ -27,5 +31,17 @@ auto main(int argc, char* argv[]) -> int { */ GitContext::Create(); + /** + * Test must not assume the existence of a home directory, nor write there. + * Hence we set the storage root to a fixed location under TEST_TMPDIR which + * is set by the test launcher. + */ + auto setup_ok = StorageConfig::SetBuildRoot( + std::filesystem::path{std::string{std::getenv("TEST_TMPDIR")}} / + ".test_build_root"); + if (not setup_ok) { + return 1; + } + return Catch::Session().run(argc, argv); } |