Skip to content

Commit

Permalink
List failed tests at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
halfgaar committed Mar 3, 2024
1 parent 024d0b4 commit f033a97
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions FlashMQTests/maintests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ bool MainTests::test(const std::vector<std::string> &tests)
selectedTests = &subset;
}

std::vector<std::string> failedTests;

for (const auto &pair : *selectedTests)
{
testCount++;
Expand All @@ -334,11 +336,13 @@ bool MainTests::test(const std::vector<std::string> &tests)
{
std::cout << RED << "FAIL" << COLOR_END << ": no asserts performed in " << pair.first << std::endl;
testFailCount++;
failedTests.push_back(pair.first);
}
else if (failCountBefore != failCountAfter)
{
std::cout << RED << "FAIL" << COLOR_END << ": " << pair.first << std::endl;
testFailCount++;
failedTests.push_back(pair.first);
}
else
{
Expand All @@ -352,6 +356,7 @@ bool MainTests::test(const std::vector<std::string> &tests)

testFailCount++;
testExceptionCount++;
failedTests.push_back(pair.first);

std::cout << RED << "FAIL EXCEPTION" << COLOR_END << ": " << pair.first << ": " << ex.what() << std::endl;
}
Expand All @@ -363,13 +368,22 @@ bool MainTests::test(const std::vector<std::string> &tests)
<< testFailCount << " (of which " << testExceptionCount << " exceptions). Total assertions: "
<< assert_count << "." << std::endl;

std::cout << std::endl << std::endl;

if (assert_fail_count == 0 && testFailCount == 0)
{
std::cout << std::endl << GREEN << "TESTS PASSED" << std::endl;
return true;
}
else
{
std::cout << "Failed tests: " << std::endl;

for (const std::string &test_name : failedTests)
{
std::cout << " - " << test_name << std::endl;
}

std::cout << std::endl << RED << "TESTS FAILED" << std::endl;
return false;
}
Expand Down

0 comments on commit f033a97

Please sign in to comment.