Convert java tracing tests to new direct format.

Reviewed By: jeremydubreil

Differential Revision: D3791189

fbshipit-source-id: ce0b7d6
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot 2
parent 674f30de2c
commit 257f4976f0

@ -16,8 +16,8 @@
java_libraries = //dependencies/java:java_libraries
# 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
tracing = //infer/tests/endtoend/java/tracing:tracing
linters = //infer/tests/endtoend:linters
componentkit = //infer/tests/endtoend:componentkit

@ -15,7 +15,7 @@ TARGETS_TO_TEST += c cpp
endif
ifeq ($(BUILD_JAVA_ANALYZERS),yes)
TARGETS_TO_TEST += java
DIRECT_TESTS += java_checkers_test java_eradicate_test java_infer_test
DIRECT_TESTS += java_checkers_test java_eradicate_test java_infer_test java_tracing_test
endif
ifneq ($(XCODE_SELECT),no)
TARGETS_TO_TEST += objc objcpp
@ -106,6 +106,9 @@ java_eradicate_test:
java_infer_test:
make -C ./infer/tests/codetoanalyze/java/infer test
java_tracing_test:
make -C ./infer/tests/codetoanalyze/java/tracing test
buck_test: infer
make $(DIRECT_TESTS)

@ -1,3 +1,4 @@
# TODO: this file exists only to support buck integration in infer/tests/build_systems/build_integration_tests.py
sources = glob(['**/*.java'])
dependencies = [
@ -47,14 +48,3 @@ genrule(
'PUBLIC',
],
)
genrule(
name = 'tracing',
out = 'comparison_report.csv',
cmd = analysis_cmd('tracing'),
deps = dependencies + [':infer'],
srcs = sources,
visibility = [
'PUBLIC',
],
)

@ -0,0 +1,25 @@
{
"never_returning_null": [
{
"language": "Java",
"source_contains": "_AUTOMATICALLY_GENERATED_"
},
{
"language": "Java",
"class": "codetoanalyze.java.infer.SomeLibrary",
"method": "get"
}
],
"infer-blacklist-files-containing": [
"@generated"
],
"enable_checks": [
"UNSAFE_GUARDED_BY_ACCESS"
],
"skip_translation": [
{
"language": "Java",
"source_contains": "_SHOULD_BE_SKIPPED_"
}
]
}

@ -13,14 +13,14 @@ import com.facebook.infer.annotation.Verify;
public class ArrayIndexOutOfBoundsExceptionExample {
void callMethodFromArray(T[] array, int index) {
void callMethodFromArray(T2[] array, int index) {
if (array[index] != null) {
array[index].f();
}
}
@Verify
public void missingCheckOnIndex(T[] array, int index) {
public void missingCheckOnIndex(T2[] array, int index) {
if (array != null) {
if (index < array.length) {
callMethodFromArray(array, index);
@ -29,17 +29,17 @@ public class ArrayIndexOutOfBoundsExceptionExample {
}
void callOutOfBound() {
T[] array = new T[42];
T2[] array = new T2[42];
callMethodFromArray(array, -5);
}
void withFixedIndex(T[] array) {
void withFixedIndex(T2[] array) {
int index = 9;
callMethodFromArray(array, index);
}
void arrayIndexOutOfBoundsInCallee() {
T[] array = new T[8];
T2[] array = new T2[8];
withFixedIndex(array);
}

@ -1,42 +0,0 @@
sources = glob(['**/*.java'])
dependencies = [
'//infer/annotations:annotations',
]
java_library(
name = 'tracing',
srcs = sources,
deps = dependencies,
visibility = [
'PUBLIC'
]
)
out = 'out'
clean_cmd = ' '.join(['rm', '-rf', out])
classpath = ':'.join([('$(classpath ' + path + ')') for path in dependencies])
infer_cmd = ' '.join([
'infer',
'--no-progress-bar',
'--absolute-paths',
'-o', out,
'-a', 'tracing',
'--',
'javac',
'-cp', classpath,
'$SRCS',
])
copy_cmd = ' '.join(['cp', out + '/report.csv', '$OUT'])
command = ' && '.join([clean_cmd, infer_cmd, copy_cmd])
genrule(
name = 'analyze',
srcs = sources,
out = 'report.csv',
cmd = command,
deps = dependencies + [':tracing'],
visibility = [
'PUBLIC',
]
)

@ -11,21 +11,21 @@ package codetoanalyze.java.tracing;
import com.facebook.infer.annotation.Verify;
class S extends T {}
class S extends T2 {}
public class ClassCastExceptionExample {
S cast(T t) {
S cast(T2 t) {
return (S) t;
}
void foo() {
T t = new T();
T2 t = new T2();
S s = cast(t);
s.toString();
}
T m;
T2 m;
@Verify
public S bar(int x) {

@ -10,20 +10,20 @@
package codetoanalyze.java.tracing;
interface I {
T get();
T2 get();
}
class A implements I {
public T get() {
return new T();
public T2 get() {
return new T2();
}
}
class B extends A {
public T get() {
public T2 get() {
return null;
}
@ -31,11 +31,11 @@ class B extends A {
public class LazyDynamicDispatchExample {
static T fromSupertype(A a) {
static T2 fromSupertype(A a) {
return a.get();
}
static T fromInterface(I i) {
static T2 fromInterface(I i) {
return i.get();
}

@ -22,14 +22,14 @@ class LocallyDefinedException extends RuntimeException {
public class LocallyDefinedExceptionExample {
T t;
T2 t;
public LocallyDefinedExceptionExample() {
this.t = new T();
this.t = new T2();
this.t.x = 42;
}
void setT(T t) {
void setT(T2 t) {
this.t = t;
}

@ -0,0 +1,42 @@
# 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
ANALYZER = tracing
FILES_FOR_TRACING = \
T2.java \
\
ArrayIndexOutOfBoundsExceptionExample.java \
ClassCastExceptionExample.java \
LazyDynamicDispatchExample.java \
LocallyDefinedExceptionExample.java \
NullPointerExceptionExample.java \
ReportOnMainExample.java \
UnavoidableExceptionExample.java \
\
FILES_LINKED_FROM_INFER = \
T.java \
SkippedSourceFile.java \
SomeLibrary.java \
Utils.java \
CloseableAsResourceExample.java \
NeverNullSource.java \
\
ArrayOutOfBounds.java \
ClassCastExceptions.java \
NullPointerExceptions.java \
FILES = $(FILES_FOR_TRACING) $(FILES_LINKED_FROM_INFER)
compile:
javac -cp $(CLASSPATH) $(FILES)
analyze:
$(INFER_BIN) -a $(ANALYZER) -- javac -cp $(CLASSPATH) $(FILES) >/dev/null 2>/dev/null

@ -13,12 +13,12 @@ import com.facebook.infer.annotation.Verify;
public class NullPointerExceptionExample {
void deref(T t) {
void deref(T2 t) {
t.f();
}
@Verify
void callDeref(T t, boolean condition) {
void callDeref(T2 t, boolean condition) {
if (condition) {
deref(t);
}

@ -11,7 +11,7 @@ package codetoanalyze.java.tracing;
public class ReportOnMainExample {
T t;
T2 t;
native boolean test();

@ -1,17 +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 codetoanalyze.java.tracing;
public class T {
int x;
void f() {
}
}

@ -0,0 +1,17 @@
/*
* 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 codetoanalyze.java.tracing;
public class T2 {
int x;
void f() {
}
}

@ -11,22 +11,22 @@ package codetoanalyze.java.tracing;
public class UnavoidableExceptionExample {
static T create() {
static T2 create() {
return null;
}
static void cannotAvoidNPE() {
T t = create();
T2 t = create();
t.f();
}
static void unavoidableNPEWithParameter(boolean b) {
T t = create();
T2 t = create();
t.f();
}
void virtualMethodWithUnavoidableNPE(boolean b) {
T t = create();
T2 t = create();
t.f();
}

@ -0,0 +1,57 @@
ArrayIndexOutOfBoundsExceptionExample.java, void ArrayIndexOutOfBoundsExceptionExample.arrayIndexOutOfBoundsInCallee(), 3, java.lang.ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionExample.java, void ArrayIndexOutOfBoundsExceptionExample.callOutOfBound(), 3, java.lang.ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsExceptionExample.java, void ArrayIndexOutOfBoundsExceptionExample.missingCheckOnIndex(codetoanalyze.java.tracing.T2[],int), 6, java.lang.ArrayIndexOutOfBoundsException
ArrayOutOfBounds.java, int ArrayOutOfBounds.arrayOutOfBounds(), 2, java.lang.ArrayIndexOutOfBoundsException
ClassCastExceptionExample.java, S ClassCastExceptionExample.bar(int), 4, java.lang.ClassCastException
ClassCastExceptionExample.java, void ClassCastExceptionExample.foo(), 4, java.lang.ClassCastException
ClassCastExceptions.java, int ClassCastExceptions.classCastExceptionImplementsInterface(), 0, java.lang.ClassCastException
ClassCastExceptions.java, void ClassCastExceptions.classCastException(), 3, java.lang.ClassCastException
ClassCastExceptions.java, void ClassCastExceptions.openHttpURLConnection(), 4, java.lang.ClassCastException
CloseableAsResourceExample.java, T CloseableAsResourceExample.sourceOfNullWithResourceLeak(), 1, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.failToCloseWithCloseQuietly(), 5, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.leakFoundWhenIndirectlyImplementingCloseable(), 1, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.notClosingCloseable(), 1, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.notClosingWrapper(), 2, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.skippedVritualCallDoesNotCloseResourceOnReceiver(), 2, RESOURCE_LEAK
CloseableAsResourceExample.java, void CloseableAsResourceExample.withException(), 4, RESOURCE_LEAK
LazyDynamicDispatchExample.java, void LazyDynamicDispatchExample.callWithSubtype(), 3, java.lang.NullPointerException
LazyDynamicDispatchExample.java, void LazyDynamicDispatchExample.shouldReportLocalVarTypeIsKnown(), 3, java.lang.NullPointerException
LocallyDefinedExceptionExample.java, void LocallyDefinedExceptionExample.fieldInvariant(), 8, codetoanalyze.java.tracing.LocallyDefinedException
NullPointerExceptionExample.java, void NullPointerExceptionExample.callDeref(T2,boolean), 4, java.lang.NullPointerException
NullPointerExceptionExample.java, void NullPointerExceptionExample.callLeadToNpe(), 2, java.lang.NullPointerException
NullPointerExceptionExample.java, void NullPointerExceptionExample.npeOnBothBranches(int), 6, java.lang.NullPointerException
NullPointerExceptionExample.java, void NullPointerExceptionExample.npeOnBothBranches(int), 6, java.lang.NullPointerException
NullPointerExceptions.java, String NullPointerExceptions.testSystemGetPropertyArgument(), 1, NULL_DEREFERENCE
NullPointerExceptions.java, int NullPointerExceptions.nullListFiles(String), 3, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerException(), 2, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionInterProc(), 2, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithAChainOfFields(NullPointerExceptions$C), 2, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithAChainOfFields(NullPointerExceptions$C), 2, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithArray(), 3, java.lang.NullPointerException
NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithExceptionHandling(boolean), 5, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.badCheckShouldCauseNPE(), 2, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.derefNonThisGetterAfterCheckShouldNotCauseNPE(), 5, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.derefNull(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.derefUndefNullableRetWrapper(), 2, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterLoopOnList(NullPointerExceptions$L), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterLoopOnList(NullPointerExceptions$L), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterUnlock1(Lock), 5, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterUnlock1(Lock), 5, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterUnlock2(Lock), 7, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.dereferenceAfterUnlock2(Lock), 7, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionArrayLength(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionCallArrayReadMethod(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionCallArrayReadMethod(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionFromFailingFileOutputStreamConstructor(), 9, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionFromFaillingResourceConstructor(), 8, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionUnlessFrameFails(), 6, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionWithNullArrayParameter(), 2, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.nullPointerExceptionWithNullObjectParameter(), 2, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.someNPEAfterResourceLeak(), 3, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.stringConstantEqualsFalseNotNPE_FP(), 11, java.lang.NullPointerException
NullPointerExceptions.java, void NullPointerExceptions.testSystemGetPropertyReturn(), 3, java.lang.NullPointerException
ReportOnMainExample.java, void ReportOnMainExample.main(java.lang.String[]), 3, java.lang.NullPointerException
UnavoidableExceptionExample.java, void UnavoidableExceptionExample.cannotAvoidNPE(), 3, java.lang.NullPointerException
UnavoidableExceptionExample.java, void UnavoidableExceptionExample.unavoidableNPEWithParameter(boolean), 3, java.lang.NullPointerException
UnavoidableExceptionExample.java, void UnavoidableExceptionExample.virtualMethodWithUnavoidableNPE(boolean), 3, java.lang.NullPointerException

@ -9,7 +9,6 @@ tests_dependencies = [
'//infer/tests/utils:utils',
'//infer/tests/codetoanalyze/java/crashcontext:crashcontext',
'//infer/tests/codetoanalyze/java/infer:infer',
'//infer/tests/codetoanalyze/java/tracing:tracing',
]
# ############### C endtoend tests ########################
@ -66,8 +65,6 @@ java_test(
'//infer/tests/endtoend/java/infer:infer',
'//infer/tests/endtoend/java/crashcontext:crashcontext',
'//infer/tests/endtoend/java/harness:harness',
'//infer/tests/endtoend/java/tracing:tracing',
'//infer/tests/endtoend/java/comparison:comparison',
],
visibility=[
'PUBLIC',

@ -1,56 +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.java.comparison;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ArrayIndexOutOfBoundsExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/infer/ArrayOutOfBounds.java";
public static final String ARRAY_OUT_OF_BOUNDS = "java.lang.ArrayIndexOutOfBoundsException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingComparisonResults(
ArrayIndexOutOfBoundsExceptionTest.class,
SOURCE_FILE);
}
@Test
public void whenInferRunsOnArrayOutOfBoundsThenErrorIsFound()
throws IOException, InterruptedException, InferException {
String[] methods = {
"arrayOutOfBounds",
};
assertThat(
"Results should contain out of bounds error.", inferResults,
containsExactly(
ARRAY_OUT_OF_BOUNDS,
SOURCE_FILE,
methods
)
);
}
}

@ -1,16 +0,0 @@
java_test(
name='comparison',
srcs=glob(['*.java']),
deps=[
'//dependencies/java/guava:guava',
'//dependencies/java/junit:hamcrest',
'//dependencies/java/junit:junit',
'//infer/tests/utils:utils',
],
resources=[
'//infer/tests/codetoanalyze/java/infer:tracing',
],
visibility=[
'PUBLIC',
],
)

@ -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.java.comparison;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ClassCastExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/infer/ClassCastExceptions.java";
public static final String CLASS_CAST_EXCEPTION =
"java.lang.ClassCastException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingComparisonResults(
ClassCastExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"classCastException",
"classCastExceptionImplementsInterface",
"openHttpURLConnection",
};
assertThat(
"Results should contain " + CLASS_CAST_EXCEPTION,
inferResults,
containsExactly(
CLASS_CAST_EXCEPTION,
SOURCE_FILE,
methods
)
);
}
}

@ -1,67 +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.java.comparison;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsTheseErrors.contains;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class NullPointerExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java";
public static final String NPE =
"java.lang.NullPointerException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingComparisonResults(
NullPointerExceptionTest.class,
SOURCE_FILE);
}
@Test
public void errorsFoundByInferExpectedToBeFoundInTracingMode()
throws IOException, InterruptedException, InferException {
String[] methods = {
"nullPointerException",
"nullPointerExceptionInterProc",
"nullPointerExceptionWithExceptionHandling",
"nullPointerExceptionWithArray",
"nullPointerExceptionWithNullObjectParameter",
"nullPointerExceptionWithNullArrayParameter",
"nullPointerExceptionFromFaillingResourceConstructor",
"nullPointerExceptionFromFailingFileOutputStreamConstructor",
"nullPointerExceptionUnlessFrameFails",
};
assertThat(
"Results should contain " + NPE,
inferResults,
contains(
NPE,
SOURCE_FILE,
methods
)
);
}
}

@ -1,3 +1,4 @@
# TODO: this file exists only to support buck integration in infer/tests/build_systems/build_integration_tests.py
java_test(
name='infer',
srcs=glob(['*.java']),

@ -1,61 +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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ArrayIndexOutOfBoundsExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/ArrayIndexOutOfBoundsExceptionExample.java";
public static final String ARRAY_OUT_OF_BOUND =
"java.lang.ArrayIndexOutOfBoundsException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
ArrayIndexOutOfBoundsExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"callOutOfBound",
"missingCheckOnIndex",
"arrayIndexOutOfBoundsInCallee",
};
assertThat(
"Results should contain " + ARRAY_OUT_OF_BOUND,
inferResults,
containsExactly(
ARRAY_OUT_OF_BOUND,
SOURCE_FILE,
methods
)
);
}
}

@ -1,16 +0,0 @@
java_test(
name='tracing',
srcs=glob(['*.java']),
deps=[
'//dependencies/java/guava:guava',
'//dependencies/java/junit:hamcrest',
'//dependencies/java/junit:junit',
'//infer/tests/utils:utils',
],
resources=[
'//infer/tests/codetoanalyze/java/tracing:analyze',
],
visibility=[
'PUBLIC',
],
)

@ -1,56 +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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ClassCastExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/ClassCastExceptionExample.java";
public static final String CLASS_CAST_EXCEPTION =
"java.lang.ClassCastException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
ClassCastExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {"foo", "bar"};
assertThat(
"Results should contain " + CLASS_CAST_EXCEPTION,
inferResults,
containsExactly(
CLASS_CAST_EXCEPTION,
SOURCE_FILE,
methods
)
);
}
}

@ -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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class LazyDynamicDispatchTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/LazyDynamicDispatchExample.java";
public static final String NPE =
"java.lang.NullPointerException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
LazyDynamicDispatchTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"callWithSubtype",
"shouldReportLocalVarTypeIsKnown",
};
assertThat(
"Results should contain " + NPE,
inferResults,
containsExactly(
NPE,
SOURCE_FILE,
methods
)
);
}
}

@ -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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class LocallyDefinedExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/LocallyDefinedExceptionExample.java";
public static final String LOCALLY_DEFINED_EXCEPTION =
"codetoanalyze.java.tracing.LocallyDefinedException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
LocallyDefinedExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"fieldInvariant"
};
assertThat(
"Results should contain " + LOCALLY_DEFINED_EXCEPTION,
inferResults,
containsExactly(
LOCALLY_DEFINED_EXCEPTION,
SOURCE_FILE,
methods
)
);
}
}

@ -1,62 +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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class NullPointerExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/NullPointerExceptionExample.java";
public static final String NPE =
"java.lang.NullPointerException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
NullPointerExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"callDeref",
"callLeadToNpe",
"npeOnBothBranches",
};
assertThat(
"Results should contain " + NPE,
inferResults,
containsExactly(
NPE,
SOURCE_FILE,
methods
)
);
}
}

@ -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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class ReportOnMainTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/ReportOnMainExample.java";
public static final String NPE =
"java.lang.NullPointerException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
ReportOnMainTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"main"
};
assertThat(
"Results should contain " + NPE,
inferResults,
containsExactly(
NPE,
SOURCE_FILE,
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.java.tracing;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import utils.InferException;
import utils.InferResults;
public class UnavoidableExceptionTest {
public static final String SOURCE_FILE =
"infer/tests/codetoanalyze/java/tracing/UnavoidableExceptionExample.java";
public static final String NPE =
"java.lang.NullPointerException";
private static InferResults inferResults;
@BeforeClass
public static void loadResults() throws InterruptedException, IOException {
inferResults = InferResults.loadTracingResults(
UnavoidableExceptionTest.class,
SOURCE_FILE);
}
@Test
public void matchErrors()
throws IOException, InterruptedException, InferException {
String[] methods = {
"cannotAvoidNPE",
"unavoidableNPEWithParameter",
"virtualMethodWithUnavoidableNPE",
};
assertThat(
"Results should contain " + NPE,
inferResults,
containsExactly(
NPE,
SOURCE_FILE,
methods
)
);
}
}
Loading…
Cancel
Save