Skip to content

[clang-format][NFC] Skip remaining tests of the same case upon failure #65540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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