diff options
author | Christopher Ferris <cferris@google.com> | 2019-09-25 16:09:17 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-09-25 16:09:17 -0700 |
commit | 4710324dc6d24dca2f9567e08ca71dbe5398ec92 (patch) | |
tree | b6e26426fd2494623c95d03145cfca472c50c254 | |
parent | 96df0e7bd0c6a7a1ea4990df2b1a7b990df11c56 (diff) | |
parent | f40837609832c6e3471a9a73865e1b8bb14e9068 (diff) | |
download | gtest_extras-4710324dc6d24dca2f9567e08ca71dbe5398ec92.tar.gz |
Fix skip test handling. am: 1d6022528a am: af21c9ef19 am: 16ea356023
am: f408376098
Change-Id: I5b6018a13909e3883d6cdc6f7a3873697038ac51
-rw-r--r-- | Test.cpp | 49 | ||||
-rw-r--r-- | tests/SystemTests.cpp | 105 |
2 files changed, 138 insertions, 16 deletions
@@ -117,23 +117,40 @@ void Test::SetResultFromOutput() { // <filename>:(<line_number>) Failure in test <testname> // Skipped // <Skip Message> - size_t line_end = output_.find('\n'); - if (line_end == std::string::npos) { - return; - } - std::string second_line(output_.substr(line_end, 9)); - if (output_.substr(line_end, 9) != "\nSkipped\n") { - return; - } - size_t failure_index = output_.find(" Failure in test "); - if (failure_index == std::string::npos || failure_index >= line_end) { - return; - } - // Only leave the output from the skip message. - output_ = output_.substr(line_end + 9); - - result_ = TEST_SKIPPED; + // There can be multiple skip messages, so remove all of them. + size_t start_index = 0; + while (true) { + size_t skipped_index = output_.find("\nSkipped\n", start_index); + if (skipped_index == std::string::npos) { + return; + } + if (skipped_index == 0) { + // The output starts with Skipped, so skip over it and keep looking. + start_index = skipped_index + 9; + continue; + } + // Look backwards for start of line before "Skipped" message. + size_t failure_line_start = output_.rfind('\n', skipped_index - 1); + if (failure_line_start == std::string::npos) { + failure_line_start = 0; + } + skipped_index += 9; + size_t failure_index = output_.find(" Failure in test ", failure_line_start); + if (failure_index == std::string::npos || failure_index > skipped_index) { + // Could still be another skipped message matching the pattern after + // this one. + start_index = skipped_index - 1; + continue; + } + start_index = 0; + result_ = TEST_SKIPPED; + if (failure_line_start != 0) { + output_ = output_.substr(0, failure_line_start + 1) + output_.substr(skipped_index); + } else { + output_ = output_.substr(skipped_index); + } + } } } // namespace gtest_extras diff --git a/tests/SystemTests.cpp b/tests/SystemTests.cpp index 002cc45..ee7b176 100644 --- a/tests/SystemTests.cpp +++ b/tests/SystemTests.cpp @@ -331,6 +331,74 @@ TEST_F(SystemTests, verify_skip_with_message) { ASSERT_NO_FATAL_FAILURE(Verify("*.DISABLED_skip_with_message", expected, 0)); } +TEST_F(SystemTests, verify_skip_with_output_before_message) { + std::string expected = + "Note: Google Test filter = *.DISABLED_skip_with_output_before\n" + "[==========] Running 1 test from 1 test suite (20 jobs).\n" + "[ RUN ] SystemTests.DISABLED_skip_with_output_before\n" + "This is the message before the skip message\n" + "This is the skip message\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_output_before (XX ms)\n" + "[==========] 1 test from 1 test suite ran. (XX ms total)\n" + "[ PASSED ] 0 tests.\n" + "[ SKIPPED ] 1 test, listed below:\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_output_before\n"; + ASSERT_NO_FATAL_FAILURE(Verify("*.DISABLED_skip_with_output_before", expected, 0)); +} + +TEST_F(SystemTests, verify_skip_with_output_after_message) { + std::string expected = + "Note: Google Test filter = *.DISABLED_skip_with_output_after\n" + "[==========] Running 1 test from 1 test suite (20 jobs).\n" + "[ RUN ] SystemTests.DISABLED_skip_with_output_after\n" + "This is the skip message\n" + "This is the message after the skip message\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_output_after (XX ms)\n" + "[==========] 1 test from 1 test suite ran. (XX ms total)\n" + "[ PASSED ] 0 tests.\n" + "[ SKIPPED ] 1 test, listed below:\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_output_after\n"; + ASSERT_NO_FATAL_FAILURE(Verify("*.DISABLED_skip_with_output_after", expected, 0)); +} + +TEST_F(SystemTests, verify_skip_with_skipped_line) { + std::string expected = + "Note: Google Test filter = *.DISABLED_skip_with_skipped_line\n" + "[==========] Running 1 test from 1 test suite (20 jobs).\n" + "[ RUN ] SystemTests.DISABLED_skip_with_skipped_line\n" + "\n" + "Skipped\n" + "This is the skip message 1\n" + "Skipped\n" + "This is the skip message 2\n" + "Skipped\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_skipped_line (XX ms)\n" + "[==========] 1 test from 1 test suite ran. (XX ms total)\n" + "[ PASSED ] 0 tests.\n" + "[ SKIPPED ] 1 test, listed below:\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_with_skipped_line\n"; + ASSERT_NO_FATAL_FAILURE(Verify("*.DISABLED_skip_with_skipped_line", expected, 0)); +} + +TEST_F(SystemTests, verify_skip_multiple) { + std::string expected = + "Note: Google Test filter = *.DISABLED_skip_multiple\n" + "[==========] Running 1 test from 1 test suite (20 jobs).\n" + "[ RUN ] SystemTests.DISABLED_skip_multiple\n" + "This is not a skip message 1\n" + "This is the skip message 1\n" + "This is not a skip message 2\n" + "This is the skip message 2\n" + "This is the skip message 3\n" + "This is not a skip message 4\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_multiple (XX ms)\n" + "[==========] 1 test from 1 test suite ran. (XX ms total)\n" + "[ PASSED ] 0 tests.\n" + "[ SKIPPED ] 1 test, listed below:\n" + "[ SKIPPED ] SystemTests.DISABLED_skip_multiple\n"; + ASSERT_NO_FATAL_FAILURE(Verify("*.DISABLED_skip_multiple", expected, 0)); +} + TEST_F(SystemTests, verify_skip_no_print_time) { std::string expected = "Note: Google Test filter = *.DISABLED_skip_no_message\n" @@ -1395,6 +1463,43 @@ TEST_F(SystemTests, DISABLED_skip_with_message) { GTEST_SKIP() << "This is a skip message"; } +TEST_F(SystemTests, DISABLED_skip_with_output_before) { + printf("This is the message before the skip message\n"); + GTEST_SKIP() << "This is the skip message"; +} + +// Do not optimize this call away so that the print after the skip +// will actually occur. +void AvoidSkipStopping(int tag = 0) __attribute__((optnone)) { + if (tag == 0) { + GTEST_SKIP() << "This is the skip message"; + } else { + GTEST_SKIP() << "This is the skip message " << std::to_string(tag); + } +} + +TEST_F(SystemTests, DISABLED_skip_with_output_after) { + AvoidSkipStopping(); + printf("This is the message after the skip message\n"); +} + +TEST_F(SystemTests, DISABLED_skip_with_skipped_line) { + printf("\nSkipped\n"); + AvoidSkipStopping(1); + printf("Skipped\n"); + AvoidSkipStopping(2); + printf("Skipped\n"); +} + +TEST_F(SystemTests, DISABLED_skip_multiple) { + printf("This is not a skip message 1\n"); + AvoidSkipStopping(1); + printf("This is not a skip message 2\n"); + AvoidSkipStopping(2); + AvoidSkipStopping(3); + printf("This is not a skip message 4\n"); +} + class DISABLED_SystemTestsXfail : public ::testing::Test {}; TEST_F(DISABLED_SystemTestsXfail, xfail_fail) { |