Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: feat: add mode ignore-syntax-errors #4054

Merged
merged 7 commits into from
Aug 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor TreeBuilderCompilerTest
  • Loading branch information
andrewbwogi committed Aug 11, 2021
commit 3496e2ba7af3c32d4103d6c04189b8f4487a5708
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,47 @@
public class TreeBuilderCompilerTest {

@Test
public void testIgnoreSyntaxErrors() {
public void testIgnoreSyntaxErrorsCompilation() {
// contract: if a file has any syntax errors, it is filtered out, otherwise, it is compiled
final TestLogger logger = TestLoggerFactory.getTestLogger(TreeBuilderCompiler.class);
Launcher launcher = new Launcher();
launcher.getEnvironment().setIgnoreSyntaxErrors(true);
launcher.addInputResource("./src/test/resources/compilation2/InvalidClass.java");
Launcher launcher = setupLauncher();
launcher.addInputResource("./src/test/resources/compilation/ClassWithStaticFields.java");
launcher.buildModel();
CtModel model = launcher.getModel();
assertEquals(1,model.getAllTypes().size());
}

// contract: if a file has any syntax errors, the incorrect file name is logged
assertTrue(logger.getLoggingEvents().get(0).getMessage().startsWith("Syntax error detected in"));
@Test
public void testIgnoreSyntaxErrorsLogging() {
// contract: if a file has any syntax errors, the name of the incorrect file is logged
TestLogger logger = TestLoggerFactory.getTestLogger(TreeBuilderCompiler.class);
Launcher launcher = setupLauncher();
launcher.buildModel();
assertTrue(logger.getLoggingEvents().get(0).getMessage().endsWith("InvalidClass.java"));
}

@Test
public void testEveryInputHasSyntaxError() {
// contract: if every input resource has a syntax error, spoon does not crash
launcher = new Launcher();
launcher.getEnvironment().setIgnoreSyntaxErrors(true);
launcher.addInputResource("./src/test/resources/compilation2/InvalidClass.java");
Launcher launcher = setupLauncher();
launcher.buildModel();
model = launcher.getModel();
CtModel model = launcher.getModel();
assertTrue(model.getAllTypes().isEmpty());
}

// contract: filter-invalid can be enabled with a command line argument
launcher = new Launcher();
@Test
public void testIgnoreSyntaxErrorsCommandLine() {
// contract: ignore-syntax-errors can be enabled with a command line argument
Launcher launcher = new Launcher();
launcher.setArgs(new String[]{"--ignore-syntax-errors", "-i", "./src/test/resources/compilation2/InvalidClass.java"});
launcher.buildModel();
model = launcher.getModel();
CtModel model = launcher.getModel();
assertTrue(model.getAllTypes().isEmpty());
}

private Launcher setupLauncher() {
Launcher launcher = new Launcher();
launcher.getEnvironment().setIgnoreSyntaxErrors(true);
launcher.addInputResource("./src/test/resources/compilation2/InvalidClass.java");
return launcher;
}
}
  NODES
COMMUNITY 2
Note 1
Project 2
USERS 1