From c78435a6fe6d5397d190f0e620ebbbfb261d01c6 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 9 Apr 2023 14:43:36 +0300 Subject: [PATCH] tests: always log to file during tests And set the cachedir (for logging and other things) to a random tmpdir. --- lib/utils/mu-test-utils.cc | 3 +++ mu/mu.cc | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils/mu-test-utils.cc b/lib/utils/mu-test-utils.cc index 4a0288a4..702548f3 100644 --- a/lib/utils/mu-test-utils.cc +++ b/lib/utils/mu-test-utils.cc @@ -93,7 +93,10 @@ black_hole(void) void Mu::mu_test_init(int *argc, char ***argv) { + const auto tmpdir{test_random_tmpdir()}; + g_setenv("MU_TEST", "yes", TRUE); + g_setenv("XDG_CACHE_HOME", tmpdir.c_str(), TRUE); g_test_init(argc, argv, NULL); diff --git a/mu/mu.cc b/mu/mu.cc index c4cd1c34..860e1eac 100644 --- a/mu/mu.cc +++ b/mu/mu.cc @@ -104,7 +104,6 @@ main(int argc, char* argv[]) * there's a subcommand */ - /* * set up logging */ @@ -113,6 +112,8 @@ main(int argc, char* argv[]) lopts |= Logger::Options::StdOutErr; if (opts->debug) lopts |= Logger::Options::Debug; + if (g_getenv("MU_TEST")) + lopts |= Logger::Options::File; const auto logger = Logger::make(opts->runtime_path(RuntimePath::LogFile), lopts);