Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a cleanup mode (`ALWAYS` (default), `ON_SUCCESS`, or `NEVER`) parameter to `@TempDir` that allows to configured when the temp directory should be deleted. The default can be configured by setting a configuration parameter. Resolves #2159. Co-authored-by: Marc Philipp <mail@marcphilipp.de>
- Loading branch information
1 parent
a7bc80f
commit 3e06d8f
Showing
16 changed files
with
724 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
documentation/src/test/java/example/TempDirCleanupModeDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2015-2021 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example; | ||
|
||
import static org.junit.jupiter.api.io.CleanupMode.ON_SUCCESS; | ||
|
||
import java.nio.file.Path; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
// tag::user_guide[] | ||
class TempDirCleanupModeDemo { | ||
|
||
@Test | ||
void fileTest(@TempDir(cleanup = ON_SUCCESS) Path tempDir) { | ||
// perform test | ||
} | ||
} | ||
// end::user_guide[] |
50 changes: 50 additions & 0 deletions
50
junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/CleanupMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2015-2021 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.io; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* Enumeration of cleanup modes for a {@code TempDir}. | ||
* | ||
* <p>When a test with a temporary directory completes, it might be useful in | ||
* some cases to be able to view the contents of the directory resulting from | ||
* the test. {@code CleanupMode} allows control of how a {@code TempDir} | ||
* is cleaned up. | ||
* | ||
* @since 5.4 | ||
* @see TempDir | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.4") | ||
public enum CleanupMode { | ||
|
||
/** | ||
* Defer to the configured cleanup mode. | ||
*/ | ||
DEFAULT, | ||
|
||
/** | ||
* Always clean up a temporary directory after the test has completed. | ||
*/ | ||
ALWAYS, | ||
|
||
/** | ||
* Don't clean up a temporary directory after the test has completed. | ||
*/ | ||
NEVER, | ||
|
||
/** | ||
* Only clean up a temporary directory if the test completed successfully. | ||
*/ | ||
ON_SUCCESS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.