diff --git a/tom/include/tom/application.hpp b/tom/include/tom/application.hpp index dbe100988..2765a8996 100644 --- a/tom/include/tom/application.hpp +++ b/tom/include/tom/application.hpp @@ -317,6 +317,10 @@ namespace Concerns public: /*! Run the tom application with the given arguments (used in auto tests). */ int runWithArguments(QStringList &&arguments); + + private: + /*! Is enabled logic for unit testing? */ + inline static bool inUnitTests() noexcept; #endif }; diff --git a/tom/include/tom/commands/command.hpp b/tom/include/tom/commands/command.hpp index 76852f281..51d03ff41 100644 --- a/tom/include/tom/commands/command.hpp +++ b/tom/include/tom/commands/command.hpp @@ -145,6 +145,12 @@ namespace Commands /*! Get database connection resolver. */ std::shared_ptr connectionResolver() const noexcept; + /* Auto tests helpers */ +#ifdef TINYTOM_TESTS_CODE + /*! Is enabled logic for unit testing? */ + bool inUnitTests() const noexcept; +#endif + /* Data members */ /*! Reference to the tom application. */ std::reference_wrapper m_application; diff --git a/tom/include/tom/commands/migrations/statuscommand.hpp b/tom/include/tom/commands/migrations/statuscommand.hpp index 8def42ebe..018354ce2 100644 --- a/tom/include/tom/commands/migrations/statuscommand.hpp +++ b/tom/include/tom/commands/migrations/statuscommand.hpp @@ -61,8 +61,6 @@ namespace Commands::Migrations /*! Get result of the status command (used in auto tests). */ inline static std::vector status(); - /*! Enable logic for unit testing? */ - inline static void setInUnitTests() noexcept; #endif protected: @@ -83,9 +81,6 @@ namespace Commands::Migrations /*! Result of the status command (used in auto tests). */ T_THREAD_LOCAL inline static std::vector m_status; - /*! Is enabled logic for unit testing? */ - T_THREAD_LOCAL - inline static auto m_inUnitTests = false; #endif }; @@ -106,11 +101,6 @@ namespace Commands::Migrations { return m_status; } - - void StatusCommand::setInUnitTests() noexcept - { - m_inUnitTests = true; - } #endif } // namespace Commands::Migrations diff --git a/tom/src/tom/application.cpp b/tom/src/tom/application.cpp index 0433ef7c1..e75b6a843 100644 --- a/tom/src/tom/application.cpp +++ b/tom/src/tom/application.cpp @@ -261,8 +261,6 @@ std::vector Application::status() void Application::enableInUnitTests() noexcept { g_inUnitTests = true; - - StatusCommand::setInUnitTests(); } #endif @@ -828,6 +826,13 @@ int Application::runWithArguments(QStringList &&arguments) // Ownership of a unique_ptr() return createCommand(getCommandName())->runWithArguments(std::move(arguments)); } + +/* private */ + +bool Application::inUnitTests() noexcept +{ + return g_inUnitTests; +} #endif } // namespace Tom diff --git a/tom/src/tom/commands/command.cpp b/tom/src/tom/commands/command.cpp index 8ef014384..842613323 100644 --- a/tom/src/tom/commands/command.cpp +++ b/tom/src/tom/commands/command.cpp @@ -336,6 +336,15 @@ Command::connectionResolver() const noexcept return application().connectionResolver(); } +/* Auto tests helpers */ + +#ifdef TINYTOM_TESTS_CODE +bool Command::inUnitTests() const noexcept +{ + return application().inUnitTests(); +} +#endif + /* private */ void Command::initializePositionalArguments() diff --git a/tom/src/tom/commands/migrations/statuscommand.cpp b/tom/src/tom/commands/migrations/statuscommand.cpp index 674f2f760..9cd4fd67c 100644 --- a/tom/src/tom/commands/migrations/statuscommand.cpp +++ b/tom/src/tom/commands/migrations/statuscommand.cpp @@ -73,7 +73,7 @@ int StatusCommand::run() /* During testing save the result of a status command to the global variable instead of outputting it, to be able to verify results. */ #ifdef TINYTOM_TESTS_CODE - if (m_inUnitTests) + if (inUnitTests()) m_status = statusForUnitTest(std::move(migrations)); else #endif @@ -83,7 +83,7 @@ int StatusCommand::run() } #ifdef TINYTOM_TESTS_CODE - if (m_inUnitTests) + if (inUnitTests()) m_status.clear(); #endif