From f487f592fdc85fbdb95856abb7f4281dd4353da9 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 12 Mar 2024 19:23:12 +0100 Subject: 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. --- test/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/main.cpp') 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 +#include + #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); } -- cgit v1.2.3