From 5c72b741a5846d49fd24c3e1c064e72f5bc923f2 Mon Sep 17 00:00:00 2001 From: John Bytheway Date: Mon, 27 May 2019 15:06:15 +0100 Subject: [PATCH] Add tests for NoLongCheck --- .travis.yml | 2 +- build-scripts/build.sh | 11 +++++++++- build-scripts/requirements.sh | 2 +- tools/clang-tidy-plugin/CMakeLists.txt | 3 +++ tools/clang-tidy-plugin/test/.clang-tidy | 1 + tools/clang-tidy-plugin/test/lit.cfg | 23 ++++++++++++++++++++ tools/clang-tidy-plugin/test/lit.site.cfg.in | 6 +++++ tools/clang-tidy-plugin/test/no-long.cpp | 4 ++++ 8 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tools/clang-tidy-plugin/test/.clang-tidy create mode 100644 tools/clang-tidy-plugin/test/lit.cfg create mode 100644 tools/clang-tidy-plugin/test/lit.site.cfg.in create mode 100644 tools/clang-tidy-plugin/test/no-long.cpp diff --git a/.travis.yml b/.travis.yml index daa7ee0419d64..1aaca516a5538 100644 --- a/.travis.yml +++ b/.travis.yml @@ -110,7 +110,7 @@ jobs: compiler: clang addons: &clang8 apt: - packages: ["clang-8", "libclang-8-dev", "llvm-8-dev", "libsdl2-dev", "libsdl2-ttf-dev", "libsdl2-image-dev", "libsdl2-mixer-dev"] + packages: ["clang-8", "libclang-8-dev", "llvm-8-dev", "llvm-8-tools", "libsdl2-dev", "libsdl2-ttf-dev", "libsdl2-image-dev", "libsdl2-mixer-dev"] sources: [*apt_sources, llvm-toolchain-xenial-8] # Finally check the compiler variants diff --git a/build-scripts/build.sh b/build-scripts/build.sh index 90ecca84bd905..0bae0c3924196 100755 --- a/build-scripts/build.sh +++ b/build-scripts/build.sh @@ -67,7 +67,16 @@ then if [ "$CATA_CLANG_TIDY" = "plugin" ] then make -j$num_jobs CataAnalyzerPlugin - CATA_CLANG_TIDY=$PWD/tools/clang-tidy-plugin/clang-tidy-plugin-support/bin/clang-tidy + export PATH=$PWD/tools/clang-tidy-plugin/clang-tidy-plugin-support/bin:$PATH + if ! which FileCheck + then + ls -l tools/clang-tidy-plugin/clang-tidy-plugin-support/bin + ls -l /usr/bin + echo "Missing FileCheck" + exit 1 + fi + CATA_CLANG_TIDY=clang-tidy + lit -v tools/clang-tidy-plugin/test fi "$CATA_CLANG_TIDY" --version diff --git a/build-scripts/requirements.sh b/build-scripts/requirements.sh index bfabcca6c602e..327463af1854a 100644 --- a/build-scripts/requirements.sh +++ b/build-scripts/requirements.sh @@ -30,7 +30,7 @@ if [ -n "${CODE_COVERAGE}" ]; then fi if [ -n "$CATA_CLANG_TIDY" ]; then - travis_retry pip install --user compiledb + travis_retry pip install --user compiledb lit fi # Influenced by https://github.com/zer0main/battleship/blob/master/build/windows/requirements.sh diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index ab576164d8777..30dab7b30abce 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -49,3 +49,6 @@ else() target_compile_options( CataAnalyzerPlugin PRIVATE -fno-exceptions -fno-rtti) endif() + +configure_file(test/lit.site.cfg.in test/lit.site.cfg @ONLY) +configure_file(test/.clang-tidy test/.clang-tidy COPYONLY) diff --git a/tools/clang-tidy-plugin/test/.clang-tidy b/tools/clang-tidy-plugin/test/.clang-tidy new file mode 100644 index 0000000000000..6179a0c5c0836 --- /dev/null +++ b/tools/clang-tidy-plugin/test/.clang-tidy @@ -0,0 +1 @@ +WarningsAsErrors: '-*' diff --git a/tools/clang-tidy-plugin/test/lit.cfg b/tools/clang-tidy-plugin/test/lit.cfg new file mode 100644 index 0000000000000..8bb0b760a4531 --- /dev/null +++ b/tools/clang-tidy-plugin/test/lit.cfg @@ -0,0 +1,23 @@ +import sys +import os +import lit.formats + +config.name = 'clang-tidy-cata' +config.test_format = lit.formats.ShTest(True) +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = os.path.join( + config.plugin_build_root, 'test') + +config.suffixes = ['.cpp'] + +check_clang_tidy = os.getenv('CHECK_CLANG_TIDY') +if not check_clang_tidy: + check_clang_tidy = os.path.join( + config.plugin_build_root, 'clang-tidy-plugin-support', 'bin', + 'check_clang_tidy.py') + +cata_plugin = os.path.join( + config.plugin_build_root, 'libCataAnalyzerPlugin.so') + +config.substitutions.append(('%check_clang_tidy', check_clang_tidy)) +config.substitutions.append(('%cata_plugin', cata_plugin)) diff --git a/tools/clang-tidy-plugin/test/lit.site.cfg.in b/tools/clang-tidy-plugin/test/lit.site.cfg.in new file mode 100644 index 0000000000000..eb6646f79c027 --- /dev/null +++ b/tools/clang-tidy-plugin/test/lit.site.cfg.in @@ -0,0 +1,6 @@ +import os + +config.plugin_build_root = "@CMAKE_CURRENT_BINARY_DIR@" + +lit_config.load_config( + config, os.path.join("@CMAKE_CURRENT_SOURCE_DIR@", "test", "lit.cfg")) diff --git a/tools/clang-tidy-plugin/test/no-long.cpp b/tools/clang-tidy-plugin/test/no-long.cpp new file mode 100644 index 0000000000000..a286c9d826408 --- /dev/null +++ b/tools/clang-tidy-plugin/test/no-long.cpp @@ -0,0 +1,4 @@ +// RUN: %check_clang_tidy %s cata-no-long %t -- -plugins=%cata_plugin -- + +long a; +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Variable 'a' declared as long. Prefer int or int64_t. [cata-no-long]