|
| 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