summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-04-09 14:43:36 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2023-04-09 15:04:19 +0300
commitc78435a6fe6d5397d190f0e620ebbbfb261d01c6 (patch)
treeeec3cd2058f64d5a916dc66eacb687f47cdd8644
parent8e9579055f6efea343bbc1ca7c1422b99be63257 (diff)
tests: always log to file during tests
And set the cachedir (for logging and other things) to a random tmpdir.
-rw-r--r--lib/utils/mu-test-utils.cc3
-rw-r--r--mu/mu.cc3
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/utils/mu-test-utils.cc b/lib/utils/mu-test-utils.cc
index 4a0288a..702548f 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 c4cd1c3..860e1ea 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);