diff options
author | Christopher Ferris <cferris@google.com> | 2019-11-15 13:28:29 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-11-15 13:28:29 -0800 |
commit | 14059b1445fd1c4157792ffbfd41bbfb8888e729 (patch) | |
tree | 927be209f8cf1a91057c3fe5090bf5e85b8db899 | |
parent | 9ec1e182fac3f3e84a317338ca2249efced15b79 (diff) | |
parent | 7cfd24e97edba8c845317c8a71a5dd0912000d54 (diff) | |
download | gtest_extras-14059b1445fd1c4157792ffbfd41bbfb8888e729.tar.gz |
Update skip test handling.android-r-preview-1
am: 7cfd24e97e
Change-Id: Ib1e5b7e8d2066a8b66a7dd38c6c6ca79f433b29a
-rw-r--r-- | Isolate.cpp | 10 | ||||
-rw-r--r-- | Test.cpp | 40 | ||||
-rw-r--r-- | Test.h | 3 | ||||
-rw-r--r-- | tests/SystemTests.cpp | 11 |
4 files changed, 28 insertions, 36 deletions
diff --git a/Isolate.cpp b/Isolate.cpp index 756f194..889b183 100644 --- a/Isolate.cpp +++ b/Isolate.cpp @@ -617,9 +617,13 @@ void TestResultPrinter::OnTestPartResult(const ::testing::TestPartResult& result return; } - // Print failure message from the assertion (e.g. expected this and got that). - printf("%s:(%d) Failure in test %s.%s\n%s\n", result.file_name(), result.line_number(), - pinfo_->test_suite_name(), pinfo_->name(), result.message()); + if (result.type() == ::testing::TestPartResult::kSkip) { + printf("%s:(%d) Skipped%s\n", result.file_name(), result.line_number(), result.message()); + } else { + // Print failure message from the assertion (e.g. expected this and got that). + printf("%s:(%d) Failure in test %s.%s\n%s\n", result.file_name(), result.line_number(), + pinfo_->test_suite_name(), pinfo_->name(), result.message()); + } fflush(stdout); } @@ -18,6 +18,7 @@ #include <stdio.h> #include <unistd.h> +#include <regex> #include <string> #include <tuple> #include <vector> @@ -32,6 +33,8 @@ namespace android { namespace gtest_extras { +std::regex Test::skipped_regex_("(^|\\n)[^\\n]+:\\(\\d+\\) Skipped\\n"); + Test::Test(std::tuple<std::string, std::string>& test, size_t index, size_t run_index, int fd) : suite_name_(std::get<0>(test)), test_name_(std::get<1>(test)), @@ -114,42 +117,13 @@ void Test::SetResultFromOutput() { // Need to parse the output to determine if this test was skipped. // Format of a skipped test: - // <filename>:(<line_number>) Failure in test <testname> - // Skipped + // <filename>:(<line_number>) Skipped // <Skip Message> - // 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; + // If there are multiple skip messages, it doesn't matter, seeing + // even one indicates this is a skipped test. + if (std::regex_search(output_, skipped_regex_)) { 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); - } } } @@ -16,6 +16,7 @@ #pragma once +#include <regex> #include <string> #include <tuple> @@ -94,6 +95,8 @@ class Test { TestResult result_ = TEST_NONE; std::string output_; + + static std::regex skipped_regex_; }; } // namespace gtest_extras diff --git a/tests/SystemTests.cpp b/tests/SystemTests.cpp index ee7b176..821c055 100644 --- a/tests/SystemTests.cpp +++ b/tests/SystemTests.cpp @@ -309,6 +309,7 @@ TEST_F(SystemTests, verify_skip) { "Note: Google Test filter = *.DISABLED_skip_no_message\n" "[==========] Running 1 test from 1 test suite (20 jobs).\n" "[ RUN ] SystemTests.DISABLED_skip_no_message\n" + "file:(XX) Skipped\n" "[ SKIPPED ] SystemTests.DISABLED_skip_no_message (XX ms)\n" "[==========] 1 test from 1 test suite ran. (XX ms total)\n" "[ PASSED ] 0 tests.\n" @@ -322,6 +323,7 @@ TEST_F(SystemTests, verify_skip_with_message) { "Note: Google Test filter = *.DISABLED_skip_with_message\n" "[==========] Running 1 test from 1 test suite (20 jobs).\n" "[ RUN ] SystemTests.DISABLED_skip_with_message\n" + "file:(XX) Skipped\n" "This is a skip message\n" "[ SKIPPED ] SystemTests.DISABLED_skip_with_message (XX ms)\n" "[==========] 1 test from 1 test suite ran. (XX ms total)\n" @@ -337,6 +339,7 @@ TEST_F(SystemTests, verify_skip_with_output_before_message) { "[==========] 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" + "file:(XX) Skipped\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" @@ -351,6 +354,7 @@ TEST_F(SystemTests, verify_skip_with_output_after_message) { "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" + "file:(XX) Skipped\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" @@ -368,8 +372,10 @@ TEST_F(SystemTests, verify_skip_with_skipped_line) { "[ RUN ] SystemTests.DISABLED_skip_with_skipped_line\n" "\n" "Skipped\n" + "file:(XX) Skipped\n" "This is the skip message 1\n" "Skipped\n" + "file:(XX) Skipped\n" "This is the skip message 2\n" "Skipped\n" "[ SKIPPED ] SystemTests.DISABLED_skip_with_skipped_line (XX ms)\n" @@ -386,9 +392,12 @@ TEST_F(SystemTests, verify_skip_multiple) { "[==========] Running 1 test from 1 test suite (20 jobs).\n" "[ RUN ] SystemTests.DISABLED_skip_multiple\n" "This is not a skip message 1\n" + "file:(XX) Skipped\n" "This is the skip message 1\n" "This is not a skip message 2\n" + "file:(XX) Skipped\n" "This is the skip message 2\n" + "file:(XX) Skipped\n" "This is the skip message 3\n" "This is not a skip message 4\n" "[ SKIPPED ] SystemTests.DISABLED_skip_multiple (XX ms)\n" @@ -404,6 +413,7 @@ TEST_F(SystemTests, verify_skip_no_print_time) { "Note: Google Test filter = *.DISABLED_skip_no_message\n" "[==========] Running 1 test from 1 test suite (20 jobs).\n" "[ RUN ] SystemTests.DISABLED_skip_no_message\n" + "file:(XX) Skipped\n" "[ SKIPPED ] SystemTests.DISABLED_skip_no_message\n" "[==========] 1 test from 1 test suite ran. (XX ms total)\n" "[ PASSED ] 0 tests.\n" @@ -418,6 +428,7 @@ TEST_F(SystemTests, verify_skip_color) { "\x1B[0;33mNote: Google Test filter = *.DISABLED_skip_no_message\x1B[m\n" "\x1B[0;32m[==========]\x1B[m Running 1 test from 1 test suite (20 jobs).\n" "\x1B[0;32m[ RUN ]\x1B[m SystemTests.DISABLED_skip_no_message\n" + "file:(XX) Skipped\n" "\x1B[0;32m[ SKIPPED ]\x1B[m SystemTests.DISABLED_skip_no_message (XX ms)\n" "\x1B[0;32m[==========]\x1B[m 1 test from 1 test suite ran. (XX ms total)\n" "\x1B[0;32m[ PASSED ]\x1B[m 0 tests.\n" |