[clang] c852145 - [clang-format][NFC] Skip stability test if input is pre-formatted

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 26 14:48:42 PDT 2023


Author: Owen Pan
Date: 2023-08-26T14:48:04-07:00
New Revision: c8521451708a49a5a55cf02c28189efac11b779e

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

LOG: [clang-format][NFC] Skip stability test if input is pre-formatted

This shortens the run-time of FormatTests by about 10% on average (and
by up to 50% if formatting would not change the input).

Differential Revision: https://reviews.llvm.org/D158925

Added: 
    

Modified: 
    clang/unittests/Format/FormatTestBase.h

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Format/FormatTestBase.h b/clang/unittests/Format/FormatTestBase.h
index 40442d60aa3300..2b0c4550bb951f 100644
--- a/clang/unittests/Format/FormatTestBase.h
+++ b/clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@ class FormatTestBase : public ::testing::Test {
                      const std::optional<FormatStyle> &Style = {},
                      const std::vector<tooling::Range> &Ranges = {}) {
     testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-    EXPECT_EQ(Expected.str(),
-              format(Expected, Style, SC_ExpectComplete, Ranges))
-        << "Expected code is not stable";
+    if (Expected != Code) {
+      EXPECT_EQ(Expected.str(),
+                format(Expected, Style, SC_ExpectComplete, Ranges))
+          << "Expected code is not stable";
+    }
     EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
     auto UsedStyle = Style ? Style.value() : getDefaultStyle();
     if (UsedStyle.Language == FormatStyle::LK_Cpp) {


        


More information about the cfe-commits mailing list