Refactor C frontend tests

Reviewed By: @dulmarod

Differential Revision: D2521747

fb-gh-sync-id: 1be8d21
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent d4c3d39fb9
commit 7ac5a5c308

@ -9,107 +9,48 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class ArithmeticExpTest {
String arithmeticBasePath = "infer/tests/codetoanalyze/c/frontend/arithmetic/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, arithmeticBasePath + fileRelative);
}
@Test
public void whenCaptureRunOnPlus_exprThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String plus_expr =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/plus_expr.c";
String plus_expr_dotty =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/plus_expr.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, plus_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + plus_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(plus_expr_dotty));
frontendTest("plus_expr.c");
}
@Test
public void whenCaptureRunOnCompound_assignmentThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String compound_assignment_expr =
"infer/tests/codetoanalyze/c/frontend/" +
"arithmetic/compound_assignment.c";
String compound_assignment_dotty =
"infer/tests/codetoanalyze/c/frontend/" +
"arithmetic/compound_assignment.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
compound_assignment_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + compound_assignment_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(compound_assignment_dotty));
frontendTest("compound_assignment.c");
}
@Test
public void whenCaptureRunOnUnaryThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String unary_expr =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/unary.c";
String unary_dotty =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/unary.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, unary_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + unary_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(unary_dotty));
frontendTest("unary.c");
}
@Test
public void whenCaptureRunOnIntConstThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String int_const_expr =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/int_const.c";
String int_const_dotty =
"infer/tests/" +
"codetoanalyze/c/frontend/arithmetic/int_const.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, int_const_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + int_const_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(int_const_dotty));
frontendTest("int_const.c");
}
}

@ -9,60 +9,36 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class BoolTest {
String boolBasePath = "infer/tests/codetoanalyze/c/frontend/booleans/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, boolBasePath + fileRelative);
}
@Test
public void whenCaptureRunCommaThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String bool_src = "infer/tests/codetoanalyze/c/frontend/booleans/bool_example.c";
String bool_dotty = "infer/tests/codetoanalyze/c/frontend/booleans/bool_example.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
bool_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + bool_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(bool_dotty));
frontendTest("bool_example.c");
}
@Test
public void whenCaptureBooleanConditionAsParamThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String bool_src = "infer/tests/codetoanalyze/c/frontend/booleans/condition_as_param.c";
String bool_dotty = "infer/tests/codetoanalyze/c/frontend/booleans/condition_as_param.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
bool_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + bool_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(bool_dotty));
frontendTest("condition_as_param.c");
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class CommaOperatorTest {
@ -33,20 +27,7 @@ public class CommaOperatorTest {
@Test
public void whenCaptureRunCommaThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String switch_src =
"infer/tests/codetoanalyze/c/frontend/comma/comma.c";
String switch_dotty =
"infer/tests/codetoanalyze/c/frontend/comma/comma.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
switch_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + switch_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(switch_dotty));
String src = "infer/tests/codetoanalyze/c/frontend/comma/comma.c";
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,235 +9,91 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class ConditionalOperatorTest {
String conditionalOperatorBasePath = "infer/tests/codetoanalyze/c/frontend/conditional_operator/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, conditionalOperatorBasePath + fileRelative);
}
@Test
public void whenCaptureRunCommaThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/conditional_operator.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/conditional_operator.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("conditional_operator.c");
}
@Test
public void whenCaptureRunShortCThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/if_short_circuit.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/if_short_circuit.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("if_short_circuit.c");
}
@Test
public void whenCaptureRunCond2ThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/cond2.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/cond2.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("cond2.c");
}
@Ignore @Test
public void whenCaptureRunOnAssertExampleThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/assert_example.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/assert_example.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("assert_example.c");
}
@Test
public void whenCaptureRunOnIntNegationThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/int_negation.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/int_negation.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
}
@Test
public void whenCaptureRunOnIntNegationThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
frontendTest("int_negation.c");
}
@Test
public void whenCaptureRunBinaryOperatorThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/binary_operator.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/binary_operator.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("binary_operator.c");
}
@Test
public void whenCaptureRunUnaryOperatorThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("unary_operator.c");
}
@Test
public void whenCaptureRunArrayAccessThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/array_access.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/array_access.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("array_access.c");
}
@Test
public void whenCaptureRunMemberAccessThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/member_access.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/member_access.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("member_access.c");
}
@Test
public void whenCaptureRunPreincrementThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/preincrement.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/preincrement.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("preincrement.c");
}
@Test
public void whenCaptureRunFunctionCallThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String cond_src =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/function_call.c";
String cond_dotty =
"infer/tests/codetoanalyze/c/frontend/conditional_operator/function_call.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
cond_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + cond_src + " the dotty files should be the same.",
newDotFile, dotFileEqualTo(cond_dotty));
frontendTest("function_call.c");
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class EnumerationTest {
@ -33,20 +27,8 @@ public class EnumerationTest {
@Test
public void whenCaptureRunEnumThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String enum_expr =
"infer/tests/codetoanalyze/c/frontend/enumeration/enum.c";
String enum_dotty =
"infer/tests/codetoanalyze/c/frontend/enumeration/enum.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, enum_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + enum_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(enum_dotty));
String src = "infer/tests/codetoanalyze/c/frontend/enumeration/enum.c";
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class GnuexprTest {
@ -33,21 +27,10 @@ public class GnuexprTest {
@Test
public void whenCaptureRunOnWhileThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String gnu_expr =
String src =
"infer/tests/codetoanalyze/" +
"c/frontend/nestedoperators/gnuexpr.c";
String gnu_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/nestedoperators/gnuexpr.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, gnu_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + gnu_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(gnu_dotty));
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class GotoStmtLabelStmtTest {
@ -33,18 +27,7 @@ public class GotoStmtLabelStmtTest {
@Test
public void whenCaptureRunGotoStmtThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String src_file =
"infer/tests/codetoanalyze/c/frontend/gotostmt/goto_ex.c";
String dot_file =
"infer/tests/codetoanalyze/c/frontend/gotostmt/goto_ex.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, src_file);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + src_file +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(dot_file));
String src = "infer/tests/codetoanalyze/c/frontend/gotostmt/goto_ex.c";
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,62 +9,35 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class InitListExprTest {
String initListBasePath = "infer/tests/codetoanalyze/c/frontend/initialization/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, initListBasePath + fileRelative);
}
@Test
public void whenCaptureRunOnArrayInitListExprThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String plus_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/initialization/array_initlistexpr.c";
String plus_expr_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/initialization/array_initlistexpr.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, plus_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + plus_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(plus_expr_dotty));
frontendTest("array_initlistexpr.c");
}
@Test
public void whenCaptureRunOnStructInitListExprThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String plus_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/initialization/struct_initlistexpr.c";
String plus_expr_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/initialization/struct_initlistexpr.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, plus_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + plus_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(plus_expr_dotty));
frontendTest("struct_initlistexpr.c");
}
}

@ -9,329 +9,120 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class LoopsTest {
String loopsBasePath = "infer/tests/codetoanalyze/c/frontend/loops/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, loopsBasePath + fileRelative);
}
@Test
public void whenCaptureRunOnWhileThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String while_expr =
"infer/tests/codetoanalyze/c/frontend/loops/while.c";
String while_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/while.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(while_dotty));
frontendTest("while.c");
}
@Test
public void whenCaptureRunOnWhile_nestedThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String while_expr =
"infer/tests/codetoanalyze/c/frontend/loops/while_nested.c";
String while_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/while_nested.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(while_dotty));
frontendTest("while_nested.c");
}
@Test
public void whenCaptureRunOnWhile_side_effectsThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String while_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/while_condition_side_effects.c";
String while_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/while_condition_side_effects.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(while_dotty));
frontendTest("while_condition_side_effects.c");
}
@Test
public void whenCaptureRunOnWhile_no_bodyThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String while_expr =
"infer/tests/codetoanalyze/c/frontend/loops/while_no_body.c";
String while_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/while_no_body.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(while_dotty));
frontendTest("while_no_body.c");
}
@Test
public void whenCaptureRunOnForside_effectsThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_condition_side_effects.c";
String for_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_condition_side_effects.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_condition_side_effects.c");
}
@Test
public void whenCaptureRunOnFor_nestedThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/c/frontend/loops/for_nested.c";
String for_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/for_nested.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_nested.c");
}
@Test
public void whenCaptureRunOnFor_no_conditionThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition.c";
String for_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_no_condition.c");
}
@Test
public void whenCaptureRunOnFor_no_conditionincrThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition_incr.c";
String for_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition_incr.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_no_condition_incr.c");
}
@Test
public void whenCaptureRunOnFor_emptyThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition_incr_body.c";
String for_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_no_condition_incr_body.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_no_condition_incr_body.c");
}
@Test
public void whenCaptureRunOnFor_only_bodyThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/c/frontend/loops/for_only_body.c";
String for_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/for_only_body.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_only_body.c");
}
@Test
public void whenCaptureRunOnFor_simpleThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/c/frontend/loops/for_simple.c";
String for_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/for_simple.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_simple.c");
}
@Test
public void whenCaptureRunOnFor_while_nestedThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String for_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_while_nested.c";
String for_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/for_while_nested.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, for_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + for_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(for_dotty));
frontendTest("for_while_nested.c");
}
@Test
public void whenCaptureRunOnDo_whileThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String do_while_expr =
"infer/tests/codetoanalyze/c/frontend/loops/do_while.c";
String do_while_dotty =
"infer/tests/codetoanalyze/c/frontend/loops/do_while.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, do_while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + do_while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(do_while_dotty));
frontendTest("do_while.c");
}
@Test
public void whenCaptureRunOnDo_while_side_effectsThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String do_while_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/do_while_condition_side_effects.c";
String do_while_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/do_while_condition_side_effects.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, do_while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + do_while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(do_while_dotty));
frontendTest("do_while_condition_side_effects.c");
}
@Test
public void whenCaptureRunOnDo_while_nestedThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String do_while_expr =
"infer/tests/codetoanalyze/c/frontend/loops/do_while_nested.c";
String do_while_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/do_while_nested.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, do_while_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + do_while_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(do_while_dotty));
frontendTest("do_while_nested.c");
}
@Test
public void whenCaptureWhile_with_continue_and_breakThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String while_with_continue_and_break_expr =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/while_with_continue_and_break.c";
String while_with_continue_and_break_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/loops/while_with_continue_and_break.dot";
ImmutableList<String> inferCmd = InferRunner.createCInferCommandFrontend(
folder, while_with_continue_and_break_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + while_with_continue_and_break_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(while_with_continue_and_break_dotty));
frontendTest("while_with_continue_and_break.c");
}
}

@ -9,90 +9,44 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class NestedOperatorsTest {
String nestedOperatorsBasePath = "infer/tests/codetoanalyze/c/frontend/nestedoperators/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCDotFiles(folder, nestedOperatorsBasePath + fileRelative);
}
@Test
public void whenCaptureRunEnumThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String nestedassignment_expr =
"infer/tests/codetoanalyze/c/frontend/" +
"nestedoperators/nestedassignment.c";
String nestedassignment_dotty =
"infer/tests/codetoanalyze/c/frontend/" +
"nestedoperators/nestedassignment.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
nestedassignment_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + nestedassignment_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(nestedassignment_dotty));
frontendTest("nestedassignment.c");
}
@Test
public void whenCaptureRunUnionThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String nestedunion_expr =
"infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c";
String nestedunion_dotty =
"infer/tests/" +
"codetoanalyze/c/frontend/nestedoperators/union.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
nestedunion_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + nestedunion_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(nestedunion_dotty));
frontendTest("union.c");
}
@Test
public void whenCaptureRunAssignInConditionThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String condition_assign_expr =
"infer/tests/codetoanalyze/c/frontend/nestedoperators/assign_in_condition.c";
String condition_assign_dotty =
"infer/tests/" +
"codetoanalyze/c/frontend/nestedoperators/assign_in_condition.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
condition_assign_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + condition_assign_expr +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(condition_assign_dotty));
frontendTest("assign_in_condition.c");
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class PrototypeTest {
@ -33,21 +27,10 @@ public class PrototypeTest {
@Test
public void whenCaptureRunOnC_prototypeThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String prototype_expr =
String src =
"infer/tests/codetoanalyze/" +
"c/frontend/c_prototype/prototype.c";
String prototype_dotty =
"infer/tests/codetoanalyze/" +
"c/frontend/c_prototype/prototype.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, prototype_expr);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + prototype_expr +
" the dotty files should be the same. ",
newDotFile, dotFileEqualTo(prototype_dotty));
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,20 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferRunner;
import utils.ClangFrontendUtils;
public class SwitchStmtTest {
@ -32,18 +26,7 @@ public class SwitchStmtTest {
@Test
public void whenCaptureRunSwitchStmtThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String switch_src =
"infer/tests/codetoanalyze/c/frontend/switchstmt/switch.c";
String switch_dotty =
"infer/tests/codetoanalyze/c/frontend/switchstmt/switch.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, switch_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + switch_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(switch_dotty));
String src = "infer/tests/codetoanalyze/c/frontend/switchstmt/switch.c";
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -9,19 +9,14 @@
package frontend.c;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.DotFilesEqual.dotFileEqualTo;
import com.google.common.collect.ImmutableList;
import org.junit.Rule;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.ClangFrontendUtils;
import utils.InferRunner;
public class TypesTest {
@ -32,18 +27,7 @@ public class TypesTest {
@Test
public void whenCaptureRunStructThenDotFilesAreTheSame()
throws InterruptedException, IOException, InferException {
String switch_src =
"infer/tests/codetoanalyze/c/frontend/types/struct.c";
String switch_dotty =
"infer/tests/codetoanalyze/c/frontend/types/struct.dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(folder, switch_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + switch_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(switch_dotty));
String src = "infer/tests/codetoanalyze/c/frontend/types/struct.c";
ClangFrontendUtils.createAndCompareCDotFiles(folder, src);
}
}

@ -38,4 +38,19 @@ public class ClangFrontendUtils {
newDotFile, dotFileEqualTo(test_dotty));
}
public static void createAndCompareCDotFiles(DebuggableTemporaryFolder folder, String pathToSrcFile)
throws InterruptedException, IOException, InferException {
String test_src = pathToSrcFile;
String test_dotty = pathToSrcFile + ".dot";
ImmutableList<String> inferCmd =
InferRunner.createCInferCommandFrontend(
folder,
test_src);
File newDotFile = InferRunner.runInferFrontend(inferCmd);
assertThat(
"In the capture of " + test_src +
" the dotty files should be the same.",
newDotFile, dotFileEqualTo(test_dotty));
}
}

Loading…
Cancel
Save