Skip to content

Commit

Permalink
Merge pull request #1343 from hcoles/bug/confusing_history_logging
Browse files Browse the repository at this point in the history
fix misleading path logging of history files
  • Loading branch information
hcoles authored Aug 27, 2024
2 parents 4ba2c54 + b756826 commit 4847e40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,23 @@ private void checkForObsoleteOptions(AbstractPitMojo mojo) {
}

private void determineHistory(final ReportOptions data) {

// set explicit history files if configured
data.setHistoryInputLocation(this.mojo.getHistoryInputFile());
data.setHistoryOutputLocation(this.mojo.getHistoryOutputFile());

// If withHistory option set, overwrite config with files in temp dir.
// This allows a user to configure files for use on ci, but still easily use temp files
// for local running
if (this.mojo.useHistory()) {
useHistoryFileInTempDir(data);
} else {
data.setHistoryInputLocation(this.mojo.getHistoryInputFile());
}

if (data.getHistoryInputLocation() != null) {
log.info("Will read history at " + data.getHistoryInputLocation());
data.setHistoryOutputLocation(this.mojo.getHistoryOutputFile());
}

if (data.getHistoryOutputLocation() != null) {
log.info("Will write history at " + data.getHistoryOutputLocation());
}
}
Expand All @@ -302,15 +313,16 @@ private void useHistoryFileInTempDir(final ReportOptions data) {
+ project.getArtifactId() + "."
+ project.getVersion() + "_pitest_history.bin";
File historyFile = new File(tempDir, name);
log.info("Will read and write history at " + historyFile);
if (this.mojo.getHistoryInputFile() == null) {
data.setHistoryInputLocation(historyFile);
}
if (this.mojo.getHistoryOutputFile() == null) {
data.setHistoryOutputLocation(historyFile);

if (mojo.getHistoryInputFile() != null || mojo.getHistoryOutputFile() != null) {
log.info("Using withHistory option. This overrides the explicitly set history file paths.");
}
data.setHistoryInputLocation(historyFile);
data.setHistoryOutputLocation(historyFile);

}



private ReportOptions updateFromSurefire(ReportOptions option) {
Collection<Plugin> plugins = lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin");
if (!this.mojo.isParseSurefireConfig()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ public void testParsesLocalHistoryFlag() {
when(this.project.getVersion()).thenReturn("0.1-SNAPSHOT");
final ReportOptions actual = parseConfig("<withHistory>true</withHistory>");
String expected = "com.example.foo.0.1-SNAPSHOT_pitest_history.bin";
assertThat(actual.getHistoryInputLocation()).isNotNull();
assertThat(actual.getHistoryInputLocation().getAbsolutePath()).endsWith(expected);
}

public void testOverridesExplicitPathsWhenWithHistoryFlagSet() {
when(this.project.getGroupId()).thenReturn("com.example");
when(this.project.getArtifactId()).thenReturn("foo");
when(this.project.getVersion()).thenReturn("0.1-SNAPSHOT");
final ReportOptions actual = parseConfig("<historyInputFile>foo.bin</historyInputFile><withHistory>true</withHistory>");
String expected = "com.example.foo.0.1-SNAPSHOT_pitest_history.bin";
assertThat(actual.getHistoryInputLocation()).isNotNull();
assertThat(actual.getHistoryInputLocation().getAbsolutePath()).endsWith(expected);
}

Expand Down

0 comments on commit 4847e40

Please sign in to comment.