Issue #13328: Kill mutation for MatchXpathCheck#13242
Issue #13328: Kill mutation for MatchXpathCheck#13242Kevin222004 wants to merge 1 commit intocheckstyle:masterfrom
Conversation
3142a92 to
b453518
Compare
| } | ||
|
|
||
| @Test | ||
| public void testExceptionMessage() { |
There was a problem hiding this comment.
It's a copy paste of testEvaluationException() with exception checked. It should be possible to test it via input like:
/*
MatchXpath
query = count(*) div 0
*/
package com.puppycrawl.tools.checkstyle.checks.coding.matchxpath;
public class InputWithBadQuery {
}
There was a problem hiding this comment.
Yes, no new pure unit testing in fake tree.
All should be on our AST and on our Check.
There was a problem hiding this comment.
It should be possible to test it via input like:
Yes, but we want to get the exact message of the exception
it won't work with input based
please guide me if I miss anything
@Test
public void testCheckWithMatchingMethodName2() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(MatchXpathCheck.class);
checkConfig.addProperty("query", "count(*) div 0");
try {
verify(checkConfig, getPath("InputMatchXpath5.java"));
}
catch (XPathException ex) {
assertWithMessage("Exception message")
.that(ex.getMessage())
.isEqualTo("Evaluation of Xpath query failed: count(*) div 0");
}
}
Input file is as same as mentioned at #13242 (comment)
There was a problem hiding this comment.
Did you try to catch all exceptions ? I think there should be CheckstyleException
And message will be in cause exception.
There was a problem hiding this comment.
If you tried and it didn't not, please show all all details on how you did this and what is results
There was a problem hiding this comment.
Done please check
c878d96 to
51c1a2e
Compare
src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/MatchXpathCheckTest.java
Outdated
Show resolved
Hide resolved
|
@Kevin222004 please resolve conflicts and address leftovers. |
| final DefaultConfiguration checkConfig = createModuleConfig(MatchXpathCheck.class); | ||
| checkConfig.addProperty("query", "count(*) div 0"); | ||
| try { | ||
| verify(checkConfig, getPath("InputMatchXpath5.java")); | ||
| } | ||
| catch (CheckstyleException ex) { | ||
| final Throwable cause = ex.getCause(); | ||
| assertThat(cause.getMessage()) | ||
| .isEqualTo("Evaluation of Xpath query failed: count(*) div 0"); | ||
| } |
There was a problem hiding this comment.
| final DefaultConfiguration checkConfig = createModuleConfig(MatchXpathCheck.class); | |
| checkConfig.addProperty("query", "count(*) div 0"); | |
| try { | |
| verify(checkConfig, getPath("InputMatchXpath5.java")); | |
| } | |
| catch (CheckstyleException ex) { | |
| final Throwable cause = ex.getCause(); | |
| assertThat(cause.getMessage()) | |
| .isEqualTo("Evaluation of Xpath query failed: count(*) div 0"); | |
| } | |
| final DefaultConfiguration checkConfig = createModuleConfig(MatchXpathCheck.class); | |
| checkConfig.addProperty("query", "count(*) div 0"); | |
| final CheckstyleException ex = assertThrows(CheckstyleException.class, () -> { | |
| verify(checkConfig, getPath("InputMatchXpath5.java")); | |
| }); | |
| assertThat(ex.getCause().getMessage()) | |
| .isEqualTo("Evaluation of Xpath query failed: count(*) div 0"); |
6dd8a36 to
e7374e2
Compare
Non of Check requires property to be set. If we are not sure on default, we usually set some value that is not going to produce any violation. We have empty string in default at https://checkstyle.org/config_coding.html#MatchXpath_Properties , are we going to change it to null ? |
|
looks like we need user defined so it is same pattern that we have in other Checks, we store user defined value but we do not use it acltually outside of setXxxxx. and so we need to preserve user defined value in |
yes if I explicitly set query to |
|
ok, so no main code changes should happen, please extend tests |
|
|
||
| /** Specify Xpath query. */ | ||
| private String query = ""; | ||
| private String query; |
There was a problem hiding this comment.
somthing is broken in this Check.
if user did setQuery ones he can not return Check to default state by setting setQuery("") by providing default value.
it is not possible to set query twice in our config, but plugings (sonar, eclipse-cs) are working directly with modules (no xml), so it might be problem for them.
I am ok with pure junit here , but we need to have default and we need to restore Check instance to default mode of execution by setting defalt value in its setter.
There was a problem hiding this comment.
And we need to reset xpathExpression field if user set empty value.
Empty string should mean null in xpathExpression
There was a problem hiding this comment.
No issue I will look on this by tommorow
There was a problem hiding this comment.
@rdiachenko sorry I haven't visited it yet will update as soon as possible
There was a problem hiding this comment.
@romani I haven't missed #13242 (comment) this but,
please look at the updated pr. I have make a slight change in setter. I don't think it is required to restore check instance.
I added all the kind of test #13242 (comment) please check
There was a problem hiding this comment.
Having null as default, make it impossible to set back to default.
There is no null as value in xml
What I meant is to update setter to:
if (!query.isEmpty()) {
....
} else {
this.query = "";
this.xpathExpression = null;
}
There was a problem hiding this comment.
Not sure I'm following the request with null. @Kevin222004 what's the latest status of this PR?
There was a problem hiding this comment.
We should remove such field, having this.xpathExpression is enough.
We have no functionality to reuse what user set, so we can loose it for now.
b87de9c to
26e293e
Compare
|
@Kevin222004 , please resolve conflict. |
|
@Kevin222004 , please focus on this PR, lets finish it. |
26e293e to
80a2da3
Compare
80a2da3 to
1bd06c4
Compare
|
Still bunch CI failures and review item above is not addressed |
|
@Kevin222004 I'm closing this PR in favour of #13726. Please take a look at it, if you have any questions I'm happy to help. |
Issue #13328: Kill mutation for MatchXpathCheck
Check
https://checkstyle.org/config_coding.html#MatchXpath
Mutation
checkstyle/config/pitest-suppressions/pitest-coding-2-suppressions.xml
Lines 39 to 55 in 3f25c37
Explaination
The reason to create a pure unit testing for mutation
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MatchXpathCheck.java
Line 238 in 3f25c37
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MatchXpathCheck.java
Line 297 in 3f25c37
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/MatchXpathCheck.java
Line 226 in 3f25c37
Removal of " " will not create an issue as it is going to change to null. This check always require to set property.