Author: Alexander Lanin Date: 2020-10-19T10:29:08-04:00 New Revision: 627c01bee0deb353b3e3e90c1b8d0b6d73464466
URL: https://github.com/llvm/llvm-project/commit/627c01bee0deb353b3e3e90c1b8d0b6d73464466 DIFF: https://github.com/llvm/llvm-project/commit/627c01bee0deb353b3e3e90c1b8d0b6d73464466.diff LOG: Extend tests of run-clang-tidy new test: parsing and using compile_commands new test: export fixes to yaml file old test extended with CHECK-MESSAGES in order to ensure that they "fail as intended" Added: clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_config-file.cpp clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_export-diagnostics.cpp Modified: Removed: clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp ################################################################################ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp deleted file mode 100644 index 0d0e41e022ae..000000000000 --- a/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; -} diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_config-file.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_config-file.cpp new file mode 100644 index 000000000000..3976ccf8860d --- /dev/null +++ b/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; +} diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_export-diagnostics.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy_export-diagnostics.cpp new file mode 100644 index 000000000000..f2c97269391e --- /dev/null +++ b/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 <vector> +int main() +{ + std::vector<int> vec; + std::vector<int>::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 +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits