https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/65540:
>From e67336055c73e9d8c1d1fccff24395ca0197e985 Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Wed, 6 Sep 2023 14:53:39 -0700 Subject: [PATCH] [clang-format] Skip additional tests of the same case upon failure A typical test case goes through the format, stability, ObjC, and messUp tests. If any of theses tests fails, we should skip the rest of the tests for the same test case. --- clang/unittests/Format/FormatTestBase.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) 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); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits