[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 19:56:25 PDT 2024


https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/91293

None

>From 55aecbedf3e10207eaef1d4c7913086a32e16b1e Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Tue, 7 May 2024 10:55:45 +0800
Subject: [PATCH] [clang-tidy] support expect no diagnosis test

---
 .../test/clang-tidy/check_clang_tidy.py             | 13 +++++++++++--
 .../clang-tidy/checkers/misc/unused-using-decls.hpp |  6 ++++++
 .../clang-tidy/checkers/misc/unused-using-decls.hxx |  6 ------
 3 files changed, 17 insertions(+), 8 deletions(-)
 create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hpp
 delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hxx

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 6d4b466afa691a..d1cfe086fc968c 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -99,6 +99,7 @@ def __init__(self, args, extra_args):
         self.has_check_fixes = False
         self.has_check_messages = False
         self.has_check_notes = False
+        self.expect_no_diagnosis = args.expect_no_diagnosis
         self.export_fixes = args.export_fixes
         self.fixes = MessagePrefix("CHECK-FIXES")
         self.messages = MessagePrefix("CHECK-MESSAGES")
@@ -225,6 +226,11 @@ def run_clang_tidy(self):
         print(diff_output)
         print("------------------------------------------------------------------")
         return clang_tidy_output
+    
+    def check_no_diagnosis(self, clang_tidy_output):
+        print(clang_tidy_output)
+        if clang_tidy_output != "":
+            sys.exit('expect no diagnosis')
 
     def check_fixes(self):
         if self.has_check_fixes:
@@ -273,11 +279,13 @@ def check_notes(self, clang_tidy_output):
 
     def run(self):
         self.read_input()
-        if self.export_fixes is None:
+        if self.export_fixes is None and not self.expect_no_diagnosis:
             self.get_prefixes()
         self.prepare_test_inputs()
         clang_tidy_output = self.run_clang_tidy()
-        if self.export_fixes is None:
+        if self.expect_no_diagnosis:
+            self.check_no_diagnosis(clang_tidy_output)
+        elif self.export_fixes is None:
             self.check_fixes()
             self.check_messages(clang_tidy_output)
             self.check_notes(clang_tidy_output)
@@ -310,6 +318,7 @@ def parse_arguments():
         formatter_class=argparse.RawDescriptionHelpFormatter,
     )
     parser.add_argument("-expect-clang-tidy-error", action="store_true")
+    parser.add_argument("-expect-no-diagnosis", action="store_true")
     parser.add_argument("-resource-dir")
     parser.add_argument("-assume-filename")
     parser.add_argument("input_file_name")
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hpp
new file mode 100644
index 00000000000000..ce37877a22ecab
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s misc-unused-using-decls -expect-no-diagnosis %t
+
+// Verify that we don't generate the warnings on header files.
+namespace foo { class Foo {}; }
+
+using foo::Foo;
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hxx b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hxx
deleted file mode 100644
index f15e4fae80c0bc..00000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hxx
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: %check_clang_tidy %s misc-unused-using-decls %t -- --fix-notes -- -fno-delayed-template-parsing -isystem %S/Inputs
-
-// Verify that we don't generate the warnings on header files.
-namespace foo { class Foo {}; }
-
-using foo::Foo;



More information about the cfe-commits mailing list