Skip to content

Commit

Permalink
[clang-format][NFC] Skip remaining tests of the same case upon failure (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
owenca committed Sep 8, 2023
1 parent a82c106 commit 7ecbf6c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions clang/unittests/Format/FormatTestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,41 @@ class FormatTestBase : public ::testing::Test {
return Style;
}

void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
bool _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
llvm::StringRef Code,
const std::optional<FormatStyle> &Style = {},
const std::vector<tooling::Range> &Ranges = {}) {
testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
const auto ExpectedCode{Expected.str()};
auto FormattedCode{format(Code, Style, SC_ExpectComplete, Ranges)};
EXPECT_EQ(ExpectedCode, FormattedCode);
if (ExpectedCode != FormattedCode)
return false;
if (Expected != Code) {
EXPECT_EQ(Expected.str(),
format(Expected, Style, SC_ExpectComplete, Ranges))
<< "Expected code is not stable";
FormattedCode = format(Expected, Style, SC_ExpectComplete, Ranges);
EXPECT_EQ(ExpectedCode, FormattedCode) << "Expected code is not stable";
if (ExpectedCode != FormattedCode)
return false;
}
EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
auto UsedStyle = Style ? Style.value() : getDefaultStyle();
if (UsedStyle.Language == FormatStyle::LK_Cpp) {
// Objective-C++ is a superset of C++, so everything checked for C++
// needs to be checked for Objective-C++ as well.
FormatStyle ObjCStyle = UsedStyle;
ObjCStyle.Language = FormatStyle::LK_ObjC;
// FIXME: Additional messUp is superfluous.
EXPECT_EQ(Expected.str(),
format(Code, ObjCStyle, SC_ExpectComplete, Ranges));
FormattedCode = format(Code, ObjCStyle, SC_ExpectComplete, Ranges);
EXPECT_EQ(ExpectedCode, FormattedCode);
if (ExpectedCode != FormattedCode)
return false;
}
return true;
}

void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
const std::optional<FormatStyle> &Style = {}) {
_verifyFormat(File, Line, Code, Code, Style);
if (!_verifyFormat(File, Line, Code, Code, Style))
return;
if (const auto MessedUpCode{messUp(Code)}; MessedUpCode != Code)
_verifyFormat(File, Line, Code, MessedUpCode, Style);
}
Expand Down

0 comments on commit 7ecbf6c

Please sign in to comment.