aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCongcong Cai <congcongcai0907@163.com>2024-05-14 09:48:57 +0800
committerGitHub <noreply@github.com>2024-05-14 09:48:57 +0800
commitf12018eba11f8d4b74cf67dbc416c429c870a5f4 (patch)
treead2c514aa170759daf84f6add94e98b77303bd70
parente6b2197a89f5d6d0f56a03c03b8afda561eee899 (diff)
downloadllvm-f12018eba11f8d4b74cf67dbc416c429c870a5f4.zip
llvm-f12018eba11f8d4b74cf67dbc416c429c870a5f4.tar.gz
llvm-f12018eba11f8d4b74cf67dbc416c429c870a5f4.tar.bz2
[clang-tidy] support expect no diagnosis test (#91293)
When someone wants to declare a test case without any diagnosis. check-clang-tidy will failed with error message ``` CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES not found in the input ``` This PR want to check there are no diagnosis from clang-tidy when CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES are not found. It also changes the extension of a test case. `hxx` is not a valid test case extension and won't be tested. --------- Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
-rwxr-xr-xclang-tools-extra/test/clang-tidy/check_clang_tidy.py28
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hpp6
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.hxx6
3 files changed, 28 insertions, 12 deletions
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 6d4b466..e92179a 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 @@ class CheckRunner:
self.has_check_fixes = False
self.has_check_messages = False
self.has_check_notes = False
+ self.expect_no_diagnosis = False
self.export_fixes = args.export_fixes
self.fixes = MessagePrefix("CHECK-FIXES")
self.messages = MessagePrefix("CHECK-MESSAGES")
@@ -172,12 +173,21 @@ class CheckRunner:
)
if not has_check_fix and not has_check_message and not has_check_note:
- sys.exit(
- "%s, %s or %s not found in the input"
- % (self.fixes.prefix, self.messages.prefix, self.notes.prefix)
- )
+ self.expect_no_diagnosis = True
- assert self.has_check_fixes or self.has_check_messages or self.has_check_notes
+ expect_diagnosis = (
+ self.has_check_fixes or self.has_check_messages or self.has_check_notes
+ )
+ if self.expect_no_diagnosis and expect_diagnosis:
+ sys.exit(
+ "%s, %s or %s not found in the input"
+ % (
+ self.fixes.prefix,
+ self.messages.prefix,
+ self.notes.prefix,
+ )
+ )
+ assert expect_diagnosis or self.expect_no_diagnosis
def prepare_test_inputs(self):
# Remove the contents of the CHECK lines to avoid CHECKs matching on
@@ -226,6 +236,10 @@ class CheckRunner:
print("------------------------------------------------------------------")
return clang_tidy_output
+ def check_no_diagnosis(self, clang_tidy_output):
+ if clang_tidy_output != "":
+ sys.exit("No diagnostics were expected, but found the ones above")
+
def check_fixes(self):
if self.has_check_fixes:
try_run(
@@ -277,7 +291,9 @@ class CheckRunner:
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)
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 0000000..4918aae
--- /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 %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 f15e4fae..0000000
--- 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;