-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb90c64
commit eeb2a62
Showing
9 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ bin | |
temp | ||
.gradle | ||
node_modules | ||
src/test/resources/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package se.bjurr.violations.lib.parsers; | ||
|
||
import static com.google.common.base.Charsets.UTF_8; | ||
import static com.google.common.collect.ImmutableMap.of; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.model.Violation.violationBuilder; | ||
import static se.bjurr.violations.lib.reports.Reporter.PITEST; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
import com.google.common.io.Files; | ||
|
||
public class PiTestParser extends ViolationsParser { | ||
|
||
@Override | ||
public List<Violation> parseFile(File file) throws Exception { | ||
String string = Files.toString(file, UTF_8); | ||
List<Violation> violations = newArrayList(); | ||
String mutations = getContent(string, "mutations"); | ||
List<String> mutationChunks = getChunks(mutations, "<mutation", "</mutation>"); | ||
for (String mutationChunk : mutationChunks) { | ||
String mutatedClass = getContent(mutationChunk, "mutatedClass"); | ||
String sourceFile = getContent(mutationChunk, "sourceFile"); | ||
String filename = toFilename(mutatedClass, sourceFile); | ||
String status = getAttribute(mutationChunk, "status"); | ||
String detected = getAttribute(mutationChunk, "detected"); | ||
String mutatedMethod = getContent(mutationChunk, "mutatedMethod"); | ||
String methodDescription = getContent(mutationChunk, "methodDescription"); | ||
String mutator = getContent(mutationChunk, "mutator"); | ||
String message = status + ", " + mutator + ", " + methodDescription; | ||
Integer startLine = getIntegerContent(mutationChunk, "lineNumber"); | ||
Integer index = getIntegerContent(mutationChunk, "index"); | ||
violations.add(// | ||
violationBuilder()// | ||
.setRule(mutator)// | ||
.setSource(sourceFile)// | ||
.setReporter(PITEST)// | ||
.setStartLine(startLine)// | ||
.setColumn(index)// | ||
.setFile(filename)// | ||
.setSeverity(WARN)// | ||
.setMessage(message)// | ||
.setSpecifics(// | ||
of(// | ||
"detected", detected,// | ||
"mutatedMethod", mutatedMethod,// | ||
"mutatedClass", mutatedClass,// | ||
"status", status,// | ||
"methodDescription", methodDescription))// | ||
.build()// | ||
); | ||
} | ||
return violations; | ||
} | ||
|
||
/** | ||
* Use package from mutadedClass and assume sourceFile is in that package. | ||
*/ | ||
private String toFilename(String mutatedClass, String sourceFile) { | ||
return mutatedClass.substring(0, mutatedClass.lastIndexOf(".")).replaceAll("\\.", "/") + "/" + sourceFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.reports.Reporter.PITEST; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class PiTestTest { | ||
|
||
@Test | ||
public void testThatViolationsCanBeParsed() { | ||
String rootFolder = getRootFolder(); | ||
|
||
List<Violation> actual = violationsReporterApi() // | ||
.withPattern(".*/pitest/.*\\.xml$") // | ||
.inFolder(rootFolder) // | ||
.findAll(PITEST) // | ||
.violations(); | ||
|
||
assertThat(actual)// | ||
.hasSize(25); | ||
|
||
assertThat(actual.get(0).getFile())// | ||
.isEqualTo("se/bjurr/violations/lib/example/CopyOfMyClass.java"); | ||
assertThat(actual.get(0).getMessage())// | ||
.isEqualTo("NO_COVERAGE, org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator, (Ljava/lang/Object;)Z"); | ||
assertThat(actual.get(0).getStartLine())// | ||
.isEqualTo(17); | ||
assertThat(actual.get(0).getEndLine())// | ||
.isEqualTo(17); | ||
assertThat(actual.get(0).getSeverity())// | ||
.isEqualTo(WARN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<mutations> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>CopyOfMyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.CopyOfMyClass</mutatedClass><mutatedMethod>equals</mutatedMethod><methodDescription>(Ljava/lang/Object;)Z</methodDescription><lineNumber>17</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>CopyOfMyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.CopyOfMyClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>7</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>CopyOfMyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.CopyOfMyClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>8</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator</mutator><index>8</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>hashCode</mutatedMethod><methodDescription>()I</methodDescription><lineNumber>17</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>myMethod</mutatedMethod><methodDescription>()V</methodDescription><lineNumber>10</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>6</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>6</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>8</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>10</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>12</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>14</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>16</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>18</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>20</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>OtherClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.OtherClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(ZZZZZZZZZ)Z</methodDescription><lineNumber>26</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>30</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>equals</mutatedMethod><methodDescription>(Ljava/lang/Object;)Z</methodDescription><lineNumber>34</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>7</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>8</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator</mutator><index>8</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>npe</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>9</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator</mutator><index>12</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>npe2</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>24</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>4</index><killingTest/></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>npe2</mutatedMethod><methodDescription>(Ljava/lang/String;Ljava/lang/String;)V</methodDescription><lineNumber>25</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator</mutator><index>8</index><killingTest/></mutation> | ||
<mutation detected='true' status='KILLED'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>thisIsTested</mutatedMethod><methodDescription>(II)I</methodDescription><lineNumber>17</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>5</index><killingTest>se.bjurr.violations.lib.example.MyClassTest.test(se.bjurr.violations.lib.example.MyClassTest)</killingTest></mutation> | ||
<mutation detected='true' status='KILLED'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>thisIsTested</mutatedMethod><methodDescription>(II)I</methodDescription><lineNumber>17</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator</mutator><index>8</index><killingTest>se.bjurr.violations.lib.example.MyClassTest.test(se.bjurr.violations.lib.example.MyClassTest)</killingTest></mutation> | ||
<mutation detected='true' status='KILLED'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>thisIsTested</mutatedMethod><methodDescription>(II)I</methodDescription><lineNumber>18</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>12</index><killingTest>se.bjurr.violations.lib.example.MyClassTest.test(se.bjurr.violations.lib.example.MyClassTest)</killingTest></mutation> | ||
<mutation detected='false' status='NO_COVERAGE'><sourceFile>MyClass.java</sourceFile><mutatedClass>se.bjurr.violations.lib.example.MyClass</mutatedClass><mutatedMethod>thisIsTested</mutatedMethod><methodDescription>(II)I</methodDescription><lineNumber>20</lineNumber><mutator>org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator</mutator><index>17</index><killingTest/></mutation> | ||
</mutations> |