Skip to content

Commit

Permalink
Add --clean-snapshot/--wipe-snapshot` flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Aug 27, 2023
1 parent 97f98d5 commit 66c2618
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class RunTestsCommand implements Callable<Integer> {
@Option(names = { "--update-snapshot",
"--updateSnapshot" }, description = "Use this flag to re-record every snapshot that fails during this test run.", required = false, showDefaultValue = Visibility.ALWAYS)
private boolean updateSnapshot = false;

@Option(names = { "--clean-snapshot", "--cleanSnapshot", "--wipe-snapshot",
"--wipeSnapshot" }, description = "Removes all obsolete snapshots.", required = false, showDefaultValue = Visibility.ALWAYS)
private boolean cleanSnapshot = false;

@Option(names = {
"--lib" }, description = "Library extension path", required = false, showDefaultValue = Visibility.ALWAYS)
private String lib = "";
Expand Down Expand Up @@ -148,6 +153,7 @@ public Integer call() throws Exception {
engine.setDebug(debug);
engine.setWorkDir(workDir);
engine.setUpdateSnapshot(updateSnapshot);
engine.setCleanSnapshot(cleanSnapshot);
engine.setLibDir(libDir);
engine.setPluginManager(manager);

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class TestExecutionEngine {

private boolean updateSnapshot = false;

private boolean cleanSnapshot = false;

private String libDir = "";

private PluginManager pluginManager = null;
Expand Down Expand Up @@ -71,6 +73,10 @@ public void setUpdateSnapshot(boolean updateSnapshot) {
this.updateSnapshot = updateSnapshot;
}

public void setCleanSnapshot(boolean cleanSnapshot) {
this.cleanSnapshot = cleanSnapshot;
}

public void setTagQuery(TagQuery tagQuery) {
this.tagQuery = tagQuery;
}
Expand Down Expand Up @@ -203,9 +209,9 @@ public int execute() throws Throwable {

}

// Remove obsolete snapshots in update mode and when no test was skipped.
//TODO: removeObsolete snapshots only when no test failed!!
if (updateSnapshot && !testSuite.hasSkippedTests() && testSuite.hasSnapshotLoaded()) {
// Remove obsolete snapshots and when no test was skipped.
// TODO: removeObsolete snapshots only when no test failed!!
if (cleanSnapshot && !testSuite.hasSkippedTests() && testSuite.hasSnapshotLoaded()) {
SnapshotFile snapshot = testSuite.getSnapshot();
snapshot.removeObsoleteSnapshots();
snapshot.save();
Expand Down

0 comments on commit 66c2618

Please sign in to comment.