[cmake] Support running extra clang tool tests without static analyzer
Support running the extra clang tool tests when the static analyzer
is disabled. Disable the relevant clang-tidy tests and one include-fixer
test that require it to work.
Previously, the tests were disabled entirely with
CLANG_ENABLE_STATIC_ANALYZER being false. Now, the tests are being
enabled and the relevant tests are excluded and marked unsupported
appropriately.
In order to disable clang-tidy tests, the whole test directory is added
to the exclude lists, to avoid having to explicitly add 'REQUIRES' line
to every single test. If the other solution is preferable, I can update
the patch.
The yamldb_plugin include-fixer test is also updated to be disabled
without static analyzer. It fails in that case because clang is not
outputting a replacement suggestion -- but I don't know the exact
reason why it does not do that.
Differential Revision: https://reviews.llvm.org/D37188
llvm-svn: 311983
GitOrigin-RevId: a81de445c187ed9d0bbfb52a78a8de21b596fd44
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac8f16b..760340a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,8 +15,7 @@
add_subdirectory(tool-template)
# Add the common testsuite after all the tools.
-# TODO: Support tests with more granularity when features are off?
-if(CLANG_ENABLE_STATIC_ANALYZER AND CLANG_INCLUDE_TESTS)
+if(CLANG_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
endif()
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 996afec..90de6c7 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -15,6 +15,9 @@
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
+llvm_canonicalize_cmake_booleans(
+ CLANG_ENABLE_STATIC_ANALYZER)
+
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@@ -31,11 +34,6 @@
endif()
set(CLANG_TOOLS_TEST_DEPS
- # clang-tidy tests require it.
- clang-headers
-
- # For the clang-tidy libclang integration test.
- c-index-test
# For the clang-apply-replacements test that uses clang-rename.
clang-rename
@@ -47,7 +45,6 @@
clang-move
clang-query
clang-reorder-fields
- clang-tidy
find-all-symbols
modularize
pp-trace
@@ -56,6 +53,17 @@
ExtraToolsUnitTests
)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ list(APPEND CLANG_TOOLS_TEST_DEPS
+ # For the clang-tidy libclang integration test.
+ c-index-test
+ # clang-tidy tests require it.
+ clang-headers
+
+ clang-tidy
+ )
+endif()
+
set(llvm_utils
FileCheck count not
)
diff --git a/test/include-fixer/yamldb_plugin.cpp b/test/include-fixer/yamldb_plugin.cpp
index 8de643e..5b6760a 100644
--- a/test/include-fixer/yamldb_plugin.cpp
+++ b/test/include-fixer/yamldb_plugin.cpp
@@ -1,23 +1,24 @@
+// REQUIRES: static-analyzer
// RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin -Xclang clang-include-fixer -fspell-checking -Xclang -plugin-arg-clang-include-fixer -Xclang -input=%p/Inputs/fake_yaml_db.yaml 2>&1 | FileCheck %s
foo f;
foo g;
unknown u;
-// CHECK: yamldb_plugin.cpp:3:1: error: unknown type name 'foo'; did you mean 'foo'?
-// CHECK: Number FIX-ITs = 1
-// CHECK: FIX-IT: Replace [3:1 - 3:4] with "foo"
-// CHECK: yamldb_plugin.cpp:3:1: note: Add '#include "foo.h"' to provide the missing declaration [clang-include-fixer]
-// CHECK: Number FIX-ITs = 1
-// CHECK: FIX-IT: Insert "#include "foo.h"
// CHECK: yamldb_plugin.cpp:4:1: error: unknown type name 'foo'; did you mean 'foo'?
// CHECK: Number FIX-ITs = 1
// CHECK: FIX-IT: Replace [4:1 - 4:4] with "foo"
// CHECK: yamldb_plugin.cpp:4:1: note: Add '#include "foo.h"' to provide the missing declaration [clang-include-fixer]
// CHECK: Number FIX-ITs = 1
// CHECK: FIX-IT: Insert "#include "foo.h"
-// CHECK: " at 3:1
-// CHECK: yamldb_plugin.cpp:5:1:
+// CHECK: yamldb_plugin.cpp:5:1: error: unknown type name 'foo'; did you mean 'foo'?
+// CHECK: Number FIX-ITs = 1
+// CHECK: FIX-IT: Replace [5:1 - 5:4] with "foo"
+// CHECK: yamldb_plugin.cpp:5:1: note: Add '#include "foo.h"' to provide the missing declaration [clang-include-fixer]
+// CHECK: Number FIX-ITs = 1
+// CHECK: FIX-IT: Insert "#include "foo.h"
+// CHECK: " at 4:1
+// CHECK: yamldb_plugin.cpp:6:1:
// CHECK: error: unknown type name 'unknown'
// CHECK: Number FIX-ITs = 0
// CHECK-NOT: error
diff --git a/test/lit.cfg b/test/lit.cfg
index 0e7de84..25f2918 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -192,13 +192,18 @@
if platform.system() not in ['Windows']:
config.available_features.add('ansi-escape-sequences')
-check_clang_tidy = os.path.join(
- config.test_source_root, "clang-tidy", "check_clang_tidy.py")
-config.substitutions.append(
- ('%check_clang_tidy',
- '%s %s' % (config.python_executable, check_clang_tidy)) )
-clang_tidy_diff = os.path.join(
- config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py")
-config.substitutions.append(
- ('%clang_tidy_diff',
- '%s %s' % (config.python_executable, clang_tidy_diff)) )
+if config.clang_staticanalyzer:
+ config.available_features.add('static-analyzer')
+ check_clang_tidy = os.path.join(
+ config.test_source_root, "clang-tidy", "check_clang_tidy.py")
+ config.substitutions.append(
+ ('%check_clang_tidy',
+ '%s %s' % (config.python_executable, check_clang_tidy)) )
+ clang_tidy_diff = os.path.join(
+ config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py")
+ config.substitutions.append(
+ ('%clang_tidy_diff',
+ '%s %s' % (config.python_executable, clang_tidy_diff)) )
+else:
+ # exclude the clang-tidy test directory
+ config.excludes.append('clang-tidy')
diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
index f310b59..86e9617 100644
--- a/test/lit.site.cfg.in
+++ b/test/lit.site.cfg.in
@@ -10,6 +10,7 @@
config.clang_libs_dir = "@SHLIBDIR@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.target_triple = "@TARGET_TRIPLE@"
+config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
index 49978d4..385759d 100644
--- a/unittests/CMakeLists.txt
+++ b/unittests/CMakeLists.txt
@@ -9,6 +9,8 @@
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-move)
add_subdirectory(clang-query)
-add_subdirectory(clang-tidy)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+ add_subdirectory(clang-tidy)
+endif()
add_subdirectory(clangd)
add_subdirectory(include-fixer)