Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ protected String mergePath(final String localPath) {

if (hasParent()) {
String parentPath = getParent().getPath();

if (StringUtils.isBlank(parentPath)) {
String slash = "/";
if (StringUtils.isBlank(parentPath) || parentPath.equals(slash) || localPath.startsWith(parentPath + slash)) {
// do not prepend parent path if empty or if root or if local path starts with it
// as it is the case for coverage node created from cobertura report
return localPath;
}
if (StringUtils.isBlank(localPath)) {
return parentPath;
}
return parentPath + "/" + localPath;
return parentPath + slash + localPath;
}

return localPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,43 @@ void shouldGetAllFileCoverageNodes() {
node -> assertThat(node).isInstanceOf(FileCoverageNode.class)));
}

@Test
void shouldReturnCorrectPatshInFileCoverageNodesFromCoberturaReport() {
CoverageResult result = readCoberturaResult("cobertura-lots-of-data.xml");
CoverageNode tree = new CoverageNodeConverter().convert(result);
tree.splitPackages();
assertThat(tree.getAllFileCoverageNodes())
.hasSize(19)
.extracting(FileCoverageNode::getPath)
.containsOnly("org/apache/commons/cli/AlreadySelectedException.java",
"org/apache/commons/cli/BasicParser.java",
"org/apache/commons/cli/CommandLine.java",
"org/apache/commons/cli/CommandLineParser.java",
"org/apache/commons/cli/GnuParser.java",
"org/apache/commons/cli/HelpFormatter.java",
"org/apache/commons/cli/MissingArgumentException.java",
"org/apache/commons/cli/MissingOptionException.java",
"org/apache/commons/cli/NumberUtils.java",
"org/apache/commons/cli/Option.java",
"org/apache/commons/cli/OptionBuilder.java",
"org/apache/commons/cli/OptionGroup.java",
"org/apache/commons/cli/Options.java",
"org/apache/commons/cli/ParseException.java",
"org/apache/commons/cli/Parser.java",
"org/apache/commons/cli/PatternOptionBuilder.java",
"org/apache/commons/cli/PosixParser.java",
"org/apache/commons/cli/TypeHandler.java",
"org/apache/commons/cli/UnrecognizedOptionException.java");

result = readCoberturaResult("cobertura-package-root.xml");
tree = new CoverageNodeConverter().convert(result);
tree.splitPackages();
assertThat(tree.getAllFileCoverageNodes())
.hasSize(1)
.extracting(FileCoverageNode::getPath)
.containsOnly("__init__.py");
}

@Test
void shouldProvideExistentChangeCoverage() {
CoverageNode tree = createTreeWithMockedTreeCreator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<coverage branch-rate="0.8337" branches-covered="396" branches-valid="475" complexity="0"
line-rate="0.9448" lines-covered="2514" lines-valid="2661" timestamp="1674553788337"
version="7.0.5">
<sources>
<source>
/home/user/dev/python/package
</source>
</sources>
<packages>
<package branch-rate="0.6759" complexity="0" line-rate="0.8305" name=".">
<classes>
<class branch-rate="1" complexity="0" filename="__init__.py" line-rate="1"
name="__init__.py">
<methods />
<lines>
<line hits="1" number="6" />
<line hits="1" number="8" />
<line hits="1" number="9" />
<line hits="1" number="10" />
<line hits="1" number="11" />
<line hits="1" number="13" />
<line hits="1" number="16" />
<line hits="1" number="25" />
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="41" />
<line hits="1" number="42" />
<line hits="1" number="46" />
<line hits="1" number="48" />
<line branch="true" condition-coverage="100% (2/2)" hits="1" number="49" />
<line hits="1" number="50" />
<line hits="1" number="54" />
<line hits="1" number="55" />
<line hits="1" number="56" />
<line hits="1" number="57" />
<line hits="1" number="60" />
</lines>
</class>
</classes>
</package>
</packages>
</coverage>