8000 Test that we can link twice on the same linker with GCC · gzm0/scala-js@3572a4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3572a4b

Browse files
committed
Test that we can link twice on the same linker with GCC
Ensures that we catch issues like this: scala-js#4917 (comment)
1 parent 8ab1d88 commit 3572a4b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

linker/jvm/src/test/scala/org/scalajs/linker/GCCLinkerTest.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ import org.junit.Test
1616

1717
import org.scalajs.junit.async._
1818

19+
import org.scalajs.logging._
20+
1921
import org.scalajs.linker.interface.StandardConfig
2022

23+
import org.scalajs.linker.testutils.{MemClassDefIRFile, TestIRRepo}
2124
import org.scalajs.linker.testutils.LinkingUtils._
25+
import org.scalajs.linker.testutils.TestIRBuilder._
2226

2327
class GCCLinkerTest {
2428
import scala.concurrent.ExecutionContext.Implicits.global
@@ -30,4 +34,30 @@ class GCCLinkerTest {
3034
*/
3135
testLink(Nil, Nil, config = StandardConfig().withClosureCompiler(true))
3236
}
37+
38+
@Test
39+
def linkIncrementalSmoke(): AsyncResult = await {
40+
/* Check that linking twice works. GCC trees are highly mutable, so if we
41+
* (re-)use them wrongly over multiple runs, things can fail unexpectedly.
42+
*
43+
* We change something about the code in the second run to force the linker
44+
* to actually re-run.
45+
*/
46+
def classDef(text: String) =
47+
MemClassDefIRFile(mainTestClassDef(consoleLog(str(text))))
48+
49+
val moduleInitializers = MainTestModuleInitializers
50+
51+
val config = StandardConfig().withCheckIR(true).withClosureCompiler(true)
52+
val linker = StandardImpl.linker(config)
53+
54+
val output = MemOutputDirectory()
55+
val logger = new ScalaConsoleLogger(Level.Error)
56+
57+
for {
58+
lib <- TestIRRepo.minilib
59+
_ <- linker.link(lib :+ classDef("test 1"), moduleInitializers, output, logger)
60+
_ <- linker.link(lib :+ classDef("test 2"), moduleInitializers, output, logger)
61+
} yield ()
62+
}
3363
}

0 commit comments

Comments
 (0)
0