@@ -3,6 +3,7 @@ package tools
33package dotc
44
55import org .junit .{ Test , BeforeClass , AfterClass }
6+ import org .junit .Assert ._
67
78import java .nio .file ._
89import java .util .stream .{ Stream => JStream }
@@ -11,6 +12,7 @@ import scala.util.matching.Regex
1112import scala .concurrent .duration ._
1213
1314import vulpix .{ ParallelTesting , SummaryReport , SummaryReporting , TestConfiguration }
15+ import dotty .tools .io .JFile
1416
1517
1618class CompilationTests extends ParallelTesting {
@@ -29,7 +31,6 @@ class CompilationTests extends ParallelTesting {
2931
3032 @ Test def compilePos : Unit = {
3133 compileList(" compileStdLib" , StdLibSources .whitelisted, scala2Mode.and(" -migration" , " -Yno-inline" )) +
32- compileDir(" ../collection-strawman/src/main" , defaultOptions) +
3334 compileDir(" ../compiler/src/dotty/tools/dotc/ast" , defaultOptions) +
3435 compileDir(" ../compiler/src/dotty/tools/dotc/config" , defaultOptions) +
3536 compileDir(" ../compiler/src/dotty/tools/dotc/core" , allowDeepSubtypes) +
@@ -293,6 +294,58 @@ class CompilationTests extends ParallelTesting {
293294 tests.foreach(_.delete())
294295 }
295296
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+ classFileChecks(linkStramanDir, " linkStrawmanTest" )
344+ classFileChecks(linkCustomLibDir, " linkCustomLibTest" )
345+
346+ (libraries + tests).delete()
347+ }
348+
296349 /** Add a `z` so that they run last. TODO: Only run them selectively? */
297350 @ Test def zBytecodeIdempotency : Unit = {
298351 val opt = defaultOptions.and(" -YemitTasty" )
0 commit comments