tom enhanced in unit tests check

Dropped a flag in the StatusCommand and used in unit tests flag defined
in the TomApplication.
This commit is contained in:
silverqx
2023-10-06 20:15:25 +02:00
parent 6b4cb526d4
commit bd424cc9df
6 changed files with 28 additions and 14 deletions
+4
View File
@@ -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
};
+6
View File
@@ -145,6 +145,12 @@ namespace Commands
/*! Get database connection resolver. */
std::shared_ptr<ConnectionResolverInterface> 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<Application> m_application;
@@ -61,8 +61,6 @@ namespace Commands::Migrations
/*! Get result of the status command (used in auto tests). */
inline static std::vector<StatusRow> 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<StatusRow> 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
+7 -2
View File
@@ -261,8 +261,6 @@ std::vector<Application::StatusRow> 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
+9
View File
@@ -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()
@@ -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