Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add qt unit test runner summary #576

Merged
merged 3 commits into from
Apr 12, 2022

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Apr 6, 2022

Append a one-line summary to the output of running ./src/qt/test/test_bitcoin-qt indicating that all tests passed or showing the number of failing tests. It's currently a bit inconvenient to see this result by eyeballing all of the output.

@jonatack
Copy link
Member Author

jonatack commented Apr 6, 2022

A sample patch to generate 3 errors to test the runner output in this case.

patch

diff --git a/src/qt/test/optiontests.cpp b/src/qt/test/optiontests.cpp
index 4a943a634..9e6c8a243 100644
--- a/src/qt/test/optiontests.cpp
+++ b/src/qt/test/optiontests.cpp
@@ -28,6 +28,7 @@ void OptionTests::optionTests()
     gArgs.LockSettings([&](util::Settings& settings) {
         settings.rw_settings.erase("prune");
     });
+    QVERIFY(gArgs.IsArgSet("-prune"));
     gArgs.WriteSettingsFile();
 }
 
@@ -51,7 +52,7 @@ void OptionTests::parametersInteraction()
 
     OptionsModel{};
 
-    const bool expected{false};
+    const bool expected{true};
 
     QVERIFY(gArgs.IsArgSet("-listen"));
     QCOMPARE(gArgs.GetBoolArg("-listen", !expected), expected);
diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp
index 669a05fe0..4395c20cf 100644
--- a/src/qt/test/rpcnestedtests.cpp
+++ b/src/qt/test/rpcnestedtests.cpp
@@ -73,7 +73,7 @@ void RPCNestedTests::rpcNestedTests()
     QVERIFY(result.substr(0,1) == "{");
 
     RPCConsole::RPCExecuteCommandLine(m_node, result, "getblockchaininfo()[\"chain\"]"); //Quote path identifier are allowed, but look after a child containing the quotes in the key
-    QVERIFY(result == "null");
+    QVERIFY(result != "null");

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d025d7f

It makes sense to give the user an overview of how many tests were failed. Though it won’t wholly communicate the information of which tests failed to the user, it still would make him alert to the situation and allow him to save his efforts of eyeballing in case the “Test failed” message is missing.

I was able to compile the PR and run the test_bitcoin-qt file successfully. I have attached the screenshot of the difference in output between the Master and PR branches.

Master PR
Master Screenshot from 2022-04-07 23-32-28

#endif

return fInvalid;
if (num_test_failures) {
qWarning("\nFailed tests: %d\n", num_test_failures);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
This is less of a suggestion and more of a preference. I don't think this line needs separate line breaks to make it stand out from other lines. I think we can forgo the "\n"s.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shaavan! I like the line breaks to set off the summary, but if reviewers agree with you I'm ok to drop them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @shaavan

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK d025d7f

I have tested and reviewed the code, I agree this can be merged.

if (QTest::qExec(&app_tests) != 0) {
fInvalid = true;
}
num_test_failures += QTest::qExec(&app_tests);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QTest::qExec does not guarantee return value 1 in case of a test failure, but:

a value other than 0 if one or more tests failed or in case of unhandled exceptions.

Copy link
Member Author

@jonatack jonatack Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in my testing it returns the number of failures; if there are two failures for instance, it returns 2. This is desirable.

@hebasto hebasto added the Tests label Apr 12, 2022
@hebasto hebasto merged commit f509760 into bitcoin-core:master Apr 12, 2022
@jonatack jonatack deleted the gui-test-runner-summary branch April 13, 2022 02:05
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 13, 2022
d025d7f gui, refactor: rename fInvalid to num_test_failures in test_main.cpp (Jon Atack)
2489b6f gui: count test failures in test runner summary (Jon Atack)
ba44aae gui: add test runner summary (Jon Atack)

Pull request description:

  Append a one-line summary to the output of running `./src/qt/test/test_bitcoin-qt` indicating that all tests passed or showing the number of failing tests. It's currently a bit inconvenient to see this result by eyeballing all of the output.

ACKs for top commit:
  shaavan:
    ACK d025d7f
  jarolrod:
    tACK bitcoin-core/gui@d025d7f

Tree-SHA512: 981c5daa13db127d38167bcf78b296b1a7e5b2d12e65f364ec6382b24f1008a223521d3b6c56e920bcd037479da5414e43758794688019d09e9aa696f3964746
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants