]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Don’t read let Context read user configuration in unit tests
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 7 Aug 2021 11:12:56 +0000 (13:12 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 7 Aug 2021 11:25:24 +0000 (13:25 +0200)
accd21e4 inadvertently made unit tests populate Context::config from the
environment and the user configuration. Fix this by moving code for
reading config, setting of logging, etc. into a separate method only to
be called by non-test code.

As noted by Michael Kruse in #815.

src/Context.cpp
src/Context.hpp
src/ccache.cpp

index bccf632f8a9c92c5c30934143444393eb0b59f8c..bcfff8c78a46d97b4bc21340510ebc7ed4f008bf 100644 (file)
@@ -44,6 +44,11 @@ Context::Context()
     ,
     inode_cache(config)
 #endif
+{
+}
+
+void
+Context::initialize()
 {
   config.read();
   Logging::init(config);
index ce40a087093f8caa6dec6a769e8e9b66d8421cec..547db9d3cf16d67d5f2f7909ee91c5a7e62c96e1 100644 (file)
@@ -48,6 +48,10 @@ public:
   Context();
   ~Context();
 
+  // Read configuration, initialize logging, etc. Typically not called from unit
+  // tests.
+  void initialize();
+
   ArgsInfo args_info;
   Config config;
 
index 357df19bccb05d916386e7623baefd8c91f4dba4..1332d7d8b33364bebf6a4c60cf627c8b729dfcc1 100644 (file)
@@ -1891,6 +1891,7 @@ cache_compilation(int argc, const char* const* argv)
 
   {
     Context ctx;
+    ctx.initialize();
     SignalHandler signal_handler(ctx);
     Finalizer finalizer([&ctx] { finalize_at_exit(ctx); });