https://github.com/owenca created https://github.com/llvm/llvm-project/pull/65540:
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. >From a1c4eb75303966edbd3c3932e8791604fe12acbe 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..15ba60417d276cd 100644 --- a/clang/unittests/Format/FormatTestBase.h +++ b/clang/unittests/Format/FormatTestBase.h @@ -80,17 +80,23 @@ 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()); + bool Passed = + Expected.str() == format(Code, Style, SC_ExpectComplete, Ranges); + EXPECT_TRUE(Passed); + if (!Passed) + return false; if (Expected != Code) { - EXPECT_EQ(Expected.str(), - format(Expected, Style, SC_ExpectComplete, Ranges)) - << "Expected code is not stable"; + Passed = + Expected.str() == format(Expected, Style, SC_ExpectComplete, Ranges); + EXPECT_TRUE(Passed) << "Expected code is not stable"; + if (!Passed) + 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 +104,17 @@ 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)); + Passed = + Expected.str() == format(Code, ObjCStyle, SC_ExpectComplete, Ranges); + EXPECT_TRUE(Passed); } + return Passed; } 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