From: Joel Rosdahl Date: Sat, 7 Aug 2021 11:12:56 +0000 (+0200) Subject: fix: Don’t read let Context read user configuration in unit tests X-Git-Tag: v4.4~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2e6316eae064cb283beb481d2135f5188d0bd9a;p=thirdparty%2Fccache.git fix: Don’t read let Context read user configuration in unit tests 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. --- diff --git a/src/Context.cpp b/src/Context.cpp index bccf632f8..bcfff8c78 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -44,6 +44,11 @@ Context::Context() , inode_cache(config) #endif +{ +} + +void +Context::initialize() { config.read(); Logging::init(config); diff --git a/src/Context.hpp b/src/Context.hpp index ce40a0870..547db9d3c 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -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; diff --git a/src/ccache.cpp b/src/ccache.cpp index 357df19bc..1332d7d8b 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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); });