[tests] convert clang_compilation_db test to Makefile

Reviewed By: akotulski

Differential Revision: D4168022

fbshipit-source-id: 0d2b9c4
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 15d80e04df
commit b3209e2c18

9
.gitignore vendored

@ -12,10 +12,17 @@
*.orig
*.rej
*.start
# generated by tests
_build
/infer/tests/codetoanalyze/java/*/codetoanalyze
*.exp.test
*.exp.test.*
*.test.dot
duplicates.txt
infer/tests/codetoanalyze/java/*/codetoanalyze
*.capture.sh
*.capture.bdump
*.capture.biniou
# Directories generated by Ocamlbuild
_build

@ -20,6 +20,9 @@ endif
ifneq ($(BUCK),no)
BUILD_SYSTEMS_TESTS += buck
endif
ifneq ($(CMAKE),no)
BUILD_SYSTEMS_TESTS += clang_compilation_db
endif
DIRECT_TESTS=
ifeq ($(BUILD_C_ANALYZERS),yes)

@ -20,6 +20,7 @@ CC = @CC@
CFLAGS = @CFLAGS@
CLANG_INCLUDES = @CLANG_INCLUDES@
CLANG_PREFIX = @CLANG_PREFIX@
CMAKE = @CMAKE@
CPP = @CPP@
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@

@ -98,8 +98,8 @@ AS_IF([test "x$enable_c_analyzers" = "xyes"], [
AC_CHECK_TOOL([SHASUM], [shasum], [no])
AC_ASSERT_PROG([shasum], [$SHASUM])
# cmake is required to build llvm+clang
AC_CHECK_TOOL([CMAKE], [cmake], [no])
AS_IF([test "x$is_release_tree" = "xno"], [
AC_CHECK_TOOL([CMAKE], [cmake], [no])
AC_ASSERT_PROG([cmake], [$CMAKE])
])
AC_ARG_ENABLE(ocamlopt-custom-cc,
@ -116,7 +116,6 @@ AC_CHECK_TOOL([PYTHON27], [python2.7], [no])
AC_ASSERT_PROG([python2.7], [$PYTHON27])
AC_CHECK_TOOL([XCODE_SELECT], [xcode-select], [no])
AC_SUBST([XCODE_SELECT])
# prefer clang over gcc because the plugins makes use of
@ -232,7 +231,6 @@ fi
AC_CHECK_TOOL([ATDGEN], [atdgen], [no])
AC_ASSERT_PROG([atdgen], [$ATDGEN])
AC_SUBST([ATDGEN])
AC_ARG_ENABLE(ocaml-annot,
AS_HELP_STRING([--disable-ocaml-annot], [do not build ocaml .annot files]),

@ -61,7 +61,6 @@ CODETOANALYZE_DIR = os.path.join(SCRIPT_DIR, 'codetoanalyze')
EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs')
ALL_TESTS = [
'clang_compilation_database',
'cmake',
'componentkit',
'delete',
@ -421,27 +420,6 @@ class BuildIntegrationTest(unittest.TestCase):
# remove build/ directory
shutil.rmtree(build_root)
def test_clang_compilation_database_integration(
self,
enabled=None,
root=os.path.join(CODETOANALYZE_DIR, 'clang_compilation_database'),
report_fname='clang_compilation_database_report.json'):
build_root = os.path.join(root, 'build')
if test('clang_compilation_database', 'clang compilation database test',
build_root,
[{'compile': ['cmake', '-DCMAKE_EXPORT_COMPILE_COMMANDS=1', '..']},
{'compile': ['clang-compilation-database', 'compile_commands.json']}],
available=lambda: is_tool_available(['cmake', '--version']),
enabled=enabled,
# remove build/ directory just in case
preprocess=lambda: shutil.rmtree(build_root, True),
# cmake produces absolute paths using the real path
postprocess=(lambda errors:
make_paths_relative_in_report(
os.path.realpath(root), errors))):
# remove build/ directory
shutil.rmtree(build_root)
def test_utf8_in_pwd_integration(self):
if not 'utf8_in_pwd' in to_test:
print('\nSkipping utf8_in_pwd integration test')

@ -0,0 +1,31 @@
# Copyright (c) 2016 - present Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
TESTS_DIR = ../..
CMAKE_DIR = ../codetoanalyze/clang_compilation_database
CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build
ANALYZER = infer
CLEAN_EXTRA = $(CMAKE_BUILD_DIR)
INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(CMAKE_DIR)
SOURCES = $(CMAKE_DIR)/hello.cpp
OBJECTS = $(CMAKE_BUILD_DIR)/compile_commands.json
INFERPRINT_OPTIONS = --issues-tests
include $(TESTS_DIR)/base.make
$(CMAKE_BUILD_DIR):
$(MKDIR_P) $@
$(CMAKE_BUILD_DIR)/compile_commands.json: $(SOURCES) $(CMAKE_DIR)/CMakeLists.txt $(CMAKE_BUILD_DIR)
cd $(CMAKE_BUILD_DIR) && \
$(CMAKE) -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
infer-out/report.json: $(CMAKE_BUILD_DIR)/compile_commands.json $(INFER_BIN) $(SOURCES)
$(call silent_on_success,\
$(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) -- clang-compilation-database $<)

@ -0,0 +1 @@
hello.cpp, test, 2, NULL_DEREFERENCE, [start of procedure test()]

@ -1,7 +0,0 @@
[
{
"bug_type": "NULL_DEREFERENCE",
"file": "hello.cpp",
"procedure": "test"
}
]
Loading…
Cancel
Save