From 2b96ad75cee880a97c87fea81d027937db267640 Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Thu, 6 Feb 2020 19:27:04 +0100 Subject: [PATCH] CPPCheckParser results version 2 #82 --- .../se/bjurr/violations/lib/CPPCheckTest.java | 41 +++++++++++++++++++ .../resources/cppcheck/results-version-2.xml | 32 +++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/test/resources/cppcheck/results-version-2.xml diff --git a/src/test/java/se/bjurr/violations/lib/CPPCheckTest.java b/src/test/java/se/bjurr/violations/lib/CPPCheckTest.java index b0e8a9d2..67584e7d 100644 --- a/src/test/java/se/bjurr/violations/lib/CPPCheckTest.java +++ b/src/test/java/se/bjurr/violations/lib/CPPCheckTest.java @@ -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; @@ -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 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."); +} } diff --git a/src/test/resources/cppcheck/results-version-2.xml b/src/test/resources/cppcheck/results-version-2.xml new file mode 100644 index 00000000..53cfea7a --- /dev/null +++ b/src/test/resources/cppcheck/results-version-2.xml @@ -0,0 +1,32 @@ + + + + + + + it + + + + + that + + \ No newline at end of file