Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix misleading path logging of history files #1343

Merged
merged 1 commit into from
Aug 27, 2024
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 @@ -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
Loading