Skip to content

Commit

Permalink
Adding pitest parser #5
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Mar 26, 2016
1 parent eb90c64 commit eeb2a62
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ bin
temp
.gradle
node_modules
src/test/resources/tests
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@
Changelog of Git Changelog.

## Unreleased
### GitHub [#5](https://github.com/tomasbjerre/violations-lib/issues/5)

**Adding pitest parser**


[d92f4e82fc3f4d6](https://github.com/tomasbjerre/git-changelog-lib/commit/d92f4e82fc3f4d6) Tomas Bjerre *2016-03-26 19:20:29*


### No issue

**Adding Jenkins plugin link to README.md**


[eb90c644065c9b6](https://github.com/tomasbjerre/git-changelog-lib/commit/eb90c644065c9b6) Tomas Bjerre *2016-03-06 20:20:42*


## 1.5
### GitHub [#3](https://github.com/tomasbjerre/violations-lib/issues/3)

**Support PerlCritic and XMLLint**


[c3677c738317827](https://github.com/tomasbjerre/git-changelog-lib/commit/c3677c738317827) Tomas Bjerre *2016-03-06 13:39:48*
[b7c4ea0c66a4c69](https://github.com/tomasbjerre/git-changelog-lib/commit/b7c4ea0c66a4c69) Tomas Bjerre *2016-03-06 13:45:16*

**Support CPPLint**

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ It supports:
* [_JSHint_](http://jshint.com/)
* _Lint_ A common XML format, used by different linters.
* [_PerlCritic_](https://github.com/Perl-Critic)
* [_PiTest_](http://pitest.org/)
* [_PMD_](https://pmd.github.io/)
* [_ReSharper_](https://www.jetbrains.com/resharper/)
* [_XMLLint_](http://xmlsoft.org/xmllint.html)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
classpath 'net.researchgate:gradle-release:2.2.2'
classpath "gradle.plugin.se.bjurr.gitchangelog:git-changelog-gradle-plugin:1.21"
classpath "gradle.plugin.se.bjurr.gitchangelog:git-changelog-gradle-plugin:1.25"
}
}

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/se/bjurr/violations/lib/parsers/PiTestParser.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public static String getContent(String in, String tag) {
throw new RuntimeException("\"" + tag + "\" not found in " + in);
}

public static Integer getIntegerContent(String in, String tag) {
String content = getContent(in, tag);
return parseInt(content);
}

public static List<String> getLines(String string) {
return Arrays.asList(string.split("\n"));
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/se/bjurr/violations/lib/reports/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import se.bjurr.violations.lib.parsers.LintParser;
import se.bjurr.violations.lib.parsers.PMDParser;
import se.bjurr.violations.lib.parsers.PerlCriticParser;
import se.bjurr.violations.lib.parsers.PiTestParser;
import se.bjurr.violations.lib.parsers.ResharperParser;
import se.bjurr.violations.lib.parsers.ViolationsParser;
import se.bjurr.violations.lib.parsers.XMLLintParser;
Expand All @@ -34,7 +35,8 @@ public enum Reporter {
FLAKE8(new Flake8Parser()), //
CPPLINT(new CppLintParser()), //
XMLLINT(new XMLLintParser()), //
PERLCRITIC(new PerlCriticParser());
PERLCRITIC(new PerlCriticParser()), //
PITEST(new PiTestParser());

private static Logger LOG = Logger.getLogger(Reporter.class.getSimpleName());
private ViolationsParser violationsParser;
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/se/bjurr/violations/lib/PiTestTest.java
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);
}
}
28 changes: 28 additions & 0 deletions src/test/resources/pitest/mutations.xml
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>

0 comments on commit eeb2a62

Please sign in to comment.