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 @@ -10,6 +10,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -163,7 +164,7 @@ private String getAnnotationSummary() {
}

private void createTotalLinesSummary(final List<FileNode> modifiedFiles, final StringBuilder summary) {
var total = modifiedFiles.stream().map(FileNode::getModifiedLines).mapToInt(Set::size).sum();
var total = countLines(modifiedFiles, FileNode::getModifiedLines);
if (total == 1) {
summary.append("- 1 line has been modified");
}
Expand All @@ -173,8 +174,12 @@ private void createTotalLinesSummary(final List<FileNode> modifiedFiles, final S
summary.append(NEW_LINE);
}

private int countLines(final List<FileNode> modifiedFiles, final Function<FileNode, Collection<?>> linesGetter) {
return modifiedFiles.stream().map(linesGetter).mapToInt(Collection::size).sum();
}

private void createLineCoverageSummary(final List<FileNode> modifiedFiles, final StringBuilder summary) {
var missed = modifiedFiles.stream().map(FileNode::getMissedLines).map(Set::size).count();
var missed = countLines(modifiedFiles, FileNode::getMissedLines);
if (missed == 0) {
summary.append("- all lines are covered");
}
Expand Down Expand Up @@ -213,7 +218,7 @@ private void createMutationCoverageSummary(final Node filteredRoot, final List<F
.flatMap(Collection::stream)
.map(Entry::getValue)
.count();
var mutations = modifiedFiles.stream().map(FileNode::getMutations).mapToLong(Collection::size).sum();
var mutations = countLines(modifiedFiles, FileNode::getMutations);
if (survived == 0) {
if (mutations == 1) {
summary.append("- 1 mutation has been killed");
Expand All @@ -222,7 +227,7 @@ private void createMutationCoverageSummary(final Node filteredRoot, final List<F
summary.append(String.format("- all %d mutations have been killed", mutations));
}
}
if (survived == 1) {
else if (survived == 1) {
summary.append(String.format("- 1 mutation survived (of %d)", mutations));
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.jenkins.plugins.coverage.metrics.steps;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -78,6 +77,35 @@ void shouldShowProjectBaselineForPit() {
assertThatTitleIs(publisher, "Line Coverage: 93.84%, Mutation Coverage: 90.24%");
}

@ParameterizedTest(name = "should create checks (scope = {0}, expected annotations = {1})")
@CsvSource({"SKIP, 0", "ALL_LINES, 18", "MODIFIED_LINES, 1"})
void shouldCreateChecksReportPit(final ChecksAnnotationScope scope, final int expectedAnnotations) {
var result = readResult("mutations.xml", new PitestParser());

var publisher = new CoverageChecksPublisher(createCoverageBuildAction(result), result, REPORT_NAME,
scope, createJenkins());

assertThat(publisher.extractChecksDetails().getOutput()).isPresent().get().satisfies(output -> {
assertSummary(output, "coverage-publisher-summary.checks-expected-result-pit");
assertMutationAnnotations(output, expectedAnnotations);
});
}

private void assertMutationAnnotations(final ChecksOutput output, final int expectedAnnotations) {
assertThat(output.getChecksAnnotations()).hasSize(expectedAnnotations);
if (expectedAnnotations == 1) {
assertThat(output.getChecksAnnotations()).satisfiesExactly(
annotation -> {
assertThat(annotation.getTitle()).contains("Mutation survived");
assertThat(annotation.getAnnotationLevel()).isEqualTo(ChecksAnnotationLevel.WARNING);
assertThat(annotation.getPath()).contains("edu/hm/hafner/coverage/parser/CoberturaParser.java");
assertThat(annotation.getMessage()).contains("One mutation survived in line 251");
assertThat(annotation.getStartLine()).isPresent().get().isEqualTo(251);
assertThat(annotation.getEndLine()).isPresent().get().isEqualTo(251);
});
}
}

private void assertThatTitleIs(final CoverageChecksPublisher publisher, final String expectedTitle) {
var checkDetails = publisher.extractChecksDetails();
assertThat(checkDetails.getOutput()).isPresent().get().satisfies(output -> {
Expand All @@ -89,7 +117,7 @@ private void assertThatTitleIs(final CoverageChecksPublisher publisher, final St

@ParameterizedTest(name = "should create checks (scope = {0}, expected annotations = {1})")
@CsvSource({"SKIP, 0", "ALL_LINES, 36", "MODIFIED_LINES, 3"})
void shouldCreateChecksReport(final ChecksAnnotationScope scope, final int expectedAnnotations) {
void shouldCreateChecksReportJaCoCo(final ChecksAnnotationScope scope, final int expectedAnnotations) {
var result = readJacocoResult("jacoco-codingstyle.xml");

var publisher = new CoverageChecksPublisher(createCoverageBuildAction(result), result, REPORT_NAME, scope, createJenkins());
Expand All @@ -113,15 +141,14 @@ private void assertThatDetailsAreCorrect(final ChecksDetails checkDetails, final
var expectedDetails = toString("coverage-publisher-details.checks-expected-result");
assertThat(output.getText()).isPresent().get().asString().isEqualToNormalizingWhitespace(expectedDetails);
assertChecksAnnotations(output, expectedAnnotations);
assertSummary(output);
assertSummary(output, "coverage-publisher-summary.checks-expected-result");
});
}

private void assertSummary(final ChecksOutput checksOutput) throws IOException {
var expectedContent = toString("coverage-publisher-summary.checks-expected-result");
private void assertSummary(final ChecksOutput checksOutput, final String fileName) {
assertThat(checksOutput.getSummary()).isPresent()
.get()
.asString().isEqualToNormalizingWhitespace(expectedContent);
.asString().isEqualToNormalizingWhitespace(toString(fileName));
}

private void assertChecksAnnotations(final ChecksOutput checksOutput, final int expectedAnnotations) {
Expand Down Expand Up @@ -179,6 +206,11 @@ private CoverageBuildAction createCoverageBuildAction(final Node result) {
assertThat(file.getPartiallyCoveredLines()).contains(entry(113, 1));
file.addModifiedLines(61, 62, 113);
});
result.findFile("CoberturaParser.java")
.ifPresent(file -> {
assertThat(file.getSurvivedMutations()).containsKey(251);
file.addModifiedLines(251);
});

return new CoverageBuildAction(run, COVERAGE_ID, REPORT_NAME, StringUtils.EMPTY, result,
new QualityGateResult(), null, "refId",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### Summary for modified lines

- 3 lines have been modified
- 1 line is not covered
- 2 lines are not covered
- 1 line is covered only partially

#### Overview by baseline
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#### Summary for modified lines
- 1 line has been modified
- all lines are covered
- 1 mutation survived (of 3)
#### Overview by baseline

* **[Overall project (difference to reference job)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#overview)**
* Line Coverage: 93.84% (198/211) - Delta: +50.00%
* Mutation Coverage: 90.24% (222/246)
* Lines of Code: 211
* **[Modified files (difference to overall project)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedFilesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
* **[Modified code lines (difference to modified files)](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#modifiedLinesCoverage)**
* Line Coverage: 50.00% (1/2) - Delta: +50.00%
* **[Indirect changes](http://127.0.0.1:8080/job/pipeline-coding-style/job/5/coverage#indirectCoverage)**
* Line Coverage: 50.00% (1/2)

#### Quality Gates Summary

No active quality gates.