summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-12-07 13:19:44 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-12-07 13:19:53 (GMT)
commit3b4337adc79c3744ad7b78b05035b4b460fb5f48 (patch)
tree9057f7ab5b14df7f35589661016810a12c9dcdc3 /Tests
parent6bae244ad2a25a95a90dde1aa9047924b5acc530 (diff)
parent232467eb1c0dab9156cd8c4af56aad3959cbee4b (diff)
downloadCMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.zip
CMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.tar.gz
CMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.tar.bz2
Merge topic 'clang-tidy-export-fixes-dir'
232467eb1c clang-tidy: add <LANG>_CLANG_TIDY_EXPORT_FIXES_DIR property Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7982
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/ClangTidy/ExportFixesDir-Build-check.cmake35
-rw-r--r--Tests/RunCMake/ClangTidy/ExportFixesDir.cmake6
-rw-r--r--Tests/RunCMake/ClangTidy/ExportFixesDir2-Build-check.cmake35
-rw-r--r--Tests/RunCMake/ClangTidy/ExportFixesDir2-check.cmake35
-rw-r--r--Tests/RunCMake/ClangTidy/ExportFixesDir2.cmake6
-rw-r--r--Tests/RunCMake/ClangTidy/RunCMakeTest.cmake52
-rw-r--r--Tests/RunCMake/ClangTidy/export_fixes_subdir/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/ClangTidy/extra.c3
-rw-r--r--Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-check.cmake3
-rw-r--r--Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-prep.cmake1
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/pseudo_tidy.c13
12 files changed, 191 insertions, 0 deletions
diff --git a/Tests/RunCMake/ClangTidy/ExportFixesDir-Build-check.cmake b/Tests/RunCMake/ClangTidy/ExportFixesDir-Build-check.cmake
new file mode 100644
index 0000000..97ec52b
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/ExportFixesDir-Build-check.cmake
@@ -0,0 +1,35 @@
+if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.obj.yaml"
+ )
+else()
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.obj.yaml"
+ )
+endif()
diff --git a/Tests/RunCMake/ClangTidy/ExportFixesDir.cmake b/Tests/RunCMake/ClangTidy/ExportFixesDir.cmake
new file mode 100644
index 0000000..2b278da
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/ExportFixesDir.cmake
@@ -0,0 +1,6 @@
+enable_language(C)
+set(CMAKE_C_CLANG_TIDY "${PSEUDO_TIDY}" -some -args)
+set(CMAKE_C_CLANG_TIDY_EXPORT_FIXES_DIR clang-tidy)
+set(files ${CMAKE_CURRENT_SOURCE_DIR}/main.c ${CMAKE_CURRENT_SOURCE_DIR}/extra.c)
+add_executable(main ${files})
+add_subdirectory(export_fixes_subdir)
diff --git a/Tests/RunCMake/ClangTidy/ExportFixesDir2-Build-check.cmake b/Tests/RunCMake/ClangTidy/ExportFixesDir2-Build-check.cmake
new file mode 100644
index 0000000..f65d33c
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/ExportFixesDir2-Build-check.cmake
@@ -0,0 +1,35 @@
+if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.obj.yaml"
+ )
+else()
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.obj.yaml"
+ )
+endif()
diff --git a/Tests/RunCMake/ClangTidy/ExportFixesDir2-check.cmake b/Tests/RunCMake/ClangTidy/ExportFixesDir2-check.cmake
new file mode 100644
index 0000000..f65d33c
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/ExportFixesDir2-check.cmake
@@ -0,0 +1,35 @@
+if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/Debug/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/Debug/__/extra.c.obj.yaml"
+ )
+else()
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/clang-tidy/CMakeFiles/main.dir/extra.c.obj.yaml"
+ )
+ assert_any_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/main.c.obj.yaml"
+ )
+ assert_no_file_exists(
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.o.yaml"
+ "${RunCMake_TEST_BINARY_DIR}/export_fixes_subdir/clang-tidy/export_fixes_subdir/CMakeFiles/subdir.dir/__/extra.c.obj.yaml"
+ )
+endif()
diff --git a/Tests/RunCMake/ClangTidy/ExportFixesDir2.cmake b/Tests/RunCMake/ClangTidy/ExportFixesDir2.cmake
new file mode 100644
index 0000000..c81c49a
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/ExportFixesDir2.cmake
@@ -0,0 +1,6 @@
+enable_language(C)
+set(CMAKE_C_CLANG_TIDY "${PSEUDO_TIDY}" -some -args)
+set(CMAKE_C_CLANG_TIDY_EXPORT_FIXES_DIR clang-tidy)
+set(files ${CMAKE_CURRENT_SOURCE_DIR}/main.c)
+add_executable(main ${files})
+add_subdirectory(export_fixes_subdir)
diff --git a/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake b/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
index 5e3fbc4..01dbb61 100644
--- a/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ClangTidy/RunCMakeTest.cmake
@@ -30,3 +30,55 @@ if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
endif()
run_tidy(C-bad)
run_tidy(compdb)
+
+function(any_file_exists varname)
+ foreach(filename IN LISTS ARGN)
+ if(EXISTS "${filename}")
+ set("${varname}" 1 PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ set("${varname}" 0 PARENT_SCOPE)
+endfunction()
+
+function(assert_any_file_exists)
+ any_file_exists(exists ${ARGN})
+ if(NOT exists)
+ string(APPEND RunCMake_TEST_FAILED "Expected one of the following files to exist but they do not:\n")
+ foreach(filename IN LISTS ARGN)
+ string(APPEND RunCMake_TEST_FAILED " ${filename}\n")
+ endforeach()
+ set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(assert_no_file_exists)
+ any_file_exists(exists ${ARGN})
+ if(exists)
+ string(APPEND RunCMake_TEST_FAILED "Expected none of the following files to exist but one of them does:\n")
+ foreach(filename IN LISTS ARGN)
+ string(APPEND RunCMake_TEST_FAILED " ${filename}\n")
+ endforeach()
+ set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(run_tidy_export_fixes)
+ # Use a single build tree for tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExportFixesDir-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(ExportFixesDir)
+
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(ExportFixesDir-Build ${CMAKE_COMMAND} --build . --config Debug)
+ unset(RunCMake_TEST_OUTPUT_MERGE)
+
+ run_cmake(ExportFixesDir2)
+
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(ExportFixesDir2-Build ${CMAKE_COMMAND} --build . --config Debug)
+ unset(RunCMake_TEST_OUTPUT_MERGE)
+endfunction()
+run_tidy_export_fixes()
diff --git a/Tests/RunCMake/ClangTidy/export_fixes_subdir/CMakeLists.txt b/Tests/RunCMake/ClangTidy/export_fixes_subdir/CMakeLists.txt
new file mode 100644
index 0000000..af2db88
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/export_fixes_subdir/CMakeLists.txt
@@ -0,0 +1 @@
+add_executable(subdir ${files})
diff --git a/Tests/RunCMake/ClangTidy/extra.c b/Tests/RunCMake/ClangTidy/extra.c
new file mode 100644
index 0000000..d235550
--- /dev/null
+++ b/Tests/RunCMake/ClangTidy/extra.c
@@ -0,0 +1,3 @@
+void extra(void)
+{
+}
diff --git a/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-check.cmake b/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-check.cmake
new file mode 100644
index 0000000..d638fda
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-check.cmake
@@ -0,0 +1,3 @@
+if(EXISTS "${RunCMake_BINARY_DIR}/tidy-fixes.yaml")
+ string(APPEND RunCMake_TEST_FAILED "Expected ${RunCMake_BINARY_DIR}/tidy-fixes.yaml not to exist but it does")
+endif()
diff --git a/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-prep.cmake b/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-prep.cmake
new file mode 100644
index 0000000..1e89ffe
--- /dev/null
+++ b/Tests/RunCMake/CommandLine/E___run_co_compile-tidy-remove-fixes-prep.cmake
@@ -0,0 +1 @@
+file(TOUCH "${RunCMake_BINARY_DIR}/tidy-fixes.yaml")
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index 44ddddf..480ad09 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -47,6 +47,7 @@ run_cmake_command(E___run_co_compile-no-iwyu ${CMAKE_COMMAND} -E __run_co_compil
run_cmake_command(E___run_co_compile-bad-iwyu ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist -- command-does-not-exist)
run_cmake_command(E___run_co_compile-no--- ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist command-does-not-exist)
run_cmake_command(E___run_co_compile-no-cc ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist --)
+run_cmake_command(E___run_co_compile-tidy-remove-fixes ${CMAKE_COMMAND} -E __run_co_compile "--tidy=${CMAKE_COMMAND}\\;-E\\;true\\;--export-fixes=${RunCMake_BINARY_DIR}/tidy-fixes.yaml" -- ${CMAKE_COMMAND} -E true)
run_cmake_command(G_no-arg ${CMAKE_COMMAND} -B DummyBuildDir -G)
run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -B DummyBuildDir -G NoSuchGenerator)
diff --git a/Tests/RunCMake/pseudo_tidy.c b/Tests/RunCMake/pseudo_tidy.c
index a43133b..f227c06 100644
--- a/Tests/RunCMake/pseudo_tidy.c
+++ b/Tests/RunCMake/pseudo_tidy.c
@@ -1,8 +1,13 @@
+#ifndef _CRT_SECURE_NO_WARNINGS
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
+ FILE* f;
int i;
for (i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-p") == 0) {
@@ -20,6 +25,14 @@ int main(int argc, char* argv[])
fprintf(stderr, "stderr from bad command line arg '-bad'\n");
return 1;
}
+ if (strncmp(argv[i], "--export-fixes=", 15) == 0) {
+ f = fopen(argv[i] + 15, "w");
+ if (!f) {
+ fprintf(stderr, "Error opening %s for writing\n", argv[i] + 15);
+ return 1;
+ }
+ fclose(f);
+ }
if (argv[i][0] != '-') {
fprintf(stdout, "%s:0:0: warning: message [checker]\n", argv[i]);
break;