@@ -80,32 +80,41 @@ class FormatTestBase : public ::testing::Test {
80
80
return Style ;
81
81
}
82
82
83
- void _verifyFormat (const char *File, int Line, llvm::StringRef Expected,
83
+ bool _verifyFormat (const char *File, int Line, llvm::StringRef Expected,
84
84
llvm::StringRef Code,
85
85
const std::optional<FormatStyle> &Style = {},
86
86
const std::vector<tooling::Range> &Ranges = {}) {
87
87
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 ;
88
93
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 ;
92
98
}
93
- EXPECT_EQ (Expected.str (), format (Code, Style , SC_ExpectComplete, Ranges));
94
99
auto UsedStyle = Style ? Style .value () : getDefaultStyle ();
95
100
if (UsedStyle.Language == FormatStyle::LK_Cpp) {
96
101
// Objective-C++ is a superset of C++, so everything checked for C++
97
102
// needs to be checked for Objective-C++ as well.
98
103
FormatStyle ObjCStyle = UsedStyle;
99
104
ObjCStyle.Language = FormatStyle::LK_ObjC;
100
105
// 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 ;
103
110
}
111
+ return true ;
104
112
}
105
113
106
114
void _verifyFormat (const char *File, int Line, llvm::StringRef Code,
107
115
const std::optional<FormatStyle> &Style = {}) {
108
- _verifyFormat (File, Line, Code, Code, Style );
116
+ if (!_verifyFormat (File, Line, Code, Code, Style ))
117
+ return ;
109
118
if (const auto MessedUpCode{messUp (Code)}; MessedUpCode != Code)
110
119
_verifyFormat (File, Line, Code, MessedUpCode, Style );
111
120
}
0 commit comments