Skip to content

Commit

Permalink
CPPCheckParser results version 2 tomasbjerre#82
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Feb 6, 2020
1 parent 957fd93 commit 2b96ad7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/test/java/se/bjurr/violations/lib/CPPCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.Test;

import se.bjurr.violations.lib.model.Violation;
import se.bjurr.violations.lib.reports.Parser;

Expand Down Expand Up @@ -152,4 +154,43 @@ public void testThatViolationsCanBeParsedWhenErrorTagHasNoEndtag() {
assertThat(violation0.getMessage()) //
.startsWith("The scope of the variable");
}

@Test
public void testThatViolationsCanBeParsedWithVersion2() {
final String rootFolder = getRootFolder();

final List<Violation> actual =
violationsApi() //
.withPattern(".*/cppcheck/results-version-2\\.xml$") //
.inFolder(rootFolder) //
.findAll(CPPCHECK) //
.violations();

assertThat(actual) //
.hasSize(4);

final Violation violation0 = actual.get(0);
assertThat(violation0.getStartLine()) //
.isEqualTo(53);
assertThat(violation0.getMessage()) //
.isEqualTo("Variable 'it' is reassigned a value before the old one has been used.");

final Violation violation1 = actual.get(1);
assertThat(violation1.getStartLine()) //
.isEqualTo(51);
assertThat(violation1.getMessage()) //
.isEqualTo("Variable 'it' is reassigned a value before the old one has been used.");

final Violation violation2 = actual.get(2);
assertThat(violation2.getStartLine()) //
.isEqualTo(53);
assertThat(violation2.getMessage()) //
.isEqualTo("Variable 'that' is reassigned a value before the old one has been used.");

final Violation violation3 = actual.get(3);
assertThat(violation3.getStartLine()) //
.isEqualTo(51);
assertThat(violation3.getMessage()) //
.isEqualTo("Variable 'that' is reassigned a value before the old one has been used.");
}
}
32 changes: 32 additions & 0 deletions src/test/resources/cppcheck/results-version-2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.52" />
<error id="redundantAssignment" severity="style"
msg="Variable &apos;it&apos; is reassigned a value before the old one has been used."
verbose="Variable &apos;it&apos; is reassigned a value before the old one has been used."
cwe="563">
<location
file0="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
file="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
line="53" />
<location
file0="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
file="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
line="51" />
<symbol>it</symbol>
</error>
<error id="redundantAssignment" severity="style"
msg="Variable &apos;that&apos; is reassigned a value before the old one has been used."
verbose="Variable &apos;that&apos; is reassigned a value before the old one has been used."
cwe="563">
<location
file0="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
file="that\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
line="51" />
<location
file0="apps\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
file="that\cloud_composer\src\point_selectors\rectangular_frustum_selector.cpp"
line="53" />
<symbol>that</symbol>
</error>
</results>

0 comments on commit 2b96ad7

Please sign in to comment.