@@ -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,60 @@ class CompilationTests extends ParallelTesting {
293294 tests.foreach(_.delete())
294295 }
295296
297+ @ Test def linkAll : Unit = {
298+
299+ // Setup and compile libraries
300+ def strawmanLibrary =
301+ compileDir(" ../collection-strawman/src/main" , defaultOptions)
302+ def linkCustomLib =
303+ compileDir(" ../tests/link/custom-lib" , defaultOptions)
304+
305+ val libraries = {
306+ strawmanLibrary +
307+ linkCustomLib
308+ }.keepOutput.checkCompile()
309+
310+
311+ def mkLinkClassPath (libPath : String ) =
312+ mkClassPath(libPath :: Jars .dottyTestDeps) ++ mkClassPath(Jars .dottyTestDeps, " -YRunClasspath" )
313+
314+ val strawmanClassPath = mkLinkClassPath(defaultOutputDir + " strawmanLibrary/main/" )
315+ val customLibClassPath = mkLinkClassPath(defaultOutputDir + " linkCustomLib/custom-lib" )
316+
317+ // Link tests
318+ val linkDir = " ../tests/link"
319+ val linkStramanDir = linkDir + " /strawman"
320+ val linkCustomLibDir = linkDir + " /on-custom-lib"
321+ def linkStrawmanTest = compileFilesInDir(linkStramanDir, basicLinkOptimise ++ strawmanClassPath)
322+ def linkCustomLibTest = compileFilesInDir(linkCustomLibDir, basicLinkOptimise ++ customLibClassPath)
323+
324+ def classFileChecks (sourceDir : String , testName : String ) = {
325+ val checkExt = " .classcheck"
326+ for (check <- new JFile (sourceDir).listFiles().filter(_.toString.endsWith(checkExt))) {
327+ val outDir = {
328+ def path (str : String ) = str.substring(linkDir.length, str.length - checkExt.length)
329+ defaultOutputDir + testName + path(check.toString) + " /"
330+ }
331+ val expectedClasses = scala.io.Source .fromFile(check).getLines().toSet
332+ val actualClasses = Files .walk(Paths .get(outDir)).iterator().asScala.collect {
333+ case f if f.toString.endsWith(" .class" ) => f.toString.substring(outDir.length, f.toString.length - " .class" .length)
334+ }.toSet
335+ assertEquals(check.toString, expectedClasses, actualClasses)
336+ }
337+ }
338+
339+ // Run all tests
340+ val tests = {
341+ linkStrawmanTest +
342+ linkCustomLibTest
343+ }.keepOutput.checkRuns()
344+
345+ classFileChecks(linkStramanDir, " linkStrawmanTest" )
346+ classFileChecks(linkCustomLibDir, " linkCustomLibTest" )
347+
348+ (libraries + tests).delete()
349+ }
350+
296351 /** Add a `z` so that they run last. TODO: Only run them selectively? */
297352 @ Test def zBytecodeIdempotency : Unit = {
298353 val opt = defaultOptions.and(" -YemitTasty" )
0 commit comments