[clang-tools-extra] r316066 - New -assume-filename=param to check_clang_tidy.py (like clang-format)
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 00:48:40 PDT 2017
Author: hokein
Date: Wed Oct 18 00:48:40 2017
New Revision: 316066
URL: http://llvm.org/viewvc/llvm-project?rev=316066&view=rev
Log:
New -assume-filename=param to check_clang_tidy.py (like clang-format)
Summary:
Currently, check_clang_tidy.py includes logic to select default
clang flags based on the extension of the source filename passed
as the first argument.
Since the source filename might be a temporary or test file with an
arbitrary extension unrelated to the file type, this adds the ability
to override the logic the same way `clang-format`'s -assume-filename=
parameter does.
I included a test with a nonstandard file extension. I confirmed
when I modified the warning message that the new test failed,
and that it passed again when I restored the warning message.
Ran tests with:
% cmake -G Ninja /path/to/llvm
% ninja check-clang-tools
Patch by Ben Hamilton!
Reviewers: hokein, alexfh
Reviewed By: hokein
Subscribers: alexfh
Differential Revision: https://reviews.llvm.org/D38963
Added:
clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test
Modified:
clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py?rev=316066&r1=316065&r2=316066&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy.py Wed Oct 18 00:48:40 2017
@@ -17,6 +17,7 @@ This script runs clang-tidy in fix mode
Usage:
check_clang_tidy.py [-resource-dir <resource-dir>] \
+ [-assume-filename <file-with-source-extension>] \
<source-file> <check-name> <temp-file> \
-- [optional clang-tidy arguments]
@@ -38,6 +39,7 @@ def write_file(file_name, text):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-resource-dir')
+ parser.add_argument('-assume-filename')
parser.add_argument('input_file_name')
parser.add_argument('check_name')
parser.add_argument('temp_file_name')
@@ -45,14 +47,17 @@ def main():
args, extra_args = parser.parse_known_args()
resource_dir = args.resource_dir
+ assume_file_name = args.assume_filename
input_file_name = args.input_file_name
check_name = args.check_name
temp_file_name = args.temp_file_name
+ file_name_with_extension = assume_file_name or input_file_name
+
extension = '.cpp'
- if (input_file_name.endswith('.c')):
+ if (file_name_with_extension.endswith('.c')):
extension = '.c'
- if (input_file_name.endswith('.hpp')):
+ if (file_name_with_extension.endswith('.hpp')):
extension = '.hpp'
temp_file_name = temp_file_name + extension
Added: clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test?rev=316066&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test (added)
+++ clang-tools-extra/trunk/test/clang-tidy/nonstandard-file-extension.test Wed Oct 18 00:48:40 2017
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy -assume-filename=const-cast.cpp %s cppcoreguidelines-pro-type-const-cast %t
+
+const int *i;
+int *j;
+void f() { j = const_cast<int *>(i); }
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]
More information about the cfe-commits
mailing list