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

Conversation

andrewbwogi
Copy link
Contributor

@andrewbwogi andrewbwogi commented Jul 18, 2021

closes #3954, closes #3952

@andrewbwogi andrewbwogi changed the title wip: feat: add mode filter-invalid review: feat: add mode filter-invalid Aug 7, 2021
Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andrewbwogi, thanks for putting in this work!

I'll leave it to @monperrus to provide final feedback on this PR, but I have some initial thoughts.

First of all, the name "filter invalid" is not precise to me, it doesn't immediately tell me the purpose of the option. The word "filter" is a bit ambiguous in its own right (although in functional programming it's a pretty ubiquitous function), and "invalid" does not specify what is invalid. How about something like "ignore syntax errors" or "ignore invalid syntax" instead? Or perhaps even "ignore files with invalid syntax", which precisely defines the functionality, but locks the semantics of this option to ignore entire files (perhaps we want to ignore parts of files in the future).

I also left a comment on the test method, it ought to be refactored.

Comment on lines 17 to 42
final TestLogger logger = TestLoggerFactory.getTestLogger(TreeBuilderCompiler.class);
Launcher launcher = new Launcher();
launcher.getEnvironment().setFilterInvalid(true);
launcher.addInputResource("./src/test/resources/compilation2/InvalidClass.java");
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"));

// contract: if every input resource has a syntax error, spoon does not crash
launcher = new Launcher();
launcher.getEnvironment().setFilterInvalid(true);
launcher.addInputResource("./src/test/resources/compilation2/InvalidClass.java");
launcher.buildModel();
model = launcher.getModel();
assertTrue(model.getAllTypes().isEmpty());

// contract: filter-invalid can be enabled with a command line argument
launcher = new Launcher();
launcher.setArgs(new String[]{"--filter-invalid", "-i", "./src/test/resources/compilation2/InvalidClass.java"});
launcher.buildModel();
model = launcher.getModel();
assertTrue(model.getAllTypes().isEmpty());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is four different tests squeezed into one. Arguably, the logger test could be squeezed into the first one to save space, but the two tests at the bottom are completely independent of the rest of the method and should absolutely be tests of their own.

@monperrus
Copy link
Collaborator

Thanks @andrewbwogi for this PR.

How about something like "ignore syntax errors" or "ignore invalid syntax" instead?

I like --ignore-syntax-errors, it's very explicit.

@andrewbwogi andrewbwogi changed the title review: feat: add mode filter-invalid review: feat: add mode ignore-syntax-errors Aug 11, 2021
Copy link
Collaborator

@slarse slarse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @andrewbwogi, thanks!

I've no further comments, but as this is a new feature I'd like @monperrus to have the final look and merge.

Ping @monperrus :)

@monperrus monperrus merged commit 4061542 into INRIA:master Aug 12, 2021
@monperrus
Copy link
Collaborator

Perfect! Thanks a lot @andrewbwogi for the PR and @slarse for the review!

@monperrus monperrus mentioned this pull request Aug 19, 2021
woutersmeenk pushed a commit to woutersmeenk/spoon that referenced this pull request Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
  NODES
COMMUNITY 2
Project 3
USERS 1