-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Core] Add location to tag expression expcetion #1979
Conversation
* Updated TagExpressionParser to use static parse function
* WIP on fixing #1976 * Added TagExpressionException interception to CoreHookDefinition to add the hook that caused the exception to be added to the exception information at runtime. * Added a test for this in HookTest
* Updated TagPredicate to intercept TagExpressionException to add information about where the exceptin comes form. * Added a test to ensure that the information is added
* Updated various parsers to use TagExpressionParser so that the parse is closer to the beginning of the run. * Updated tests to pass. Additionally, as there is no equals method override on Expression instances, I had to call toString() on them so that matching could occur. This could be improved by overriding equals so that Hamcrest matchers could match directly but overriding equals is tricky to get right so used the already overridden toString instead.
* Updated tag expression parsing on CommandLineOptionParser and CucumberOptionsAnnotationParser * Updated everything that uses the tag expression to use and Expression object rather than a string * Updated tests to reflect the new method of parsing
* Updated everything that uses the tag expression to use and Expression object rather than a string * Updated tests to reflect the new method of parsing (d91208c)
core/src/main/java/io/cucumber/core/options/CucumberOptionsAnnotationParser.java
Outdated
Show resolved
Hide resolved
try { | ||
this.tagExpression = TagExpressionParser.parse(delegate.getTagExpression()); | ||
} catch (TagExpressionException tee) { | ||
throw new IllegalArgumentException(String.format("%s at '%s'", tee.getMessage(), delegate.getLocation()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You originally pushed this down into the different hook implementations. I think because I suggested something about being as close to the source as possible. However this means that we'll have to implement the correct location reporting in all different hook implementations. Using the getLocation
method we can get the location of the hook. So this is close enough.
core/src/test/java/io/cucumber/core/filter/TagPredicateTest.java
Outdated
Show resolved
Hide resolved
try { | ||
parsedOptions.addTagFilter(TagExpressionParser.parse(removeArgFor(arg, args))); | ||
} catch (TagExpressionException tee) { | ||
throw new IllegalArgumentException(tee); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll have to look at this. Currently the problem is that it doesn't report back where the problem came from. But this is true for all other CLI arguments as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be easier if we have a shared session to discuss the options.
I've reverted the changes to This usually means that a bit more code has to change. Something like: @Override
public Optional<CucumberOptionsAnnotationParser.CucumberOptions> getOptions(Class<?> clazz) {
final CucumberOptions annotation = clazz.getAnnotation(CucumberOptions.class);
if (annotation == null) {
return Optional.empty();
}
return Optional.of(new CoreCucumberOptions(annotation));
}
} requireNonNull(optionsProvider).getOptions(classWithOptions)
.ifPresent(options -> {
addDryRun(options, args);
addMonochrome(options, args);
addTags(clazz, options, args);
addPlugins(options, args);
addStrict(options, args);
addName(options, args);
addSnippets(options, args);
addGlue(options, args);
addFeatures(options, args);
addObjectFactory(options, args);
});
} |
Thanks for the changes. I have not had a chance to look over them yet. I know you had suggested to revert the change that I made to HookDefinition. I have done that locally but I am having serious difficulties with a test that I cannot see why it is failing so I am a bit stuck at the moment. |
Summary
This integrates changes to the way that TagExpressionParser works in Cucumber-JVM to fix #1976.
Details
Updated the TagPredicate and the CoreHookDefinition to catch TagExpressionException and add information from the relevant classes to the exception message which is then wrapped in a RuntimeException and rethrown. The rethrow as a RuntimeException is due to the fact that the constructor for TagExpressionParser is package scope only and is not available in other packages.
Motivation and Context
This is to fix issue #1976.
How Has This Been Tested?
Added tests to both TagPredicateTest and CoreHookDefinition test to see if the proper exception was rethrown and if the information expected was included in the expected exception.
Screenshots (if appropriate):
Types of changes
Checklist: