diff options
author | Christopher Ferris <cferris@google.com> | 2018-09-30 17:59:06 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-09-30 17:59:06 -0700 |
commit | b9328d516b26d37aba9f8a0bfbb9089b5ca10a9b (patch) | |
tree | 57a5436bbb311ba68c211e3dd7a0fb8def058138 | |
parent | 0767df758786546007429109369e9a14119e7be6 (diff) | |
parent | f83622fa1454eed1e4d965066c65aeb257c2b155 (diff) | |
download | gtest_extras-b9328d516b26d37aba9f8a0bfbb9089b5ca10a9b.tar.gz |
Do not output XFAIL/XPASS. am: ef98217cf3 am: b9dd84f814
am: f83622fa14
Change-Id: Ibf1a38e010ed8790cc67e8f73c3e1f36a7599110
-rw-r--r-- | Isolate.cpp | 81 | ||||
-rw-r--r-- | Isolate.h | 19 | ||||
-rw-r--r-- | Test.cpp | 6 | ||||
-rw-r--r-- | tests/SystemTests.cpp | 50 |
4 files changed, 97 insertions, 59 deletions
diff --git a/Isolate.cpp b/Isolate.cpp index e2e2f33..58283fd 100644 --- a/Isolate.cpp +++ b/Isolate.cpp @@ -413,18 +413,16 @@ void Isolate::RunAllTests() { } } -void Isolate::PrintResults(size_t total, const char* color, const char* prefix, const char* title, - std::string* footer, bool (*match_func)(const Test&), - void (*print_func)(const Options&, const Test&)) { - ColoredPrintf(color, prefix); - printf(" %s, listed below:\n", PluralizeString(total, " test").c_str()); +void Isolate::PrintResults(size_t total, const ResultsType& results, std::string* footer) { + ColoredPrintf(results.color, results.prefix); + printf(" %s %s, listed below:\n", PluralizeString(total, " test").c_str(), results.list_desc); for (const auto& entry : finished_) { const Test* test = entry.second.get(); - if (match_func(*test)) { - ColoredPrintf(color, prefix); + if (results.match_func(*test)) { + ColoredPrintf(results.color, results.prefix); printf(" %s", test->name().c_str()); - if (print_func) { - print_func(options_, *test); + if (results.print_func != nullptr) { + results.print_func(options_, *test); } printf("\n"); } @@ -432,9 +430,53 @@ void Isolate::PrintResults(size_t total, const char* color, const char* prefix, if (total < 10) { *footer += ' '; } - *footer += PluralizeString(total, (std::string(" ") + title + " TEST").c_str(), true) + '\n'; + *footer += + PluralizeString(total, (std::string(" ") + results.title + " TEST").c_str(), true) + '\n'; } +Isolate::ResultsType Isolate::SlowResults = { + .color = COLOR_YELLOW, + .prefix = "[ SLOW ]", + .list_desc = "slow", + .title = "SLOW", + .match_func = [](const Test& test) { return test.slow(); }, + .print_func = + [](const Options& options, const Test& test) { + printf(" (%" PRIu64 " ms, exceeded %" PRIu64 " ms)", test.RunTimeNs() / kNsPerMs, + options.slow_threshold_ms()); + }, +}; + +Isolate::ResultsType Isolate::XpassFailResults = { + .color = COLOR_RED, + .prefix = "[ FAIL ]", + .list_desc = "should have failed", + .title = "SHOULD HAVE FAILED", + .match_func = [](const Test& test) { return test.result() == TEST_XPASS; }, + .print_func = nullptr, +}; + +Isolate::ResultsType Isolate::FailResults = { + .color = COLOR_RED, + .prefix = "[ FAIL ]", + .list_desc = "failed", + .title = "FAILED", + .match_func = [](const Test& test) { return test.result() == TEST_FAIL; }, + .print_func = nullptr, +}; + +Isolate::ResultsType Isolate::TimeoutResults = { + .color = COLOR_RED, + .prefix = "[ TIMEOUT ]", + .list_desc = "timed out", + .title = "TIMEOUT", + .match_func = [](const Test& test) { return test.result() == TEST_TIMEOUT; }, + .print_func = + [](const Options&, const Test& test) { + printf(" (stopped at %" PRIu64 " ms)", test.RunTimeNs() / kNsPerMs); + }, +}; + void Isolate::PrintFooter(uint64_t elapsed_time_ns) { ColoredPrintf(COLOR_GREEN, "[==========]"); printf(" %s from %s ran. (%" PRId64 " ms total)\n", @@ -451,33 +493,22 @@ void Isolate::PrintFooter(uint64_t elapsed_time_ns) { std::string footer; // Tests that ran slow. if (total_slow_tests_ != 0) { - PrintResults(total_slow_tests_, COLOR_YELLOW, "[ SLOW ]", "SLOW", &footer, - [](const Test& test) { return test.slow(); }, - [](const Options& options, const Test& test) { - printf(" (%" PRIu64 " ms, exceeded %" PRIu64 " ms)", test.RunTimeNs() / kNsPerMs, - options.slow_threshold_ms()); - }); + PrintResults(total_slow_tests_, SlowResults, &footer); } // Tests that passed but should have failed. if (total_xpass_tests_ != 0) { - PrintResults(total_xpass_tests_, COLOR_RED, "[ XPASS ]", "SHOULD HAVE FAILED", &footer, - [](const Test& test) { return test.result() == TEST_XPASS; }, nullptr); + PrintResults(total_xpass_tests_, XpassFailResults, &footer); } // Tests that timed out. if (total_timeout_tests_ != 0) { - PrintResults(total_timeout_tests_, COLOR_RED, "[ TIMEOUT ]", "TIMEOUT", &footer, - [](const Test& test) { return test.result() == TEST_TIMEOUT; }, - [](const Options&, const Test& test) { - printf(" (stopped at %" PRIu64 " ms)", test.RunTimeNs() / kNsPerMs); - }); + PrintResults(total_timeout_tests_, TimeoutResults, &footer); } // Tests that failed. if (total_fail_tests_ != 0) { - PrintResults(total_fail_tests_, COLOR_RED, "[ FAIL ]", "FAILED", &footer, - [](const Test& test) { return test.result() == TEST_FAIL; }, nullptr); + PrintResults(total_fail_tests_, FailResults, &footer); } if (!footer.empty()) { @@ -45,6 +45,15 @@ class Isolate { int Run(); private: + struct ResultsType { + const char* color; + const char* prefix; + const char* list_desc; + const char* title; + bool (*match_func)(const Test&); + void (*print_func)(const Options&, const Test&); + }; + size_t CheckTestsFinished(); void CheckTestsTimeout(); @@ -61,9 +70,7 @@ class Isolate { void PrintFooter(uint64_t elapsed_time_ns); - void PrintResults(size_t total, const char* color, const char* prefix, const char* title, - std::string* footer, bool (*match_func)(const Test&), - void (*print_func)(const Options&, const Test&)); + void PrintResults(size_t total, const ResultsType& results, std::string* footer); void WriteXmlResults(uint64_t elapsed_time_ns, time_t start_time); @@ -71,7 +78,6 @@ class Isolate { return std::get<0>(test) + std::get<1>(test); } - private: const Options& options_; const std::vector<const char*>& child_args_; @@ -99,6 +105,11 @@ class Isolate { std::map<size_t, std::unique_ptr<Test>> finished_; static constexpr useconds_t MIN_USECONDS_WAIT = 1000; + + static ResultsType SlowResults; + static ResultsType XpassFailResults; + static ResultsType FailResults; + static ResultsType TimeoutResults; }; } // namespace gtest_extras @@ -78,18 +78,14 @@ void Test::Print(bool gtest_format) { } switch (result_) { + case TEST_XFAIL: case TEST_PASS: ColoredPrintf(COLOR_GREEN, "[ OK ]"); break; case TEST_XPASS: - ColoredPrintf(COLOR_RED, "[ XPASS ]"); - break; case TEST_FAIL: ColoredPrintf(COLOR_RED, "[ FAILED ]"); break; - case TEST_XFAIL: - ColoredPrintf(COLOR_YELLOW, "[ XFAIL ]"); - break; case TEST_TIMEOUT: ColoredPrintf(COLOR_RED, "[ TIMEOUT ]"); break; diff --git a/tests/SystemTests.cpp b/tests/SystemTests.cpp index 57d7656..d384317 100644 --- a/tests/SystemTests.cpp +++ b/tests/SystemTests.cpp @@ -231,7 +231,7 @@ TEST_F(SystemTests, verify_pass_gtest_format_color) { TEST_F(SystemTests, verify_xfail_fail_expect_to_fail) { std::string expected = "[==========] Running 1 test from 1 test case (20 jobs).\n" - "[ XFAIL ] DISABLED_SystemTestsXfail.xfail_fail (XX ms)\n" + "[ OK ] DISABLED_SystemTestsXfail.xfail_fail (XX ms)\n" "file:(XX) Failure in test DISABLED_SystemTestsXfail.xfail_fail\n" "Expected equality of these values:\n" " 1\n" @@ -245,7 +245,7 @@ TEST_F(SystemTests, verify_xfail_fail_expect_to_fail) { TEST_F(SystemTests, verify_xfail_fail_expect_to_fail_color) { std::string expected = "\x1B[0;32m[==========]\x1B[m Running 1 test from 1 test case (20 jobs).\n" - "\x1B[0;33m[ XFAIL ]\x1B[m DISABLED_SystemTestsXfail.xfail_fail (XX ms)\n" + "\x1B[0;32m[ OK ]\x1B[m DISABLED_SystemTestsXfail.xfail_fail (XX ms)\n" "file:(XX) Failure in test DISABLED_SystemTestsXfail.xfail_fail\n" "Expected equality of these values:\n" " 1\n" @@ -276,11 +276,11 @@ TEST_F(SystemTests, verify_xfail_fail_expect_to_fail_gtest_format) { TEST_F(SystemTests, verify_xfail_pass_expect_to_fail) { std::string expected = "[==========] Running 1 test from 1 test case (20 jobs).\n" - "[ XPASS ] DISABLED_SystemTestsXfail.xfail_pass (XX ms)\n" + "[ FAILED ] DISABLED_SystemTestsXfail.xfail_pass (XX ms)\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ XPASS ] 1 test, listed below:\n" - "[ XPASS ] DISABLED_SystemTestsXfail.xfail_pass\n" + "[ FAIL ] 1 test should have failed, listed below:\n" + "[ FAIL ] DISABLED_SystemTestsXfail.xfail_pass\n" "\n" " 1 SHOULD HAVE FAILED TEST\n"; ASSERT_NO_FATAL_FAILURE(Verify("*.xfail_pass", expected, 1)); @@ -293,8 +293,8 @@ TEST_F(SystemTests, verify_xfail_pass_expect_to_fail_gtest_format) { "[ FAILED ] DISABLED_SystemTestsXfail.xfail_pass (XX ms)\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ XPASS ] 1 test, listed below:\n" - "[ XPASS ] DISABLED_SystemTestsXfail.xfail_pass\n" + "[ FAIL ] 1 test should have failed, listed below:\n" + "[ FAIL ] DISABLED_SystemTestsXfail.xfail_pass\n" "\n" " 1 SHOULD HAVE FAILED TEST\n"; ASSERT_NO_FATAL_FAILURE( @@ -304,11 +304,11 @@ TEST_F(SystemTests, verify_xfail_pass_expect_to_fail_gtest_format) { TEST_F(SystemTests, verify_xfail_pass_expect_to_fail_color) { std::string expected = "\x1B[0;32m[==========]\x1B[m Running 1 test from 1 test case (20 jobs).\n" - "\x1B[0;31m[ XPASS ]\x1B[m DISABLED_SystemTestsXfail.xfail_pass (XX ms)\n" + "\x1B[0;31m[ FAILED ]\x1B[m DISABLED_SystemTestsXfail.xfail_pass (XX ms)\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test case ran. (XX ms total)\n" "\x1B[0;32m[ PASS ]\x1B[m 0 tests.\n" - "\x1B[0;31m[ XPASS ]\x1B[m 1 test, listed below:\n" - "\x1B[0;31m[ XPASS ]\x1B[m DISABLED_SystemTestsXfail.xfail_pass\n" + "\x1B[0;31m[ FAIL ]\x1B[m 1 test should have failed, listed below:\n" + "\x1B[0;31m[ FAIL ]\x1B[m DISABLED_SystemTestsXfail.xfail_pass\n" "\n" " 1 SHOULD HAVE FAILED TEST\n"; ASSERT_NO_FATAL_FAILURE( @@ -335,7 +335,7 @@ TEST_F(SystemTests, verify_fail) { "SystemTests.DISABLED_fail exited with exitcode 1.\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ FAIL ] 1 test, listed below:\n" + "[ FAIL ] 1 test failed, listed below:\n" "[ FAIL ] SystemTests.DISABLED_fail\n" "\n" " 1 FAILED TEST\n"; @@ -353,7 +353,7 @@ TEST_F(SystemTests, verify_fail_color) { "SystemTests.DISABLED_fail exited with exitcode 1.\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test case ran. (XX ms total)\n" "\x1B[0;32m[ PASS ]\x1B[m 0 tests.\n" - "\x1B[0;31m[ FAIL ]\x1B[m 1 test, listed below:\n" + "\x1B[0;31m[ FAIL ]\x1B[m 1 test failed, listed below:\n" "\x1B[0;31m[ FAIL ]\x1B[m SystemTests.DISABLED_fail\n" "\n" " 1 FAILED TEST\n"; @@ -373,7 +373,7 @@ TEST_F(SystemTests, verify_fail_gtest_format) { "[ FAILED ] SystemTests.DISABLED_fail (XX ms)\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ FAIL ] 1 test, listed below:\n" + "[ FAIL ] 1 test failed, listed below:\n" "[ FAIL ] SystemTests.DISABLED_fail\n" "\n" " 1 FAILED TEST\n"; @@ -393,7 +393,7 @@ TEST_F(SystemTests, verify_fail_gtest_format_color) { "\x1B[0;31m[ FAILED ]\x1B[m SystemTests.DISABLED_fail (XX ms)\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test case ran. (XX ms total)\n" "\x1B[0;32m[ PASS ]\x1B[m 0 tests.\n" - "\x1B[0;31m[ FAIL ]\x1B[m 1 test, listed below:\n" + "\x1B[0;31m[ FAIL ]\x1B[m 1 test failed, listed below:\n" "\x1B[0;31m[ FAIL ]\x1B[m SystemTests.DISABLED_fail\n" "\n" " 1 FAILED TEST\n"; @@ -413,7 +413,7 @@ TEST_F(SystemTests, verify_deathtest_fail) { "SystemTestsDeathTest.DISABLED_death_fail exited with exitcode 1.\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ FAIL ] 1 test, listed below:\n" + "[ FAIL ] 1 test failed, listed below:\n" "[ FAIL ] SystemTestsDeathTest.DISABLED_death_fail\n" "\n" " 1 FAILED TEST\n"; @@ -431,7 +431,7 @@ TEST_F(SystemTests, verify_crash) { #endif "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ FAIL ] 1 test, listed below:\n" + "[ FAIL ] 1 test failed, listed below:\n" "[ FAIL ] SystemTests.DISABLED_crash\n" "\n" " 1 FAILED TEST\n"; @@ -444,7 +444,7 @@ TEST_F(SystemTests, verify_warning_slow) { "[ OK ] SystemTests.DISABLED_sleep5 (XX ms)\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 1 test.\n" - "[ SLOW ] 1 test, listed below:\n" + "[ SLOW ] 1 test slow, listed below:\n" "[ SLOW ] SystemTests.DISABLED_sleep5 (XX ms, exceeded 3000 ms)\n" "\n" " 1 SLOW TEST\n"; @@ -458,7 +458,7 @@ TEST_F(SystemTests, verify_warning_slow_color) { "\x1B[0;32m[ OK ]\x1B[m SystemTests.DISABLED_sleep5 (XX ms)\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test case ran. (XX ms total)\n" "\x1B[0;32m[ PASS ]\x1B[m 1 test.\n" - "\x1B[0;33m[ SLOW ]\x1B[m 1 test, listed below:\n" + "\x1B[0;33m[ SLOW ]\x1B[m 1 test slow, listed below:\n" "\x1B[0;33m[ SLOW ]\x1B[m SystemTests.DISABLED_sleep5 (XX ms, exceeded 3000 ms)\n" "\n" " 1 SLOW TEST\n"; @@ -474,7 +474,7 @@ TEST_F(SystemTests, verify_timeout) { "SystemTests.DISABLED_sleep_forever killed because of timeout at XX ms.\n" "[==========] 1 test from 1 test case ran. (XX ms total)\n" "[ PASS ] 0 tests.\n" - "[ TIMEOUT ] 1 test, listed below:\n" + "[ TIMEOUT ] 1 test timed out, listed below:\n" "[ TIMEOUT ] SystemTests.DISABLED_sleep_forever (stopped at XX ms)\n" "\n" " 1 TIMEOUT TEST\n"; @@ -492,9 +492,9 @@ TEST_F(SystemTests, verify_timeout_not_slow) { "SystemTests.DISABLED_sleep_forever killed because of timeout at XX ms.\n" "[==========] 2 tests from 1 test case ran. (XX ms total)\n" "[ PASS ] 1 test.\n" - "[ SLOW ] 1 test, listed below:\n" + "[ SLOW ] 1 test slow, listed below:\n" "[ SLOW ] SystemTests.DISABLED_sleep5 (XX ms, exceeded 1000 ms)\n" - "[ TIMEOUT ] 1 test, listed below:\n" + "[ TIMEOUT ] 1 test timed out, listed below:\n" "[ TIMEOUT ] SystemTests.DISABLED_sleep_forever (stopped at XX ms)\n" "\n" " 1 SLOW TEST\n" @@ -511,7 +511,7 @@ TEST_F(SystemTests, verify_timeout_color) { "SystemTests.DISABLED_sleep_forever killed because of timeout at XX ms.\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test case ran. (XX ms total)\n" "\x1B[0;32m[ PASS ]\x1B[m 0 tests.\n" - "\x1B[0;31m[ TIMEOUT ]\x1B[m 1 test, listed below:\n" + "\x1B[0;31m[ TIMEOUT ]\x1B[m 1 test timed out, listed below:\n" "\x1B[0;31m[ TIMEOUT ]\x1B[m SystemTests.DISABLED_sleep_forever (stopped at XX ms)\n" "\n" " 1 TIMEOUT TEST\n"; @@ -580,13 +580,13 @@ TEST_F(SystemTests, verify_error_order) { ASSERT_FALSE(footer.empty()) << "Test output:\n" << raw_output_; ASSERT_EQ( "[ PASS ] 4 tests.\n" - "[ SLOW ] 2 tests, listed below:\n" + "[ SLOW ] 2 tests slow, listed below:\n" "[ SLOW ] SystemTests.DISABLED_all_slow_1 (XX ms, exceeded 2000 ms)\n" "[ SLOW ] SystemTests.DISABLED_all_slow_2 (XX ms, exceeded 2000 ms)\n" - "[ TIMEOUT ] 2 tests, listed below:\n" + "[ TIMEOUT ] 2 tests timed out, listed below:\n" "[ TIMEOUT ] SystemTests.DISABLED_all_timeout_1 (stopped at XX ms)\n" "[ TIMEOUT ] SystemTests.DISABLED_all_timeout_2 (stopped at XX ms)\n" - "[ FAIL ] 2 tests, listed below:\n" + "[ FAIL ] 2 tests failed, listed below:\n" "[ FAIL ] SystemTests.DISABLED_all_fail_1\n" "[ FAIL ] SystemTests.DISABLED_all_fail_2\n" "\n" |