Skip to content

Commit

Permalink
Merge pull request #1179 from Bonajo/csv-quote-killingtest
Browse files Browse the repository at this point in the history
fix: quote killingTest in CSV report
  • Loading branch information
hcoles authored Mar 26, 2023
2 parents 081bddf + 4dbd349 commit 0e96a5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.Writer;

import java.util.Optional;

import org.apache.commons.text.StringEscapeUtils;
import org.pitest.mutationtest.ClassMutationResults;
import org.pitest.mutationtest.MutationResult;
import org.pitest.mutationtest.MutationResultListener;
Expand All @@ -37,7 +39,7 @@ public CSVReportListener(final Writer out) {
}

private String createKillingTestDesc(final Optional<String> killingTest) {
return killingTest.orElse("none");
return (killingTest.isPresent()) ? StringEscapeUtils.escapeCsv(killingTest.get()) : "none";
}

private String makeCsv(final Object... os) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public void shouldOutputKillingTestWhenOneFound() throws IOException {
verify(this.out).write(expected);
}

@Test
public void shouldQuoteKillingTestWhenNeeded() throws IOException {
final MutationResult mr = new MutationResult(
MutationTestResultMother.createDetails(), new MutationStatusTestPair(1,
DetectionStatus.KILLED, "foo(java.lang.String, java.lang.String)"));
this.testee.handleMutationResult(MutationTestResultMother
.createClassResults(mr));
final String expected = "file,clazz,mutator,method,42,KILLED,\"foo(java.lang.String, java.lang.String)\""
+ NEW_LINE;
verify(this.out).write(expected);
}

@Test
public void shouldOutputNoneWhenNoKillingTestFound() throws IOException {
final MutationResult mr = new MutationResult(
Expand Down

0 comments on commit 0e96a5f

Please sign in to comment.