Skip to content

Commit

Permalink
Clean up in ExpectingFailureRuleStatement - cherry-pick of #30944 to …
Browse files Browse the repository at this point in the history
…release (#31355)
  • Loading branch information
bot-gradle authored Nov 20, 2024
2 parents 69b756e + 76f03f8 commit b937017
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.gradle.integtests.fixtures

import org.gradle.test.fixtures.file.AbstractTestDirectoryProvider
import org.junit.runners.model.Statement

class ExpectingFailureRuleStatement extends Statement {
Expand All @@ -39,6 +40,9 @@ class ExpectingFailureRuleStatement extends Statement {
} catch (Throwable ex) {
System.err.println("Failed with $feature as expected:")
ex.printStackTrace()
if (next instanceof AbstractTestDirectoryProvider.TestDirectoryCleaningStatement) {
next.cleanup()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Statement apply(final Statement base, Description description) {
return new TestDirectoryCleaningStatement(base, description);
}

private class TestDirectoryCleaningStatement extends Statement {
public class TestDirectoryCleaningStatement extends Statement {
private final Statement base;
private final Description description;

Expand All @@ -95,13 +95,9 @@ private class TestDirectoryCleaningStatement extends Statement {
this.description = description;
}

@Override
public void evaluate() throws Throwable {
// implicitly don't clean up if this throws
base.evaluate();

public void cleanup() {
try {
cleanup();
AbstractTestDirectoryProvider.this.cleanup();
} catch (Exception e) {
if (suppressCleanupErrors()) {
System.err.println(cleanupErrorMessage());
Expand All @@ -112,6 +108,15 @@ public void evaluate() throws Throwable {
}
}

@Override
public void evaluate() throws Throwable {
// implicitly don't clean up if this throws exceptions
// so that we can inspect the test directory
base.evaluate();

cleanup();
}

private boolean suppressCleanupErrors() {
return suppressCleanupErrors
|| testClass().getAnnotation(LeaksFileHandles.class) != null
Expand Down

0 comments on commit b937017

Please sign in to comment.