Commit 7f8db020 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(tests): return an error code at program termination, logs tests status

parent 31f2ec67
...@@ -29,6 +29,7 @@ class MainViewTest : public QObject { ...@@ -29,6 +29,7 @@ class MainViewTest : public QObject {
public: public:
MainViewTest () = default; MainViewTest () = default;
~MainViewTest () = default;
private slots: private slots:
void showManageAccountsPopup (); void showManageAccountsPopup ();
......
...@@ -46,14 +46,16 @@ int main (int argc, char *argv[]) { ...@@ -46,14 +46,16 @@ int main (int argc, char *argv[]) {
if (app->isSecondary()) if (app->isSecondary())
qFatal("Unable to run test with secondary app."); qFatal("Unable to run test with secondary app.");
int testsRet = 0;
const QHash<QString, QObject *> tests = initializeTests(); const QHash<QString, QObject *> tests = initializeTests();
QObject *test = nullptr; QObject *test = nullptr;
if (argc > 1) { if (argc > 1) {
if (!strcmp(argv[1], "self-test")) if (!strcmp(argv[1], "self-test"))
// Execute only self-test. // Execute only self-test.
QTimer::singleShot(0, [app] { QTimer::singleShot(0, [app, &testsRet] {
QTest::qExec(new SelfTest(app)); testsRet = QTest::qExec(new SelfTest(app));
QCoreApplication::quit(); QCoreApplication::quit();
}); });
else { else {
...@@ -65,18 +67,22 @@ int main (int argc, char *argv[]) { ...@@ -65,18 +67,22 @@ int main (int argc, char *argv[]) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
QTimer::singleShot(0, [app, test, argc, argv] { QTimer::singleShot(0, [app, &testsRet, test, argc, argv] {
QTest::qExec(new SelfTest(app)); testsRet = QTest::qExec(new SelfTest(app));
QTest::qExec(test, argc - 1, argv + 1); if (!testsRet)
QTest::qExec(test, argc - 1, argv + 1);
QCoreApplication::quit(); QCoreApplication::quit();
}); });
} }
} else } else
// Execute all tests. // Execute all tests.
QTimer::singleShot(0, [app, &tests] { QTimer::singleShot(0, [app, &testsRet, &tests] {
QTest::qExec(new SelfTest(app)); testsRet = QTest::qExec(new SelfTest(app));
for (const auto &test : tests) if (!testsRet)
QTest::qExec(test); for (const auto &test : tests) {
testsRet |= QTest::qExec(test);
}
QCoreApplication::quit(); QCoreApplication::quit();
}); });
...@@ -86,5 +92,10 @@ int main (int argc, char *argv[]) { ...@@ -86,5 +92,10 @@ int main (int argc, char *argv[]) {
for (auto &test : tests) for (auto &test : tests)
delete test; delete test;
return ret; if (testsRet)
qWarning() << QStringLiteral("One or many tests are failed. :(");
else
qInfo() << QStringLiteral("Tests seems OK. :)");
return testsRet || ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment