[tests] Create simple compilation database integration test

Summary: Right now there is no test for compilation database integration. Add one

Reviewed By: jvillard

Differential Revision: D4118769

fbshipit-source-id: 5591de7
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent c9bac51b81
commit 80f25d17fd

@ -56,13 +56,16 @@ let touch_start_file () =
try Unix.close (Unix.openfile start flags file_perm)
with Unix.Unix_error (Unix.EEXIST, _, _) -> ()
type build_mode = Analyze | Ant | Buck | Gradle | Java | Javac | Make | Mvn | Ndk | Xcode
type build_mode =
| Analyze | Ant | Buck | ClangCompilationDatabase | Gradle | Java | Javac | Make | Mvn | Ndk
| Xcode
let build_mode_of_string path =
match Filename.basename path with
| "analyze" -> Analyze
| "ant" -> Ant
| "buck" -> Buck
| "clang-compilation-database" -> ClangCompilationDatabase
| "gradle" | "gradlew" -> Gradle
| "java" -> Java
| "javac" -> Javac
@ -147,7 +150,7 @@ let analyze = function
| Java | Javac ->
(* In Java and Javac modes, analysis is invoked from capture. *)
()
| Analyze | Ant | Buck | Gradle | Make | Mvn | Ndk | Xcode ->
| Analyze | Ant | Buck | ClangCompilationDatabase | Gradle | Make | Mvn | Ndk | Xcode ->
if not (Sys.file_exists Config.(results_dir // captured_dir_name)) then (
L.err "There was nothing to analyze, exiting" ;
Config.print_usage_exit ()

@ -74,15 +74,13 @@ let create_files_stack compilation_database =
stack
let swap_command cmd =
let plusplus = "++" in
let clang = "clang" in
let clangplusplus = "clang++" in
if Utils.string_is_suffix clang cmd then
Config.wrappers_dir // clang
else if Utils.string_is_suffix clangplusplus cmd then
if Utils.string_is_suffix plusplus cmd then
Config.wrappers_dir // clangplusplus
else
(* The command in the compilation database json emitted by buck can only be clang or clang++ *)
failwithf "Unexpected command name in Buck compilation database: %s" cmd
Config.wrappers_dir // clang
let run_compilation_file compilation_database file =
try

@ -63,6 +63,7 @@ EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs')
ALL_TESTS = [
'assembly',
'buck',
'clang_compilation_database',
'cmake',
'componentkit',
'delete',
@ -442,6 +443,26 @@ 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:

@ -0,0 +1,4 @@
cmake_minimum_required (VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
project (HELLO)
add_library (Hello hello.cpp)

@ -0,0 +1,13 @@
/*
* Copyright (c) 2015 - 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.
*/
void test() {
int* s = nullptr; // requires -std=c++11 flag
*s = 42;
}

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