Switch check_clang_tidy to argparse and add a -resource-dir argument.

-resource-dir can be used to inject non-standard resource dirs via the
lit site config.

llvm-svn: 251021
This commit is contained in:
Manuel Klimek 2015-10-22 14:54:50 +00:00
parent 5884a1f5a6
commit 8f9e444061
36 changed files with 55 additions and 44 deletions

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s cert-err52-cpp %t -- -std=c++11
// RUN: %check_clang_tidy %s cert-err52-cpp %t -- -- -std=c++11
typedef void *jmp_buf;
extern int __setjmpimpl(jmp_buf);

View File

@ -16,13 +16,15 @@ ClangTidy Test Helper
This script runs clang-tidy in fix mode and verify fixes, messages or both.
Usage:
check_clang_tidy.py <source-file> <check-name> <temp-file> \
[optional clang-tidy arguments]
check_clang_tidy.py [-resource-dir <resource-dir>] \
<source-file> <check-name> <temp-file> \
-- [optional clang-tidy arguments]
Example:
// RUN: %check_clang_tidy %s llvm-include-order %t -- -isystem $(dirname %s)/Inputs/Headers
"""
import argparse
import re
import subprocess
import sys
@ -34,21 +36,30 @@ def write_file(file_name, text):
f.truncate()
def main():
if len(sys.argv) < 4:
sys.exit('Not enough arguments.')
parser = argparse.ArgumentParser()
parser.add_argument('-resource-dir')
parser.add_argument('input_file_name')
parser.add_argument('check_name')
parser.add_argument('temp_file_name')
args, extra_args = parser.parse_known_args()
resource_dir = args.resource_dir
input_file_name = args.input_file_name
check_name = args.check_name
temp_file_name = args.temp_file_name
input_file_name = sys.argv[1]
extension = '.cpp'
if (input_file_name.endswith('.c')):
extension = '.c'
temp_file_name = temp_file_name + extension
check_name = sys.argv[2]
temp_file_name = sys.argv[3] + extension
clang_tidy_extra_args = sys.argv[4:]
clang_tidy_extra_args = extra_args
if len(clang_tidy_extra_args) == 0:
clang_tidy_extra_args = ['--', '--std=c++11'] if extension == '.cpp' \
else ['--']
if resource_dir is not None:
clang_tidy_extra_args.append('-resource-dir=%s' % resource_dir)
with open(input_file_name, 'r') as input_file:
input_text = input_file.read()

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s google-readability-casting %t -- -x c
// RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
// The testing script always adds .cpp extension to the input file name, so we
// need to run clang-tidy directly in order to verify handling of .c files:
// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s google-readability-todo %t -config="{User: 'some user'}" --
// RUN: %check_clang_tidy %s google-readability-todo %t -- -config="{User: 'some user'}" --
// TODOfix this1
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: missing username/bug in TODO

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s google-runtime-int %t \
// RUN: %check_clang_tidy %s google-runtime-int %t -- \
// RUN: -config='{CheckOptions: [ \
// RUN: {key: google-runtime-int.UnsignedTypePrefix, value: "std::uint"}, \
// RUN: {key: google-runtime-int.SignedTypePrefix, value: "std::int"}, \

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s llvm-include-order %t -- -isystem %S/Inputs/Headers
// RUN: %check_clang_tidy %s llvm-include-order %t -- -- -isystem %S/Inputs/Headers
// CHECK-MESSAGES: [[@LINE+2]]:1: warning: #includes are not sorted properly
#include "j.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-assert-side-effect %t -config="{CheckOptions: [{key: misc-assert-side-effect.CheckFunctionCalls, value: 1}, {key: misc-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert'}]}" -- -fexceptions
// RUN: %check_clang_tidy %s misc-assert-side-effect %t -- -config="{CheckOptions: [{key: misc-assert-side-effect.CheckFunctionCalls, value: 1}, {key: misc-assert-side-effect.AssertMacros, value: 'assert,assert2,my_assert,convoluted_assert'}]}" -- -fexceptions
//===--- assert definition block ------------------------------------------===//
int abort() { return 0; }

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-move-constructor-init %t -- -std=c++11 -isystem %S/Inputs/Headers
// RUN: %check_clang_tidy %s misc-move-constructor-init %t -- -- -std=c++11 -isystem %S/Inputs/Headers
#include <s.h>

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-new-delete-overloads %t -- -std=c++14 -fsized-deallocation
// RUN: %check_clang_tidy %s misc-new-delete-overloads %t -- -- -std=c++14 -fsized-deallocation
typedef decltype(sizeof(int)) size_t;

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-new-delete-overloads %t -- -std=c++14
// RUN: %check_clang_tidy %s misc-new-delete-overloads %t -- -- -std=c++14
typedef decltype(sizeof(int)) size_t;

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-sizeof-container %t -- -std=c++11 -target x86_64-unknown-unknown
// RUN: %check_clang_tidy %s misc-sizeof-container %t -- -- -std=c++11 -target x86_64-unknown-unknown
namespace std {

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-static-assert %t -- -std=c11
// RUN: %check_clang_tidy %s misc-static-assert %t -- -- -std=c11
// RUN: clang-tidy %s -checks=-*,misc-static-assert -- -std=c99 | count 0
void abort() {}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-throw-by-value-catch-by-reference %t -- -std=c++11 -fcxx-exceptions
// RUN: %check_clang_tidy %s misc-throw-by-value-catch-by-reference %t -- -- -std=c++11 -fcxx-exceptions
class logic_error {

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -xc
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -- -xc
// Basic removal
// =============

View File

@ -1,6 +1,6 @@
// RUN: echo "static void staticFunctionHeader(int i) {}" > %T/header.h
// RUN: echo "static void staticFunctionHeader(int /*i*/) {}" > %T/header-fixed.h
// RUN: %check_clang_tidy %s misc-unused-parameters %t -header-filter='.*' -- -std=c++11 -fno-delayed-template-parsing
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- -header-filter='.*' -- -std=c++11 -fno-delayed-template-parsing
// RUN: diff %T/header.h %T/header-fixed.h
#include "header.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -std=c++11 -I %S/Inputs/modernize-loop-convert
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -std=c++11 -I %S/Inputs/modernize-loop-convert
#include "structures.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t \
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
// RUN: -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'camelBack'}]}" \
// RUN: -- -std=c++11 -I %S/Inputs/modernize-loop-convert

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -std=c++11 -I %S/Inputs/modernize-loop-convert
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -std=c++11 -I %S/Inputs/modernize-loop-convert
#include "structures.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t \
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
// RUN: -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'lower_case'}]}" \
// RUN: -- -std=c++11 -I %S/Inputs/modernize-loop-convert

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -std=c++11 -I %S/Inputs/modernize-loop-convert
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -std=c++11 -I %S/Inputs/modernize-loop-convert
#include "structures.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-loop-convert %t \
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- \
// RUN: -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'UPPER_CASE'}]}" \
// RUN: -- -std=c++11 -I %S/Inputs/modernize-loop-convert

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -std=c++11 -fno-delayed-template-parsing
// RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -- -std=c++11 -fno-delayed-template-parsing
// CHECK-FIXES: #include <utility>

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- \
// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- \
// RUN: -std=c++11 -I %S/Inputs/modernize-replace-auto-ptr
// CHECK-FIXES: #include <utility>

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-auto %t -- \
// RUN: %check_clang_tidy %s modernize-use-auto %t -- -- \
// RUN: -std=c++11 -I %S/Inputs/modernize-use-auto
#include "containers.h"

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-default %t -- -std=c++11 -fno-delayed-template-parsing
// RUN: %check_clang_tidy %s modernize-use-default %t -- -- -std=c++11 -fno-delayed-template-parsing
class A {
public:

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- \
// RUN: -std=c++98 -Wno-non-literal-null-conversion
//
// Some parts of the test (e.g. assignment of `const int` to `int *`) fail in

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-nullptr %t \
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \
// RUN: -config="{CheckOptions: [{key: modernize-use-nullptr.NullMacros, value: 'MY_NULL,NULL'}]}" \
// RUN: -- -std=c++11

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s modernize-use-override %t -- -std=c++98
// RUN: %check_clang_tidy %s modernize-use-override %t -- -- -std=c++98
struct Base {
virtual ~Base() {}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" --
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" --
void do_something(const char *) {}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 1}]}" --
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 1}]}" --
void do_something(const char *) {}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" --
// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" --
void do_something(const char *) {}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-function-size %t -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}]}' -- -std=c++11
// RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}]}' -- -std=c++11
void foo1() {
}

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-identifier-naming %t \
// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
// RUN: -config='{CheckOptions: [ \
// RUN: {key: readability-identifier-naming.AbstractClassCase, value: CamelCase}, \
// RUN: {key: readability-identifier-naming.AbstractClassPrefix, value: 'A'}, \

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- -std=c++11 -fno-delayed-template-parsing
// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- -- -std=c++11 -fno-delayed-template-parsing
void consistentFunction(int a, int b, int c);
void consistentFunction(int a, int b, int c);

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalAssignment", value: 1}]}" --
// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalAssignment", value: 1}]}" --
void chained_conditional_compound_assignment(int i) {
bool b;

View File

@ -1,4 +1,4 @@
// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalReturn", value: 1}]}" --
// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{key: "readability-simplify-boolean-expr.ChainedConditionalReturn", value: 1}]}" --
bool chained_conditional_compound_return(int i) {
if (i < 0) {