mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#687) Improved launch of unit tests from command line
This commit is contained in:
parent
97b95216e9
commit
d2537a207f
@ -208,6 +208,35 @@ RiaApplication* RiaApplication::instance()
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return -1 if unit test is not executed, returns 0 if test passed, returns 1 if tests failed
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaApplication::parseArgumentsAndRunUnitTestsIfRequested()
|
||||
{
|
||||
cvf::ProgramOptions progOpt;
|
||||
progOpt.registerOption("unittest", "", "Execute unit tests");
|
||||
progOpt.setOptionPrefix(cvf::ProgramOptions::DOUBLE_DASH);
|
||||
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
|
||||
bool parseOk = progOpt.parse(cvfqt::Utils::toStringVector(arguments));
|
||||
if (!parseOk)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Unit testing
|
||||
// --------------------------------------------------------
|
||||
if (cvf::Option o = progOpt.option("unittest"))
|
||||
{
|
||||
int testReturnValue = launchUnitTestsWithConsole();
|
||||
|
||||
return testReturnValue;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -1149,34 +1178,32 @@ bool RiaApplication::parseArguments()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unit testing
|
||||
// --------------------------------------------------------
|
||||
if (cvf::Option o = progOpt.option("unittest"))
|
||||
{
|
||||
launchUnitTests();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::launchUnitTests()
|
||||
int RiaApplication::launchUnitTests()
|
||||
{
|
||||
cvf::Assert::setReportMode(cvf::Assert::CONSOLE);
|
||||
|
||||
int argc = QCoreApplication::argc();
|
||||
testing::InitGoogleTest(&argc, QCoreApplication::argv());
|
||||
|
||||
//int result = RUN_ALL_TESTS();
|
||||
RUN_ALL_TESTS();
|
||||
// Use this macro in main() to run all tests. It returns 0 if all
|
||||
// tests are successful, or 1 otherwise.
|
||||
//
|
||||
// RUN_ALL_TESTS() should be invoked after the command line has been
|
||||
// parsed by InitGoogleTest().
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::launchUnitTestsWithConsole()
|
||||
int RiaApplication::launchUnitTestsWithConsole()
|
||||
{
|
||||
// Following code is taken from cvfAssert.cpp
|
||||
#ifdef WIN32
|
||||
@ -1224,7 +1251,7 @@ void RiaApplication::launchUnitTestsWithConsole()
|
||||
}
|
||||
#endif
|
||||
|
||||
launchUnitTests();
|
||||
return launchUnitTests();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
~RiaApplication();
|
||||
static RiaApplication* instance();
|
||||
|
||||
int parseArgumentsAndRunUnitTestsIfRequested();
|
||||
bool parseArguments();
|
||||
|
||||
void executeRegressionTests(const QString& regressionTestPath);
|
||||
@ -159,8 +160,8 @@ public:
|
||||
|
||||
bool isRunningRegressionTests() const;
|
||||
|
||||
void launchUnitTests();
|
||||
void launchUnitTestsWithConsole();
|
||||
int launchUnitTests();
|
||||
int launchUnitTestsWithConsole();
|
||||
|
||||
private:
|
||||
enum ProjectLoadAction
|
||||
|
@ -26,6 +26,12 @@ int main(int argc, char *argv[])
|
||||
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
||||
setlocale(LC_NUMERIC,"C");
|
||||
|
||||
int unitTestResult = app.parseArgumentsAndRunUnitTestsIfRequested();
|
||||
if (unitTestResult > -1)
|
||||
{
|
||||
return unitTestResult;
|
||||
}
|
||||
|
||||
RiuMainWindow window;
|
||||
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
|
||||
window.setWindowTitle("ResInsight " + platform);
|
||||
|
Loading…
Reference in New Issue
Block a user