diff options
author | Nail Samatov <sanail@yandex.ru> | 2021-09-15 21:00:59 +0300 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-01-30 17:16:02 -0500 |
commit | 2b01ac3389c11be88ec875048d6a2cc4ed6903f1 (patch) | |
tree | 9891d1d9df4bb21a6646bebc79dad27caff37960 /org.eclipse.jgit.junit | |
parent | 8633ea4f07cbe10706a9edd1301f13aebe5be942 (diff) | |
download | jgit-2b01ac3389c11be88ec875048d6a2cc4ed6903f1.tar.gz jgit-2b01ac3389c11be88ec875048d6a2cc4ed6903f1.zip |
[test] Fix closing of test repositories
Fix tests failing on Windows because Repository instance is created but
not closed on tear down.
Fix repositories closed twice, except in tests that test this behavior
explicitly.
Name the temporary directories the tests run in after the test method;
that makes it easier to figure out in which tests repositories are
closed twice if it should occur again in the future.
Bug: 550111
Change-Id: I9398b58f0f36d2c29236d2a9a8599117d9083980
Signed-off-by: Nail Samatov <sanail@yandex.ru>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index 494d2f3bae..a3c5b1202d 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -45,6 +45,8 @@ import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; /** * JUnit TestCase with specialized support for temporary local repository. @@ -84,18 +86,33 @@ public abstract class LocalDiskRepositoryTestCase { private File tmp; /** + * The current test name. + */ + @Rule + public TestName currentTest = new TestName(); + + private String getTestName() { + String name = currentTest.getMethodName(); + name = name.replaceAll("[^a-zA-Z0-9]", "_"); + name = name.replaceAll("__+", "_"); + if (name.startsWith("_")) { + name = name.substring(1); + } + return name; + } + + /** * Setup test * * @throws Exception */ @Before public void setUp() throws Exception { - tmp = File.createTempFile("jgit_test_", "_tmp"); + tmp = File.createTempFile("jgit_" + getTestName() + '_', "_tmp"); CleanupThread.deleteOnShutdown(tmp); if (!tmp.delete() || !tmp.mkdir()) { throw new IOException("Cannot create " + tmp); } - mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); |