Skip to content

Commit

Permalink
Include type in streaming TestPartResult output (fixes #3994).
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmatson committed Apr 2, 2024
1 parent c4fec74 commit 08e78b5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
17 changes: 16 additions & 1 deletion googletest/src/gtest-internal-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,12 +1199,27 @@ class StreamingListener : public EmptyTestEventListener {
void OnTestPartResult(const TestPartResult& test_part_result) override {
const char* file_name = test_part_result.file_name();
if (file_name == nullptr) file_name = "";
SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
SendLn("event=TestPartResult&type=" + FormatType(test_part_result.type()) +
"&file=" + UrlEncode(file_name) +
"&line=" + StreamableToString(test_part_result.line_number()) +
"&message=" + UrlEncode(test_part_result.message()));
}

private:
static std::string FormatType(TestPartResult::Type type) {
switch (type) {
case TestPartResult::kSkip:
return "skip";
case TestPartResult::kSuccess:
return "success";
case TestPartResult::kNonFatalFailure:
case TestPartResult::kFatalFailure:
return "failure";
default:
return "unknown";
}
}

// Sends the given message and a newline to the socket.
void SendLn(const std::string& message) { socket_writer_->SendLn(message); }

Expand Down
42 changes: 41 additions & 1 deletion googletest/test/gtest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,47 @@ TEST_F(StreamingListenerTest, OnTestPartResult) {

// Meta characters in the failure message should be properly escaped.
EXPECT_EQ(
"event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
"event=TestPartResult&type=failure&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
*output());
}

TEST_F(StreamingListenerTest, OnTestPartResultSkip) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(TestPartResult::kSkip,
"foo.cc", 42, "Skipped"));

EXPECT_EQ(
"event=TestPartResult&type=skip&file=foo.cc&line=42&message=Skipped\n",
*output());
}

TEST_F(StreamingListenerTest, OnTestPartResultSuccess) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(TestPartResult::kSuccess,
"foo.cc", 42, "Succeeded"));

EXPECT_EQ(
"event=TestPartResult&type=success&file=foo.cc&line=42&message=Succeeded\n",
*output());
}

TEST_F(StreamingListenerTest, OnTestPartResultNonFatalFailure) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(TestPartResult::kNonFatalFailure,
"foo.cc", 42, "Failed"));

EXPECT_EQ(
"event=TestPartResult&type=failure&file=foo.cc&line=42&message=Failed\n",
*output());
}

TEST_F(StreamingListenerTest, OnTestPartResultUnknown) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult((TestPartResult::type)-1,
"foo.cc", 42, "Other"));

EXPECT_EQ(
"event=TestPartResult&type=unknown&file=foo.cc&line=42&message=Other\n",
*output());
}

Expand Down

0 comments on commit 08e78b5

Please sign in to comment.