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

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 01:06:58 PDT 2023


Author: Owen
Date: 2023-09-08T01:06:54-07:00
New Revision: 7ecbf6c30605ecbee4fdbcdec8f0866328c5217f

URL: https://github.com/llvm/llvm-project/commit/7ecbf6c30605ecbee4fdbcdec8f0866328c5217f
DIFF: https://github.com/llvm/llvm-project/commit/7ecbf6c30605ecbee4fdbcdec8f0866328c5217f.diff

LOG: [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.

Added: 
    

Modified: 
    clang/unittests/Format/FormatTestBase.h

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Format/FormatTestBase.h b/clang/unittests/Format/FormatTestBase.h
index 22eea23b869a212..eaadb1c9f83e5a5 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<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++
@@ -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<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);
   }


        


More information about the cfe-commits mailing list