Skip to content

Commit

Permalink
Check for obsolete snapshots only when all tests are green
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Aug 28, 2023
1 parent 66c2618 commit 5dde3de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/main/java/com/askimed/nf/test/core/AbstractTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public abstract class AbstractTestSuite implements ITestSuite {

private SnapshotFile snapshotFile;

private boolean failedTests = false;

private List<String> tags = new Vector<String>();

@Override
Expand Down Expand Up @@ -147,9 +149,19 @@ public SnapshotFile getSnapshot() {
}
return snapshotFile;
}

@Override
public boolean hasSnapshotLoaded() {
return (snapshotFile != null);
}

@Override
public void setFailedTests(boolean failedTests) {
this.failedTests = failedTests;
}

@Override
public boolean hasFailedTests() {
return failedTests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public void testSuiteExecutionFinished(ITestSuite testSuite) {

// if we have at least one skipped test, we can not
// determine if a snapshot is obsolete.
// TODO: add check. if at lest one test failed, same situation.
if (testSuite.hasSkippedTests()) {
if (testSuite.hasSkippedTests() || testSuite.hasFailedTests()) {
System.out.println(AnsiText.padding(
"Obsolete snapshots can only be checked if all tests of a file are executed.", 2 * TEST_PADDING));
"Obsolete snapshots can only be checked if all tests of a file are executed successful.",
2 * TEST_PADDING));
return;
}

if (snapshot.getObsoleteSnapshots().size() > 0) {
if (snapshot.getObsoleteSnapshots().size() > 0) {
System.out.println(AnsiColors.yellow(AnsiText.padding(
snapshot.getObsoleteSnapshots().size() + " obsolete " + snapshot.getObsoleteSnapshots(),
2 * TEST_PADDING)));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/askimed/nf/test/core/ITestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public interface ITestSuite extends ITaggable {

public boolean hasSkippedTests();

public void setFailedTests(boolean b);

public boolean hasFailedTests();

public SnapshotFile getSnapshot();

public boolean hasSnapshotLoaded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public int execute() throws Throwable {
result.setThrowable(e);
result.setErrorReport(test.getErrorReport());
failed = true;
testSuite.setFailedTests(true);

}
test.cleanup();
Expand All @@ -209,9 +210,9 @@ public int execute() throws Throwable {

}

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

0 comments on commit 5dde3de

Please sign in to comment.