From a2e6316eae064cb283beb481d2135f5188d0bd9a Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 7 Aug 2021 13:12:56 +0200 Subject: [PATCH] =?utf8?q?fix:=20Don=E2=80=99t=20read=20let=20Context=20re?= =?utf8?q?ad=20user=20configuration=20in=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 5 +++++ src/Context.hpp | 4 ++++ src/ccache.cpp | 1 + 3 files changed, 10 insertions(+) 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); }); -- 2.47.2