diff --git a/infer/tests/codetoanalyze/c/errors/null_dereference/getc.c b/infer/tests/codetoanalyze/c/errors/null_dereference/getc.c index 0e40ed302..ecf0ecb4d 100644 --- a/infer/tests/codetoanalyze/c/errors/null_dereference/getc.c +++ b/infer/tests/codetoanalyze/c/errors/null_dereference/getc.c @@ -1,57 +1,43 @@ #include #include - - -void crashgetc() { - - +void crash_getc() { FILE *f; int i; - - f=fopen("this_file_doesnt_exists", "r"); - i =getc(f); - printf("i =%i\n", i); + f = fopen("this_file_doesnt_exists", "r"); + i = getc(f); + printf("i =%i\n", i); fclose(f); } -void nocrashgetc() { - - +void nocrash_getc() { FILE *f; int i; - - f=fopen("this_file_doesnt_exists", "r"); - - + f = fopen("this_file_doesnt_exists", "r"); if (f) { - i =getc(f); + i = getc(f); printf("i =%i\n", i); fclose(f); } } -void crashfgetc() { - +void crash_fgetc() { FILE *f; int i; - - f=fopen("this_file_doesnt_exists", "r"); - i =fgetc(f); + f = fopen("this_file_doesnt_exists", "r"); + i = fgetc(f); printf("i =%i\n", i); fclose(f); } -void nocrashfgetc() { - +void nocrash_fgetc() { FILE *f; int i; - - f=fopen("this_file_doesnt_exists", "r"); + f = fopen("this_file_doesnt_exists", "r"); if (f) { - i =fgetc(f); + i = fgetc(f); printf("i =%i\n", i); - fclose(f); + fclose(f); } } diff --git a/infer/tests/endtoend/c/NullDereferenceTest2.java b/infer/tests/endtoend/c/NullDereferenceTest2.java index cb3fd60de..5c9dae4be 100644 --- a/infer/tests/endtoend/c/NullDereferenceTest2.java +++ b/infer/tests/endtoend/c/NullDereferenceTest2.java @@ -6,8 +6,7 @@ package endtoend.c; import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.ResultContainsErrorInMethod.contains; - +import static utils.matchers.ResultContainsExactly.containsExactly; import org.junit.BeforeClass; import org.junit.Test; @@ -20,7 +19,7 @@ import utils.InferResults; public class NullDereferenceTest2 { public static final String SOURCE_FILE = - "null_dereference/get.c"; + "null_dereference/getc.c"; public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE"; @@ -34,31 +33,21 @@ public class NullDereferenceTest2 { SOURCE_FILE); } - /* - @Test - public void nullDereferenceTest2() throws InterruptedException, IOException, InferException { - assertThat( - "Results should contain null pointer dereference error", - inferResults, - contains( - NULL_DEREFERENCE, - SOURCE_FILE, - "crashgetc" - ) - ); - } - @Test - public void nullDereferenceTest2_fgetc() throws InterruptedException, IOException, InferException { + public void nullDereferenceTest() throws InterruptedException, IOException, InferException { + String[] procedures = { + "crash_getc", + "crash_fgetc", + }; + System.out.println(inferResults.toString()); assertThat( "Results should contain null pointer dereference error", inferResults, - contains( + containsExactly( NULL_DEREFERENCE, SOURCE_FILE, - "crashfgetc" + procedures ) ); } - */ } diff --git a/infer/tests/utils/InferResults.java b/infer/tests/utils/InferResults.java index 354f94533..558c89462 100644 --- a/infer/tests/utils/InferResults.java +++ b/infer/tests/utils/InferResults.java @@ -107,6 +107,7 @@ public class InferResults { for (InferError e : errors) { s = s + "\n" + e.toString(); } + if (s.length() == 0) return "No results."; return s; }