Skip to content

Commit 677a221

Browse files
committed
Extract -Xlink-optimise tests from vulpix
1 parent 6abb679 commit 677a221

File tree

2 files changed

+87
-54
lines changed

2 files changed

+87
-54
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -294,60 +294,6 @@ class CompilationTests extends ParallelTesting {
294294
tests.foreach(_.delete())
295295
}
296296

297-
@Test def linkAll: Unit = {
298-
// Setup and compile libraries
299-
def strawmanLibrary =
300-
compileDir("../collection-strawman/src/main", defaultOptions)
301-
def linkCustomLib =
302-
compileDir("../tests/link/custom-lib", defaultOptions)
303-
304-
val libraries = {
305-
strawmanLibrary +
306-
linkCustomLib
307-
}.keepOutput.checkCompile()
308-
309-
// Setup class paths
310-
def mkLinkClassPath(libPath: String) =
311-
mkClassPath(libPath :: Jars.dottyTestDeps) ++ mkClassPath(Jars.dottyTestDeps, "-YRunClasspath")
312-
val strawmanClassPath = mkLinkClassPath(defaultOutputDir + "strawmanLibrary/main/")
313-
val customLibClassPath = mkLinkClassPath(defaultOutputDir + "linkCustomLib/custom-lib")
314-
315-
// Link tests
316-
val linkDir = "../tests/link"
317-
val linkStramanDir = linkDir + "/strawman"
318-
val linkCustomLibDir = linkDir + "/on-custom-lib"
319-
def linkStrawmanTest = compileFilesInDir(linkStramanDir, basicLinkOptimise ++ strawmanClassPath)
320-
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, basicLinkOptimise ++ customLibClassPath)
321-
322-
def classFileChecks(sourceDir: String, testName: String) = {
323-
val checkExt = ".classcheck"
324-
for (check <- new JFile(sourceDir).listFiles().filter(_.toString.endsWith(checkExt))) {
325-
val outDir = {
326-
def path(str: String) = str.substring(linkDir.length, str.length - checkExt.length)
327-
defaultOutputDir + testName + path(check.toString) + "/"
328-
}
329-
val expectedClasses = scala.io.Source.fromFile(check).getLines().toSet
330-
val actualClasses = Files.walk(Paths.get(outDir)).iterator().asScala.collect {
331-
case f if f.toString.endsWith(".class") => f.toString.substring(outDir.length, f.toString.length - ".class".length)
332-
}.toSet
333-
assertEquals(check.toString, expectedClasses, actualClasses)
334-
}
335-
}
336-
337-
// Run all tests
338-
val tests = {
339-
linkStrawmanTest +
340-
linkCustomLibTest
341-
}.keepOutput.checkRuns()
342-
343-
try {
344-
classFileChecks(linkStramanDir, "linkStrawmanTest")
345-
classFileChecks(linkCustomLibDir, "linkCustomLibTest")
346-
} finally {
347-
(libraries + tests).delete()
348-
}
349-
}
350-
351297
private val (compilerSources, backendSources, backendJvmSources) = {
352298
val compilerDir = Paths.get("../compiler/src")
353299
val compilerSources0 = sources(Files.walk(compilerDir))
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package dotty
2+
package tools
3+
package dotc
4+
5+
import java.io.{File => JFile}
6+
import java.nio.file.{Files, Path, Paths}
7+
8+
import org.junit.{AfterClass, Test}
9+
import org.junit.Assert._
10+
import vulpix.{ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration}
11+
12+
import scala.concurrent.duration._
13+
import scala.collection.JavaConverters._
14+
15+
class LinkOptimiseTests extends ParallelTesting {
16+
import TestConfiguration._
17+
import LinkOptimiseTests._
18+
19+
// Test suite configuration --------------------------------------------------
20+
21+
def maxDuration = 30.seconds
22+
def numberOfSlaves = 5
23+
def safeMode = Properties.testsSafeMode
24+
def isInteractive = SummaryReport.isInteractive
25+
def testFilter = Properties.testsFilter
26+
27+
28+
@Test def linkOptimise: Unit = {
29+
// Setup and compile libraries
30+
def strawmanLibrary =
31+
compileDir("../collection-strawman/src/main", defaultOptions)
32+
def linkCustomLib =
33+
compileDir("../tests/link/custom-lib", defaultOptions)
34+
35+
val libraries = {
36+
strawmanLibrary +
37+
linkCustomLib
38+
}.keepOutput.checkCompile()
39+
40+
// Setup class paths
41+
def mkLinkClassPath(libPath: String) =
42+
mkClassPath(libPath :: Jars.dottyTestDeps) ++ mkClassPath(Jars.dottyTestDeps, "-YRunClasspath")
43+
val strawmanClassPath = mkLinkClassPath(defaultOutputDir + "strawmanLibrary/main/")
44+
val customLibClassPath = mkLinkClassPath(defaultOutputDir + "linkCustomLib/custom-lib")
45+
46+
// Link tests
47+
val linkDir = "../tests/link"
48+
val linkStramanDir = linkDir + "/strawman"
49+
val linkCustomLibDir = linkDir + "/on-custom-lib"
50+
def linkStrawmanTest = compileFilesInDir(linkStramanDir, basicLinkOptimise ++ strawmanClassPath)
51+
def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, basicLinkOptimise ++ customLibClassPath)
52+
53+
def classFileChecks(sourceDir: String, testName: String) = {
54+
val checkExt = ".classcheck"
55+
for (check <- new JFile(sourceDir).listFiles().filter(_.toString.endsWith(checkExt))) {
56+
val outDir = {
57+
def path(str: String) = str.substring(linkDir.length, str.length - checkExt.length)
58+
defaultOutputDir + testName + path(check.toString) + "/"
59+
}
60+
val expectedClasses = scala.io.Source.fromFile(check).getLines().toSet
61+
val actualClasses = Files.walk(Paths.get(outDir)).iterator().asScala.collect {
62+
case f if f.toString.endsWith(".class") => f.toString.substring(outDir.length, f.toString.length - ".class".length)
63+
}.toSet
64+
assertEquals(check.toString, expectedClasses, actualClasses)
65+
}
66+
}
67+
68+
// Run all tests
69+
val tests = {
70+
linkStrawmanTest +
71+
linkCustomLibTest
72+
}.keepOutput.checkRuns()
73+
74+
try {
75+
classFileChecks(linkStramanDir, "linkStrawmanTest")
76+
classFileChecks(linkCustomLibDir, "linkCustomLibTest")
77+
} finally {
78+
(libraries + tests).delete()
79+
}
80+
}
81+
82+
}
83+
84+
object LinkOptimiseTests {
85+
implicit val summaryReport: SummaryReporting = new SummaryReport
86+
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
87+
}

0 commit comments

Comments
 (0)