diff --git a/clang/unittests/Format/FormatTestBase.h b/clang/unittests/Format/FormatTestBase.h index 22eea23b869a2..eaadb1c9f83e5 100644 --- a/clang/unittests/Format/FormatTestBase.h +++ b/clang/unittests/Format/FormatTestBase.h @@ -80,17 +80,22 @@ 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 &Style = {}, const std::vector &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++ @@ -98,14 +103,18 @@ class FormatTestBase : public ::testing::Test { 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 &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); }