diff --git a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java index 854364a1..6fc71038 100644 --- a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java @@ -56,6 +56,11 @@ public class RunTestsCommand implements Callable { @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 = ""; @@ -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); diff --git a/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java b/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java index 71b8304d..ff316637 100644 --- a/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java +++ b/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java @@ -31,6 +31,8 @@ public class TestExecutionEngine { private boolean updateSnapshot = false; + private boolean cleanSnapshot = false; + private String libDir = ""; private PluginManager pluginManager = null; @@ -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; } @@ -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();