[tests] Convert the linter tests to the new direct format

Reviewed By: jberdine

Differential Revision: D3877153

fbshipit-source-id: a0efb3c
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot 0
parent da01c2b94a
commit fe21442d47

@ -14,8 +14,5 @@
# TODO: this line exists only to support buck integration in infer/tests/build_systems/build_integration_tests.py
infer = //infer/tests/endtoend/java/infer:infer
linters = //infer/tests/endtoend:linters
componentkit = //infer/tests/endtoend:componentkit
[project]
ignore = .git, .ml, .mli

@ -1,7 +1,4 @@
{
"enable_checks": [
"GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL"
],
"skip_translation": [
{
"language": "Java",

@ -19,7 +19,7 @@ DIRECT_TESTS += java_checkers_test java_eradicate_test java_infer_test java_trac
endif
ifneq ($(XCODE_SELECT),no)
TARGETS_TO_TEST += objc objcpp
DIRECT_TESTS += objc_infer_test
DIRECT_TESTS += objc_infer_test objc_linters objcpp_linters
endif
TARGETS_TO_TEST := $(shell echo $(TARGETS_TO_TEST))
@ -136,6 +136,12 @@ java_quandary_test:
objc_infer_test:
make -C ./infer/tests/codetoanalyze/objc/errors test
objc_linters:
make -C ./infer/tests/codetoanalyze/objc/linters test
objcpp_linters:
make -C ./infer/tests/codetoanalyze/objcpp/linters test
buck_test: infer
make $(DIRECT_TESTS)
NO_BUCKD=1 buck clean

@ -482,16 +482,24 @@ let module IssuesTests = {
| Some proc_loc =>
let line_offset = loc.Location.line - proc_loc.Location.line;
(proc_loc.Location.file, line_offset)
| None => (loc.Location.file, 0)
| None => (loc.Location.file, loc.Location.line)
};
let should_report =
ekind == Exceptions.Kerror ||
IList.exists
(Localise.equal error_name)
[
Localise.return_value_ignored,
Localise.assign_pointer_warning,
Localise.bad_pointer_comparison,
Localise.cxx_reference_captured_in_objc_block,
Localise.direct_atomic_property_access,
Localise.field_not_null_checked,
Localise.global_variable_initialized_with_function_or_method_call,
Localise.mutable_local_variable_in_component_file,
Localise.parameter_not_null_checked,
Localise.field_not_null_checked
Localise.registered_observer_being_deallocated,
Localise.return_value_ignored,
Localise.strong_delegate_warning
];
if (in_footprint && should_report && error_filter source_file error_desc error_name) {
F.fprintf

@ -32,26 +32,32 @@ let compare (s1: string) (s2: string) = Pervasives.compare s1 s2
let equal s1 s2 =
compare s1 s2 = 0
let context_leak = "CONTEXT_LEAK"
let analysis_stops = "ANALYSIS_STOPS"
let array_out_of_bounds_l1 = "ARRAY_OUT_OF_BOUNDS_L1"
let array_out_of_bounds_l2 = "ARRAY_OUT_OF_BOUNDS_L2"
let array_out_of_bounds_l3 = "ARRAY_OUT_OF_BOUNDS_L3"
let assign_pointer_warning = "ASSIGN_POINTER_WARNING"
let bad_pointer_comparison = "BAD_POINTER_COMPARISON"
let class_cast_exception = "CLASS_CAST_EXCEPTION"
let comparing_floats_for_equality = "COMPARING_FLOAT_FOR_EQUALITY"
let condition_is_assignment = "CONDITION_IS_ASSIGNMENT"
let condition_always_false = "CONDITION_ALWAYS_FALSE"
let condition_always_true = "CONDITION_ALWAYS_TRUE"
let context_leak = "CONTEXT_LEAK"
let cxx_reference_captured_in_objc_block = "CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK"
let dangling_pointer_dereference = "DANGLING_POINTER_DEREFERENCE"
let deallocate_stack_variable = "DEALLOCATE_STACK_VARIABLE"
let deallocate_static_memory = "DEALLOCATE_STATIC_MEMORY"
let deallocation_mismatch = "DEALLOCATION_MISMATCH"
let direct_atomic_property_access = "DIRECT_ATOMIC_PROPERTY_ACCESS"
let divide_by_zero = "DIVIDE_BY_ZERO"
let empty_vector_access = "EMPTY_VECTOR_ACCESS"
let field_not_null_checked = "IVAR_NOT_NULL_CHECKED"
let global_variable_initialized_with_function_or_method_call =
"GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL"
let inherently_dangerous_function = "INHERENTLY_DANGEROUS_FUNCTION"
let memory_leak = "MEMORY_LEAK"
let mutable_local_variable_in_component_file = "MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE"
let null_dereference = "NULL_DEREFERENCE"
let parameter_not_null_checked = "PARAMETER_NOT_NULL_CHECKED"
let null_test_after_dereference = "NULL_TEST_AFTER_DEREFERENCE"
@ -68,6 +74,7 @@ let return_statement_missing = "RETURN_STATEMENT_MISSING"
let skip_function = "SKIP_FUNCTION"
let skip_pointer_dereference = "SKIP_POINTER_DEREFERENCE"
let stack_variable_address_escape = "STACK_VARIABLE_ADDRESS_ESCAPE"
let strong_delegate_warning = "STRONG_DELEGATE_WARNING"
let tainted_value_reaching_sensitive_function = "TAINTED_VALUE_REACHING_SENSITIVE_FUNCTION"
let unary_minus_applied_to_unsigned_expression = "UNARY_MINUS_APPLIED_TO_UNSIGNED_EXPRESSION"
let unsafe_guarded_by_access = "UNSAFE_GUARDED_BY_ACCESS"
@ -789,9 +796,9 @@ let desc_registered_observer_being_deallocated pvar loc =
let tags = Tags.create () in
let obj_str = Pvar.to_string pvar in
{ no_desc with descriptions = [ registered_observer_being_deallocated_str obj_str ^ at_line tags loc ^
". Being still registered as observer of the notification " ^
"center, the deallocated object "
^ obj_str ^ " may be notified in the future." ]; tags = !tags }
". Being still registered as observer of the notification " ^
"center, the deallocated object "
^ obj_str ^ " may be notified in the future." ]; tags = !tags }
let desc_return_statement_missing loc =
let tags = Tags.create () in

@ -29,26 +29,31 @@ val compare : t -> t -> int
val equal : t -> t -> bool
val context_leak : t
val analysis_stops : t
val array_out_of_bounds_l1 : t
val array_out_of_bounds_l2 : t
val array_out_of_bounds_l3 : t
val assign_pointer_warning : t
val bad_pointer_comparison : t
val class_cast_exception : t
val comparing_floats_for_equality : t
val condition_is_assignment : t
val condition_always_false : t
val condition_always_true : t
val comparing_floats_for_equality : t
val context_leak : t
val cxx_reference_captured_in_objc_block : t
val dangling_pointer_dereference : t
val deallocate_stack_variable : t
val deallocate_static_memory : t
val deallocation_mismatch : t
val direct_atomic_property_access : t
val divide_by_zero : t
val empty_vector_access : t
val field_not_null_checked : t
val global_variable_initialized_with_function_or_method_call : t
val inherently_dangerous_function : t
val memory_leak : t
val mutable_local_variable_in_component_file : t
val null_dereference : t
val parameter_not_null_checked : t
val null_test_after_dereference : t
@ -63,6 +68,7 @@ val return_value_ignored : t
val return_expression_required : t
val return_statement_missing : t
val stack_variable_address_escape : t
val strong_delegate_warning : t
val unary_minus_applied_to_unsigned_expression : t
val uninitialized_value : t
val unsafe_guarded_by_access : t

@ -18,18 +18,25 @@ type issue =
| Strong_delegate_warning
let to_string issue =
match issue with
| Assign_pointer_warning -> "ASSIGN_POINTER_WARNING"
| Bad_pointer_comparison -> "BAD_POINTER_COMPARISON"
| Cxx_reference_captured_in_objc_block ->
"CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK"
| Direct_atomic_property_access -> "DIRECT_ATOMIC_PROPERTY_ACCESS"
| Global_variable_initialized_with_function_or_method_call ->
"GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL"
| Mutable_local_variable_in_component_file -> "MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE"
| Registered_observer_being_deallocated ->
Localise.to_string (Localise.registered_observer_being_deallocated)
| Strong_delegate_warning -> "STRONG_DELEGATE_WARNING"
Localise.to_string
(match issue with
| Assign_pointer_warning ->
Localise.assign_pointer_warning
| Bad_pointer_comparison ->
Localise.bad_pointer_comparison
| Cxx_reference_captured_in_objc_block ->
Localise.cxx_reference_captured_in_objc_block
| Direct_atomic_property_access ->
Localise.direct_atomic_property_access
| Global_variable_initialized_with_function_or_method_call ->
Localise.global_variable_initialized_with_function_or_method_call
| Mutable_local_variable_in_component_file ->
Localise.mutable_local_variable_in_component_file
| Registered_observer_being_deallocated ->
Localise.registered_observer_being_deallocated
| Strong_delegate_warning ->
Localise.strong_delegate_warning
)
let severity_of_issue issue =
match issue with

@ -1,7 +1,6 @@
java_test(
name='objc_tests',
deps=[
'//infer/tests/endtoend:objc_endtoend_tests',
'//infer/tests/frontend:objc_frontend_tests',
],
)

@ -0,0 +1,23 @@
# 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 ../../Makefile.clang
OPTIONS = -x objective-c -fobjc-arc -c
ANALYZER = linters
FILES = \
**.m \
*/*.m \
compile:
clang $(OPTIONS) $(FILES)
analyze:
$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets all --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) >/dev/null 2>duplicates.txt
grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0

@ -0,0 +1,31 @@
assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 18, ASSIGN_POINTER_WARNING
assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 20, ASSIGN_POINTER_WARNING
assign_pointer.m, frontend_checks_006677034375a1c7e7ccfd3694390282, 22, ASSIGN_POINTER_WARNING
atomic_prop.m, A_bla, 98, DIRECT_ATOMIC_PROPERTY_ACCESS
atomic_prop.m, A_bla, 99, DIRECT_ATOMIC_PROPERTY_ACCESS
atomic_prop.m, A_readP, 77, DIRECT_ATOMIC_PROPERTY_ACCESS
atomic_prop.m, A_readQ, 86, DIRECT_ATOMIC_PROPERTY_ACCESS
atomic_prop.m, A_writeQ:, 82, DIRECT_ATOMIC_PROPERTY_ACCESS
atomic_prop.m, __objc_anonymous_block_______1, 114, DIRECT_ATOMIC_PROPERTY_ACCESS
badpointer.m, bad1, 17, BAD_POINTER_COMPARISON
badpointer.m, bad10, 139, BAD_POINTER_COMPARISON
badpointer.m, bad2, 26, BAD_POINTER_COMPARISON
badpointer.m, bad3, 33, BAD_POINTER_COMPARISON
badpointer.m, bad4, 85, BAD_POINTER_COMPARISON
badpointer.m, bad5, 99, BAD_POINTER_COMPARISON
badpointer.m, bad6, 106, BAD_POINTER_COMPARISON
badpointer.m, bad7, 121, BAD_POINTER_COMPARISON
badpointer.m, bad8, 128, BAD_POINTER_COMPARISON
badpointer.m, bad9, 135, BAD_POINTER_COMPARISON
nsnumber.m, bad1, 13, BAD_POINTER_COMPARISON
nsnumber.m, bad2, 18, BAD_POINTER_COMPARISON
nsnumber.m, bad3, 23, BAD_POINTER_COMPARISON
nsnumber.m, bad4, 43, BAD_POINTER_COMPARISON
registered_observer/Person.m, frontend_checks_e09ed2cbfd6c3584b50a5fd5783367c9, 80, REGISTERED_OBSERVER_BEING_DEALLOCATED
registered_observer/Person.m, frontend_checks_e09ed2cbfd6c3584b50a5fd5783367c9, 97, REGISTERED_OBSERVER_BEING_DEALLOCATED
registered_observer/ViewController3.m, frontend_checks_6eb87af45b67f4c5dda049872d80dc43, 14, REGISTERED_OBSERVER_BEING_DEALLOCATED
strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 15, STRONG_DELEGATE_WARNING
strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 19, STRONG_DELEGATE_WARNING
strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 21, STRONG_DELEGATE_WARNING
strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 23, STRONG_DELEGATE_WARNING
strong_delegate.m, frontend_checks_40af2f421be894c3b6306d2942a2c8b7, 25, STRONG_DELEGATE_WARNING

@ -0,0 +1,11 @@
{
"enable_checks": [
"GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL"
],
"skip_translation": [
{
"language": "Java",
"source_contains": "_SHOULD_BE_SKIPPED_"
}
]
}

@ -0,0 +1,22 @@
# 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 ../../Makefile.clang
OPTIONS = -x objective-c++ -std=c++11 -fobjc-arc -c
ANALYZER = linters
FILES = \
*/*.mm \
compile:
clang $(OPTIONS) $(FILES)
analyze:
$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets all --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) >/dev/null 2>duplicates.txt
grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0

@ -0,0 +1,13 @@
componentkit/Test.mm, BarComponent_new, 103, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, BarComponent_new, 105, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, FooComponent_newWithString:, 69, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, FooComponent_newWithString:, 74, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, FooComponent_newWithString:, 76, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, FooComponent_newWithString:, 80, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, FooComponent_newWithString:, 85, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
componentkit/Test.mm, SomeClass_init, 58, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE
cxx_reference_in_block/block.mm, A_foo3:param2:, 37, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK
cxx_reference_in_block/block.mm, A_foo:, 20, CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK
global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 30, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL
global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 32, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL
global-var/B.mm, frontend_checks_a1a4821f6afe8cbd5bde0f8905d6f284, 34, GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL

@ -11,24 +11,11 @@ tests_dependencies = [
'//infer/tests/codetoanalyze/java/infer:infer',
]
# ############### ObjC endtoend tests ########################
java_test(
name='objc_endtoend_tests',
deps=[
'//infer/tests/endtoend/objc/linters:linters',
],
visibility=[
'PUBLIC',
],
)
# ############### ObjCpp endtoend tests ########################
java_test(
name='objcpp_endtoend_tests',
deps=[
'//infer/tests/endtoend/objcpp/infer:infer',
'//infer/tests/endtoend/objcpp/linters:linters',
'//infer/tests/endtoend/objcpp/componentkit:componentkit',
],
visibility=[
'PUBLIC',
@ -47,22 +34,3 @@ java_test(
'PUBLIC',
],
)
# ############### Linters tests ########################
java_test(
name='linters',
deps=[
'//infer/tests/endtoend/objc/linters:linters',
'//infer/tests/endtoend/objcpp/linters:linters',
],
)
# ############### ComponentKit tests ########################
java_test(
name='componentkit',
deps=[
'//infer/tests/endtoend/objcpp/componentkit:componentkit',
],
)

@ -1,63 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class AssignPointerTest {
public static final String FILE =
"infer/tests/codetoanalyze/objc/linters/assign_pointer.m";
private static ImmutableList<String> inferCmd;
public static final String ASSIGN_POINTER_WARNING = "ASSIGN_POINTER_WARNING";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommand(
folder,
FILE);
}
@Test
public void matchErrors()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain the correct " + ASSIGN_POINTER_WARNING,
inferResults,
containsOnlyLines(
new int[]{
18,
20,
22
}));
}
}

@ -1,66 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class AtomicPropertyTest {
public static final String FILE =
"infer/tests/codetoanalyze/objc/linters/atomic_prop.m";
private static ImmutableList<String> inferCmd;
public static final String DIRECT_ATOMIC_PROPERTY_ACCESS = "DIRECT_ATOMIC_PROPERTY_ACCESS";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommand(
folder,
FILE);
}
@Test
public void matchErrors()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain the correct " + DIRECT_ATOMIC_PROPERTY_ACCESS,
inferResults,
containsOnlyLines(
new int[]{
77,
82,
86,
98,
99,
114
}));
}
}

@ -1,35 +0,0 @@
tests_dependencies = [
'//infer/lib/java/android:android',
'//dependencies/java/guava:guava',
'//dependencies/java/junit:hamcrest',
'//dependencies/java/jackson:jackson',
'//dependencies/java/jsr-305:jsr-305',
'//dependencies/java/junit:junit',
'//dependencies/java/opencsv:opencsv',
'//infer/tests/utils:utils',
]
objc_linters_test_sources = glob(['*.java'])
objc_linters_test_deps = []
for test_source in objc_linters_test_sources:
target_name = test_source.replace("/", "_")[:-len(".java")]
objc_linters_test_deps.append(target_name)
java_test(
name=target_name,
srcs=[test_source],
deps=tests_dependencies,
visibility=[
'PUBLIC',
],
source='7',
target='7',
)
java_test(
name='linters',
deps=[':' + x for x in objc_linters_test_deps],
visibility=[
'PUBLIC',
],
)

@ -1,57 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class NSNumber2Test {
public static final String NSNUMBER_FILE =
"infer/tests/codetoanalyze/objc/linters/badpointer.m";
private static ImmutableList<String> inferCmd;
public static final String BAD_POINTER_COMPARISON = "BAD_POINTER_COMPARISON";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommand(
folder,
NSNUMBER_FILE);
}
@Test
public void badNSNumberPointerComparisonShouldBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain " + BAD_POINTER_COMPARISON,
inferResults,
containsOnlyLines(new int[]{17, 26, 33, 85, 99, 106, 121, 128, 135, 139}));
}
}

@ -1,58 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class NSNumberTest {
public static final String NSNUMBER_FILE =
"infer/tests/codetoanalyze/objc/linters/nsnumber.m";
private static ImmutableList<String> inferCmd;
public static final String BAD_POINTER_COMPARISON = "BAD_POINTER_COMPARISON";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommand(
folder,
NSNUMBER_FILE);
}
@Test
public void badNSNumberPointerComparisonShouldBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain " + BAD_POINTER_COMPARISON,
inferResults,
containsOnlyLines(new int[]{13, 18, 23, 43})
);
}
}

@ -1,65 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class RegisteredObserver {
public static final String VCFile =
"infer/tests/codetoanalyze/objc/linters/registered_observer/ViewController.m";
private static ImmutableList<String> inferCmd;
public static final String REGISTERED_OBSERVER = "REGISTERED_OBSERVER_BEING_DEALLOCATED";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommandSimple(
folder,
VCFile);
}
@Test
public void RegisteredObserverShouldBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
String[] methods = {
//"fooError", "barError"
};
assertThat(
"Results should contain " + REGISTERED_OBSERVER,
inferResults,
containsExactly(
REGISTERED_OBSERVER,
VCFile,
methods
)
);
}
}

@ -1,63 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class RegisteredObserver2 {
public static final String VCFile2 =
"infer/tests/codetoanalyze/objc/linters/registered_observer/ViewController2.m";
private static ImmutableList<String> inferCmd;
public static final String REGISTERED_OBSERVER = "REGISTERED_OBSERVER_BEING_DEALLOCATED";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommandSimple(
folder,
VCFile2);
}
@Test
public void RegisteredObserverShouldNotBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
String[] methods = {};
assertThat(
"Results should contain " + REGISTERED_OBSERVER,
inferResults,
containsExactly(
REGISTERED_OBSERVER,
VCFile2,
methods
)
);
}
}

@ -1,60 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class RegisteredObserver3 {
public static final String VCFile3 =
"infer/tests/codetoanalyze/objc/linters/registered_observer/ViewController3.m";
private static ImmutableList<String> inferCmd;
public static final String REGISTERED_OBSERVER = "REGISTERED_OBSERVER_BEING_DEALLOCATED";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommandSimple(
folder,
VCFile3);
}
@Test
public void RegisteredObserverShouldBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
String[] methods = {
"frontendChecks"
};
assertThat(
"Results should contain " + REGISTERED_OBSERVER,
inferResults,
containsOnlyLines(new int[]{14}));
}
}

@ -1,58 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class RegisteredObserver4 {
public static final String VCFile =
"infer/tests/codetoanalyze/objc/linters/registered_observer/Person.m";
private static ImmutableList<String> inferCmd;
public static final String REGISTERED_OBSERVER = "REGISTERED_OBSERVER_BEING_DEALLOCATED";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCLintersCommandSimple(
folder,
VCFile);
}
@Test
public void RegisteredObserverShouldBeFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain " + REGISTERED_OBSERVER,
inferResults,
containsOnlyLines(new int[] {80, 97})
);
}
}

@ -1,58 +0,0 @@
/*
* 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.
*/
package endtoend.objc.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class StrongDelegateTest {
public static final String FILE =
"infer/tests/codetoanalyze/objc/linters/strong_delegate.m";
private static ImmutableList<String> inferCmdFraction;
public static final String STRONG_DELEGATE_WARNING = "STRONG_DELEGATE_WARNING";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmdFraction = InferRunner.createObjCLintersCommand(
folder,
FILE);
}
@Test
public void whenInferRunsOnStrongDelegate()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmdFraction);
assertThat(
"Results should contain " + STRONG_DELEGATE_WARNING,
inferResults,
containsOnlyLines(new int[]{15, 19, 21, 23, 25}));
}
}

@ -1,35 +0,0 @@
tests_dependencies = [
'//infer/lib/java/android:android',
'//dependencies/java/guava:guava',
'//dependencies/java/junit:hamcrest',
'//dependencies/java/jackson:jackson',
'//dependencies/java/jsr-305:jsr-305',
'//dependencies/java/junit:junit',
'//dependencies/java/opencsv:opencsv',
'//infer/tests/utils:utils',
]
objcpp_linters_test_sources = glob(['*.java'])
objcpp_linters_test_deps = []
for test_source in objcpp_linters_test_sources:
target_name = test_source.replace("/", "_")[:-len(".java")]
objcpp_linters_test_deps.append(target_name)
java_test(
name=target_name,
srcs=[test_source],
deps=tests_dependencies,
visibility=[
'PUBLIC',
],
source='7',
target='7',
)
java_test(
name='componentkit',
deps=[':' + x for x in objcpp_linters_test_deps],
visibility=[
'PUBLIC',
],
)

@ -1,51 +0,0 @@
/*
* 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.
*/
package endtoend.objcpp.componentkit;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsLinesOfError;
import static org.hamcrest.core.IsNot.not;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class MutableLocalVariableInNonComponentTest {
public static final String FILE =
"infer/tests/codetoanalyze/objcpp/componentkit/Test2.mm";
private static ImmutableList<String> inferCmd;
public static final String MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE =
"MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCPPLintersCommand(
folder,
FILE);
}
@Test
public void MLVsInComponentFile()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should not contain " + MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE,
inferResults,
not(containsLinesOfError(new int[]{38}, MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE)));
}
}

@ -1,66 +0,0 @@
/*
* 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.
*/
package endtoend.objcpp.componentkit;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import static utils.matchers.ResultContainsErrorInMethod.contains;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class MutableLocalVariableTest {
public static final String FILE =
"infer/tests/codetoanalyze/objcpp/componentkit/Test.mm";
private static ImmutableList<String> inferCmd;
public static final String MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE =
"MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE";
@ClassRule
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCPPLintersCommand(
folder,
FILE);
}
@Test
public void MLVsInComponentFile()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain " + MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE,
inferResults,
containsOnlyLines(new int[]{58, 69, 74, 76, 80, 85, 103, 105}));
}
@Test
public void MLVsInNewWithString()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain " + MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE,
inferResults,
contains(MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE, FILE, "newWithString:"));
}
}

@ -1,35 +0,0 @@
tests_dependencies = [
'//infer/lib/java/android:android',
'//dependencies/java/guava:guava',
'//dependencies/java/junit:hamcrest',
'//dependencies/java/jackson:jackson',
'//dependencies/java/jsr-305:jsr-305',
'//dependencies/java/junit:junit',
'//dependencies/java/opencsv:opencsv',
'//infer/tests/utils:utils',
]
objcpp_linters_test_sources = glob(['*.java'])
objcpp_linters_test_deps = []
for test_source in objcpp_linters_test_sources:
target_name = test_source.replace("/", "_")[:-len(".java")]
objcpp_linters_test_deps.append(target_name)
java_test(
name=target_name,
srcs=[test_source],
deps=tests_dependencies,
visibility=[
'PUBLIC',
],
source='7',
target='7',
)
java_test(
name='linters',
deps=[':' + x for x in objcpp_linters_test_deps],
visibility=[
'PUBLIC',
],
)

@ -1,59 +0,0 @@
/*
* 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.
*/
package endtoend.objcpp.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class BlockCaptureCXXRefTest {
public static final String FILE =
"infer/tests/codetoanalyze/objcpp/linters/cxx_reference_in_block/block.mm";
private static ImmutableList<String> inferCmd;
public static final String REFERENCE_CAPTURED = "CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createObjCPPLintersCommand(folder, FILE);
}
@Test
public void matchErrors()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
assertThat(
"Results should contain the correct " + REFERENCE_CAPTURED,
inferResults,
containsOnlyLines(
new int[]{
20,
37
}));
}
}

@ -1,59 +0,0 @@
/*
* 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.
*/
package endtoend.objcpp.linters;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class GlobalVarTest {
public static final String FILE =
"infer/tests/codetoanalyze/objcpp/linters/global-var/B.mm";
private static ImmutableList<String> inferCmdFraction;
public static final String GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL =
"GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmdFraction = InferRunner.createObjCPPLintersCommand(
folder,
FILE);
}
@Test
public void whenInferRunsGlobalVar()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferObjC(inferCmdFraction);
assertThat(
"Results should contain " + GLOBAL_VARIABLE_INITIALIZED_WITH_FUNCTION_OR_METHOD_CALL,
inferResults,
containsOnlyLines(new int[]{30, 32, 34}));
}
}

@ -563,48 +563,6 @@ public class InferRunner {
ImmutableList.<String>of());
}
public static ImmutableList<String> createLintersCommand(
TemporaryFolder folder,
String sourceFile,
Language lang) throws IOException, InterruptedException {
return createClangInferCommand(
folder,
sourceFile,
lang,
"linters",
getXcodeRoot() + IPHONESIMULATOR_ISYSROOT_SUFFIX,
null,
true,
ImmutableList.<String>of());
}
public static ImmutableList<String> createObjCLintersCommand(
TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException {
return createLintersCommand(folder, sourceFile, Language.ObjC);
}
public static ImmutableList<String> createObjCLintersCommandSimple(
TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException {
return createClangInferCommand(
folder,
sourceFile,
Language.ObjC,
"linters",
null,
null,
true,
ImmutableList.<String>of());
}
public static ImmutableList<String> createObjCPPLintersCommand(
TemporaryFolder folder,
String sourceFile) throws IOException, InterruptedException {
return createLintersCommand(folder, sourceFile, Language.ObjCPP);
}
@Nullable
public static File runInferFrontend(ImmutableList<String> inferCmd)
throws IOException, InterruptedException, InferException {

Loading…
Cancel
Save