Index: clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %run_clang_tidy --help -// RUN: rm -rf %t -// RUN: mkdir %t -// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/test.cpp\",\"file\":\"%/t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json -// RUN: echo "Checks: '-*,modernize-use-auto'" > %t/.clang-tidy -// RUN: echo "WarningsAsErrors: '*'" >> %t/.clang-tidy -// RUN: echo "CheckOptions:" >> %t/.clang-tidy -// RUN: echo " - key: modernize-use-auto.MinTypeNameLength" >> %t/.clang-tidy -// RUN: echo " value: '0'" >> %t/.clang-tidy -// RUN: cp "%s" "%t/test.cpp" -// RUN: cd "%t" -// RUN: not %run_clang_tidy "test.cpp" - -int main() -{ - int* x = new int(); - delete x; -} Index: clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_config-file.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_config-file.cpp @@ -0,0 +1,33 @@ +// under test: +// - .clang-tidy read from file & treat warnings as errors +// - return code of run-clang-tidy on those errors + +// First make sure clang-tidy is executable and can print help without crashing: +// RUN: %run_clang_tidy --help + +// use %t as directory instead of file: +// RUN: rm -rf %t +// RUN: mkdir %t + +// add this file to %t, add compile_commands for it and .clang-tidy config: +// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/test.cpp\",\"file\":\"%/t/test.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json +// RUN: echo "Checks: '-*,modernize-use-auto'" > %t/.clang-tidy +// RUN: echo "WarningsAsErrors: '*'" >> %t/.clang-tidy +// RUN: echo "CheckOptions:" >> %t/.clang-tidy +// RUN: echo " - key: modernize-use-auto.MinTypeNameLength" >> %t/.clang-tidy +// RUN: echo " value: '0'" >> %t/.clang-tidy +// RUN: cp "%s" "%t/test.cpp" + +// execute and check: +// RUN: cd "%t" +// RUN: not %run_clang_tidy "test.cpp" > %t/msg.txt 2>&1 +// RUN: FileCheck -input-file=%t/msg.txt -check-prefix=CHECK-MESSAGES %s \ +// RUN: -implicit-check-not='{{warning|error|note}}:' + +int main() +{ + int* x = new int(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: error: {{.+}} [modernize-use-auto,-warnings-as-errors] + + delete x; +} Index: clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_export-diagnostics.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_export-diagnostics.cpp @@ -0,0 +1,33 @@ +// under test: +// - parsing and using compile_commands +// - export fixes to yaml file + +// use %t as directory instead of file, +// because "compile_commands.json" must have exactly that name: +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo '[{"directory":"%/S","command":"clang++ -c %s","file":"%s"}]' \ +// RUN: > %t/compile_commands.json + +// execute and check: +// RUN: cd "%t" +// RUN: %run_clang_tidy -checks='-*,bugprone-sizeof-container,modernize-use-auto' \ +// RUN: -p="%/t" -export-fixes=%t/fixes.yaml > %t/msg.txt 2>&1 +// RUN: FileCheck -input-file=%t/msg.txt -check-prefix=CHECK-MESSAGES %s \ +// RUN: -implicit-check-not='{{warning|error|note}}:' +// RUN: FileCheck -input-file=%t/fixes.yaml -check-prefix=CHECK-YAML %s + +#include +int main() +{ + std::vector vec; + std::vector::iterator iter = vec.begin(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators + // CHECK-YAML: modernize-use-auto + + return sizeof(vec); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: sizeof() doesn't return the size of the container; did you mean .size()? [bugprone-sizeof-container] + // CHECK-YAML: bugprone-sizeof-container + // After https://reviews.llvm.org/D72730 --> CHECK-YAML-NOT: bugprone-sizeof-container +} +