diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java index 2d9579a82..d8c70ca23 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/BaseCppTest.java @@ -44,6 +44,9 @@ import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.GrammarSemanticsMessage; import org.antlr.v4.tool.LexerGrammar; import org.antlr.v4.tool.Rule; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupString; @@ -89,6 +92,17 @@ public class BaseCppTest implements RuntimeTestSupport { /** Errors found while running antlr */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + private String getPropertyPrefix() { return "antlr-" + getLanguage().toLowerCase(); } diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java index a14067ee4..923b34298 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/BaseCSharpTest.java @@ -121,6 +121,17 @@ public class BaseCSharpTest implements RuntimeTestSupport { */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + @Override public void testSetUp() throws Exception { if (CREATE_PER_TEST_DIRECTORIES) { diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/dart/BaseDartTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/dart/BaseDartTest.java index 6ce699ae9..fd4da1cfb 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/dart/BaseDartTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/dart/BaseDartTest.java @@ -26,6 +26,9 @@ import org.antlr.v4.test.runtime.*; import org.antlr.v4.test.runtime.descriptors.LexerExecDescriptors; import org.antlr.v4.test.runtime.descriptors.PerformanceDescriptors; import org.antlr.v4.tool.*; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupString; @@ -126,6 +129,17 @@ public class BaseDartTest implements RuntimeTestSupport { private static String cacheDartPackages; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + private String getPropertyPrefix() { return "antlr-dart"; } diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java index f5596db3e..0226d5023 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java @@ -41,6 +41,9 @@ import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.GrammarSemanticsMessage; import org.antlr.v4.tool.LexerGrammar; import org.antlr.v4.tool.Rule; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupString; @@ -86,6 +89,17 @@ public class BaseGoTest implements RuntimeTestSupport { /** Errors found while running antlr */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + /** * Copies all files from go runtime to a temporary folder that is inside a valid GOPATH project structure. */ diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java index 765ab9e9f..d142d1df3 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/BaseJavaTest.java @@ -42,6 +42,9 @@ import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.GrammarSemanticsMessage; import org.antlr.v4.tool.LexerGrammar; import org.antlr.v4.tool.Rule; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupString; @@ -170,6 +173,17 @@ public class BaseJavaTest implements RuntimeTestSupport { */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + @Override public void testSetUp() throws Exception { // STGroup.verbose = true; diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/BaseNodeTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/BaseNodeTest.java index bfe98a21c..65fb05aba 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/BaseNodeTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/BaseNodeTest.java @@ -15,6 +15,9 @@ import org.antlr.v4.semantics.SemanticPipeline; import org.antlr.v4.test.runtime.*; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LexerGrammar; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import java.io.File; @@ -46,6 +49,17 @@ public class BaseNodeTest implements RuntimeTestSupport { /** Errors found while running antlr */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + @Override public void testSetUp() throws Exception { // new output dir for each test diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/php/BasePHPTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/php/BasePHPTest.java index f164ffec8..89d9d081f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/php/BasePHPTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/php/BasePHPTest.java @@ -30,6 +30,9 @@ import org.antlr.v4.test.runtime.RuntimeTestSupport; import org.antlr.v4.test.runtime.StreamVacuum; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LexerGrammar; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString; @@ -53,6 +56,17 @@ public class BasePHPTest implements RuntimeTestSupport { */ protected StringBuilder antlrToolErrors; + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + private String getPropertyPrefix() { return "antlr-php"; } diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java index 7f2158975..2efd08a64 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/swift/BaseSwiftTest.java @@ -11,6 +11,9 @@ import org.antlr.v4.test.runtime.ErrorQueue; import org.antlr.v4.test.runtime.RuntimeTestDescriptor; import org.antlr.v4.test.runtime.RuntimeTestSupport; import org.antlr.v4.test.runtime.StreamVacuum; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.stringtemplate.v4.ST; import java.io.BufferedReader; @@ -96,6 +99,17 @@ public class BaseSwiftTest implements RuntimeTestSupport { */ private final Set sourceFiles = new HashSet<>(); + @org.junit.Rule + public final TestRule testWatcher = new TestWatcher() { + + @Override + protected void succeeded(Description description) { + // remove tmpdir if no error. + eraseTempDir(); + } + + }; + @Override public void testSetUp() throws Exception { // new output dir for each test