@@ -4,10 +4,9 @@ import java.io.ByteArrayOutputStream
4
4
import java .nio .file .{FileSystems , Files , Path }
5
5
import java .util .jar .Attributes
6
6
import java .util .jar .Attributes .Name
7
-
8
7
import org .junit .{Assert , Test }
9
8
10
- import scala .tools .nsc .{Global , Settings }
9
+ import scala .tools .nsc .{CloseableRegistry , Global , Settings }
11
10
import scala .tools .testing .BytecodeTesting
12
11
import scala .util .Properties
13
12
@@ -22,6 +21,7 @@ class MultiReleaseJarTest extends BytecodeTesting {
22
21
// TODO test fails if both Global runs look at the same JAR on disk. Caching problem in our classpath implementation?
23
22
// val temp2 = temp1
24
23
val temp2 = Files .createTempFile(" mr-jar-test-" , " .jar" )
24
+ val cleanup = new CloseableRegistry
25
25
26
26
try {
27
27
def code (newApi : String ) = s " package p1; abstract class Versioned { def oldApi: Int; $newApi } "
@@ -39,6 +39,7 @@ class MultiReleaseJarTest extends BytecodeTesting {
39
39
settings.usejavacp.value = true
40
40
settings.classpath.value = jarPath.toAbsolutePath.toString
41
41
val g = new Global (settings)
42
+ cleanup.registerClosable(g)
42
43
settings.release.value = release
43
44
new g.Run
44
45
val decls = g.rootMirror.staticClass(" p1.Versioned" ).info.decls.filterNot(_.isConstructor).map(_.name.toString).toList.sorted
@@ -47,28 +48,38 @@ class MultiReleaseJarTest extends BytecodeTesting {
47
48
48
49
Assert .assertEquals(List (" newApi" , " oldApi" ), declsOfC(temp1, " 9" ))
49
50
Assert .assertEquals(List (" oldApi" ), declsOfC(temp2, " 8" ))
50
- } finally
51
+ } finally {
52
+ cleanup.close()
51
53
List (temp1, temp2).foreach(Files .deleteIfExists)
54
+ }
52
55
}
53
56
54
57
@ Test
55
58
def ctSymTest (): Unit = {
56
59
if (! Properties .isJavaAtLeast(" 9" )) { println(" skipping mrJar() on old JDK" ); return } // TODO test that the compiler warns that --release is unsupported.
60
+ val cleanup = new CloseableRegistry
57
61
58
62
def lookup (className : String , release : String ): Boolean = {
59
63
val settings = new Settings ()
60
64
settings.usejavacp.value = true
61
65
val g = new Global (settings)
66
+ cleanup.registerClosable(g)
62
67
import g ._
63
68
settings.release.value = release
64
69
new Run
65
70
rootMirror.getClassIfDefined(TypeName (className)) != NoSymbol
66
71
}
67
- Assert .assertTrue(lookup(" java.lang.invoke.LambdaMetafactory" , " 8" ))
68
- Assert .assertFalse(lookup(" java.lang.invoke.LambdaMetafactory" , " 7" ))
69
- Assert .assertTrue(lookup(" java.lang.invoke.LambdaMetafactory" , " 9" ))
72
+ try {
73
+ Assert .assertTrue(lookup(" java.lang.invoke.LambdaMetafactory" , " 8" ))
74
+ Assert .assertFalse(lookup(" java.lang.invoke.LambdaMetafactory" , " 7" ))
75
+ Assert .assertTrue(lookup(" java.lang.invoke.LambdaMetafactory" , " 9" ))
76
+ } finally {
77
+ cleanup.close()
78
+ }
70
79
}
71
80
81
+
82
+
72
83
private def createManifest = {
73
84
val manifest = new java.util.jar.Manifest ()
74
85
manifest.getMainAttributes.put(Name .MANIFEST_VERSION , " 1.0" )
0 commit comments