[tests] extend compilation database test with changed-files-index options

Summary:
Add test for compilation database and --changed-files-index option
Fix one bug that the test uncovered

Reviewed By: dulmarod

Differential Revision: D4198502

fbshipit-source-id: 9039c65
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 34739522c0
commit 548918e524

@ -42,7 +42,7 @@ let read_files_to_compile () =
| Some lines -> | Some lines ->
IList.fold_left IList.fold_left
(fun changed_files line -> (fun changed_files line ->
let file = replace_header_file_with_source_file (DB.abs_source_file_from_path line) in let file = replace_header_file_with_source_file (DB.source_file_from_string line) in
DB.SourceFileSet.add file changed_files) DB.SourceFileSet.add file changed_files)
changed_files lines changed_files lines

@ -12,7 +12,7 @@ CMAKE_BUILD_DIR = $(CMAKE_DIR)/_build
ANALYZER = infer ANALYZER = infer
CLEAN_EXTRA = $(CMAKE_BUILD_DIR) CLEAN_EXTRA = $(CMAKE_BUILD_DIR)
INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(CMAKE_DIR) INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(CMAKE_DIR) --changed-files-index $(CMAKE_DIR)/index.txt
SOURCES = $(CMAKE_DIR)/hello.cpp SOURCES = $(CMAKE_DIR)/hello.cpp
OBJECTS = $(CMAKE_BUILD_DIR)/compile_commands.json OBJECTS = $(CMAKE_BUILD_DIR)/compile_commands.json
INFERPRINT_OPTIONS = --issues-tests INFERPRINT_OPTIONS = --issues-tests

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

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

@ -7,7 +7,21 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
void test() { #include "lib1.h"
#include "lib2.h"
void test0() {
int* s = nullptr; // requires -std=c++11 flag int* s = nullptr; // requires -std=c++11 flag
*s = 42; *s = 42;
} }
int test1() {
int* s = nullptr;
return deref1(s); // should be nullderef
}
void test2() {
int* s = nullptr;
return deref2(s); // should be nullderef, but will be skipped
// because of --changed-files-index option
}

@ -0,0 +1,11 @@
/*
* 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.
*/
#include "lib1.h"
int deref1(int* p) { return *p; }

@ -0,0 +1,9 @@
/*
* 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.
*/
int deref1(int* p);

@ -0,0 +1,11 @@
/*
* 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.
*/
#include "lib2.h"
int deref2(int* p) { return *p; }

@ -0,0 +1,9 @@
/*
* 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.
*/
int deref2(int* p);
Loading…
Cancel
Save