Skip to content

Commit 7ecbf6c

Browse files
authored
[clang-format][NFC] Skip remaining tests of the same case upon failure (#65540)
A typical test case goes through the format, stability, ObjC, and messUp tests. If any of theses tests fails, we should skip the remaining tests for the same test case.
1 parent a82c106 commit 7ecbf6c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

clang/unittests/Format/FormatTestBase.h

+17-8
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,41 @@ class FormatTestBase : public ::testing::Test {
8080
return Style;
8181
}
8282

83-
void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
83+
bool _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
8484
llvm::StringRef Code,
8585
const std::optional<FormatStyle> &Style = {},
8686
const std::vector<tooling::Range> &Ranges = {}) {
8787
testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
88+
const auto ExpectedCode{Expected.str()};
89+
auto FormattedCode{format(Code, Style, SC_ExpectComplete, Ranges)};
90+
EXPECT_EQ(ExpectedCode, FormattedCode);
91+
if (ExpectedCode != FormattedCode)
92+
return false;
8893
if (Expected != Code) {
89-
EXPECT_EQ(Expected.str(),
90-
format(Expected, Style, SC_ExpectComplete, Ranges))
91-
<< "Expected code is not stable";
94+
FormattedCode = format(Expected, Style, SC_ExpectComplete, Ranges);
95+
EXPECT_EQ(ExpectedCode, FormattedCode) << "Expected code is not stable";
96+
if (ExpectedCode != FormattedCode)
97+
return false;
9298
}
93-
EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
9499
auto UsedStyle = Style ? Style.value() : getDefaultStyle();
95100
if (UsedStyle.Language == FormatStyle::LK_Cpp) {
96101
// Objective-C++ is a superset of C++, so everything checked for C++
97102
// needs to be checked for Objective-C++ as well.
98103
FormatStyle ObjCStyle = UsedStyle;
99104
ObjCStyle.Language = FormatStyle::LK_ObjC;
100105
// FIXME: Additional messUp is superfluous.
101-
EXPECT_EQ(Expected.str(),
102-
format(Code, ObjCStyle, SC_ExpectComplete, Ranges));
106+
FormattedCode = format(Code, ObjCStyle, SC_ExpectComplete, Ranges);
107+
EXPECT_EQ(ExpectedCode, FormattedCode);
108+
if (ExpectedCode != FormattedCode)
109+
return false;
103110
}
111+
return true;
104112
}
105113

106114
void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
107115
const std::optional<FormatStyle> &Style = {}) {
108-
_verifyFormat(File, Line, Code, Code, Style);
116+
if (!_verifyFormat(File, Line, Code, Code, Style))
117+
return;
109118
if (const auto MessedUpCode{messUp(Code)}; MessedUpCode != Code)
110119
_verifyFormat(File, Line, Code, MessedUpCode, Style);
111120
}

0 commit comments

Comments
 (0)