Skip to content

Commit

Permalink
fix gtest FAIL statment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
matepek committed Oct 19, 2024
1 parent f581bbc commit 15f2705
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/framework/GoogleTest/GoogleTestExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,16 @@ class FailureProcessor implements LineProcessor {
private readonly fullMsg: string,
) {}

private treatRemainingAsPart: boolean = false;
private lines: string[] = [];

online(line: string): void | false {
if (acceptedAndDecoratedPrefixes.some(prefix => line.startsWith(prefix))) {
if (this.treatRemainingAsPart) {
if (line.startsWith('[')) {
return false;
}
this.lines.push(line);
} else if (acceptedAndDecoratedPrefixes.some(prefix => line.startsWith(prefix))) {
if (isDecorationEnabled) {
const first = line.indexOf(':');
if (first != -1) {
Expand All @@ -529,6 +535,9 @@ class FailureProcessor implements LineProcessor {
this.lines.push(line);
} else if (line.startsWith(' ')) {
this.lines.push(line); /* special prefix. This might cause some issue */
} else if (line.startsWith('Failed')) {
this.lines.push(line);
this.treatRemainingAsPart = true;
} else {
return false;
}
Expand Down
13 changes: 13 additions & 0 deletions test/cpp/gtest/gtest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,17 @@ TEST(CppMateTest, LeadingWhitespace)
<< "- Third line\n"
<< " Fourth line\n";
FAIL() << "bad whitespace";
}

TEST(ThisTest, FailsWithContext) {
FAIL() << "This test fails with context";
}

TEST(ThisTest, FailsWithEmpty) {
FAIL();
std::cout << "not related";
}

TEST(ThisTest, AlsoFailsWithContext) {
ASSERT_EQ(1, 2) << "Value of [" << 1 << "] is not equal to [" << 2 << "]";
}

0 comments on commit 15f2705

Please sign in to comment.