[clang] 69ecd24 - [clang-format] Indicate source location on test failure. NFC.

Marek Kurdej via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 20 05:15:21 PST 2022


Author: Marek Kurdej
Date: 2022-01-20T14:10:59+01:00
New Revision: 69ecd2484f0d363537afc0157bd6a946fccf8453

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

LOG: [clang-format] Indicate source location on test failure. NFC.

Added: 
    

Modified: 
    clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
    clang/unittests/Format/FormatTestTextProto.cpp
    clang/unittests/Format/SortImportsTestJS.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index 13054bcad1a96..69c87cb4b51fd 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -41,9 +41,10 @@ class DefinitionBlockSeparatorTest : public ::testing::Test {
         /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
   }
 
-  static void verifyFormat(llvm::StringRef Code,
-                           const FormatStyle &Style = getLLVMStyle(),
-                           llvm::StringRef ExpectedCode = "") {
+  static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+                            const FormatStyle &Style = getLLVMStyle(),
+                            llvm::StringRef ExpectedCode = "") {
+    ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
     bool HasOriginalCode = true;
     if (ExpectedCode == "") {
       ExpectedCode = Code;
@@ -83,6 +84,8 @@ class DefinitionBlockSeparatorTest : public ::testing::Test {
   }
 };
 
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
 TEST_F(DefinitionBlockSeparatorTest, Basic) {
   FormatStyle Style = getLLVMStyle();
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;

diff  --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp
index 1e25948938416..44b67d275bcc3 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -34,18 +34,22 @@ class FormatTestTextProto : public ::testing::Test {
     return format(Code, 0, Code.size(), Style);
   }
 
-  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+  static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+                            const FormatStyle &Style) {
+    ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
     EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
 
-  static void verifyFormat(llvm::StringRef Code) {
+  static void _verifyFormat(const char *File, int Line, llvm::StringRef Code) {
     FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
     Style.ColumnLimit = 60; // To make writing tests easier.
-    verifyFormat(Code, Style);
+    _verifyFormat(File, Line, Code, Style);
   }
 };
 
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
 TEST_F(FormatTestTextProto, KeepsTopLevelEntriesFittingALine) {
   verifyFormat("field_a: OK field_b: OK field_c: OK field_d: OK field_e: OK");
 }

diff  --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp
index 4b426375cfea8..6fe8bba53549b 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -33,8 +33,10 @@ class SortImportsTestJS : public ::testing::Test {
     return *Formatted;
   }
 
-  void verifySort(llvm::StringRef Expected, llvm::StringRef Code,
-                  unsigned Offset = 0, unsigned Length = 0) {
+  void _verifySort(const char *File, int Line, llvm::StringRef Expected,
+                   llvm::StringRef Code, unsigned Offset = 0,
+                   unsigned Length = 0) {
+    ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
     std::string Result = sort(Code, Offset, Length);
     EXPECT_EQ(Expected.str(), Result) << "Expected:\n"
                                       << Expected << "\nActual:\n"
@@ -44,6 +46,8 @@ class SortImportsTestJS : public ::testing::Test {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
 };
 
+#define verifySort(...) _verifySort(__FILE__, __LINE__, __VA_ARGS__)
+
 TEST_F(SortImportsTestJS, AlreadySorted) {
   verifySort("import {sym} from 'a';\n"
              "import {sym} from 'b';\n"


        


More information about the cfe-commits mailing list