@@ -10,6 +10,8 @@ import mill._
1010import mill .scalalib ._
1111import coursier .core .Version
1212
13+ import java .io .File
14+
1315import scala .concurrent .duration ._
1416import scala .util .Properties .isWin
1517
@@ -142,19 +144,12 @@ class ScalaJsCliNativeImage(val scalaJsVersion0: String) extends ScalaModule wit
142144 suffix = nameSuffix
143145 )
144146 }
145-
146- def testNative () = T .command {
147- val path = nativeImage().path
148- System .err.println(s " Testing ${path.relativeTo(os.pwd)}" )
149- val cwd = T .dest / " workdir"
150- os.makeDir.all(cwd)
151- os.proc(bash, os.pwd / " scripts" / " test-cli.sh" , path, scalaJsVersion)
152- .call(cwd = cwd, stdin = os.Inherit , stdout = os.Inherit )
153- }
154147}
155148
156149object native extends Cross [ScalaJsCliNativeImage ](scalaJsVersions : _* )
157150
151+ def native0 = native
152+
158153def csDockerVersion = " 2.1.0-M5-18-gfebf9838c"
159154
160155class ScalaJsCliStaticNativeImage (scalaJsVersion0 : String ) extends ScalaJsCliNativeImage (scalaJsVersion0) {
@@ -191,6 +186,67 @@ class ScalaJsCliMostlyStaticNativeImage(scalaJsVersion0: String) extends ScalaJs
191186}
192187object `native-mostly-static` extends Cross [ScalaJsCliMostlyStaticNativeImage ](scalaJsVersions : _* )
193188
189+ object tests extends Cross [Tests ](scalaJsVersions : _* )
190+ class Tests (val scalaJsVersion0 : String ) extends ScalaModule {
191+ def scalaVersion = scala213
192+
193+ object test extends Tests {
194+ def ivyDeps = super .ivyDeps() ++ Seq (
195+ ivy " org.scalameta::munit:0.7.29 " ,
196+ ivy " com.lihaoyi::os-lib:0.8.1 " ,
197+ ivy " com.lihaoyi::pprint:0.8.0 "
198+ )
199+ def testFramework = " munit.Framework"
200+
201+ private final class TestHelper (
202+ launcherTask : T [PathRef ]
203+ ) {
204+ def test (args : String * ) = {
205+ val argsTask = T .task {
206+ val launcher = launcherTask().path
207+ val extraArgs = Seq (
208+ s " -Dtest.scala-js-cli.path= $launcher" ,
209+ s " -Dtest.scala-js-cli.scala-js-version= $scalaJsVersion0"
210+ )
211+ args ++ extraArgs
212+ }
213+ T .command {
214+ testTask(argsTask, T .task(Seq .empty[String ]))()
215+ }
216+ }
217+ }
218+
219+ def test (args : String * ) =
220+ jvm(args : _* )
221+ def jvm (args : String * ) =
222+ new TestHelper (cli(scalaJsVersion0).standaloneLauncher).test(args : _* )
223+ def native (args : String * ) =
224+ new TestHelper (native0(scalaJsVersion0).nativeImage).test(args : _* )
225+ def nativeStatic (args : String * ) =
226+ new TestHelper (`native-static`(scalaJsVersion0).nativeImage).test(args : _* )
227+ def nativeMostlyStatic (args : String * ) =
228+ new TestHelper (`native-mostly-static`(scalaJsVersion0).nativeImage).test(args : _* )
229+
230+ private def updateRef (ref : PathRef ): PathRef = {
231+ val rawPath = ref.path.toString.replace(
232+ File .separator + scalaJsVersion0 + File .separator,
233+ File .separator
234+ )
235+ PathRef (os.Path (rawPath))
236+ }
237+ def sources = T .sources {
238+ super .sources().flatMap { ref =>
239+ Seq (updateRef(ref), ref)
240+ }
241+ }
242+ def resources = T .sources {
243+ super .resources().flatMap { ref =>
244+ Seq (updateRef(ref), ref)
245+ }
246+ }
247+ }
248+ }
249+
194250def ghOrg = " scala-cli"
195251def ghName = " scala-js-cli"
196252trait ScalaJsCliPublishModule extends PublishModule {
@@ -341,23 +397,6 @@ object ci extends Module {
341397
342398 Upload .upload(" scala-cli" , " scala-js-cli" , ghToken, tag, dryRun = false , overwrite = overwriteAssets)(launchers : _* )
343399 }
344-
345- def testCli () = {
346- val tasks = scalaJsVersions.map { scalaJsVer =>
347- cli(scalaJsVer).standaloneLauncher.map((scalaJsVer, _))
348- }
349- T .command {
350- val workDir = T .dest
351- val launchers = T .sequence(tasks)()
352- for ((scalaJsVer, launcher) <- launchers) {
353- System .err.println(s " Testing Scala.JS $scalaJsVer" )
354- val cwd = workDir / scalaJsVer
355- os.makeDir.all(cwd)
356- os.proc(bash, os.pwd / " scripts" / " test-cli.sh" , launcher.path, scalaJsVer)
357- .call(cwd = cwd, stdin = os.Inherit , stdout = os.Inherit )
358- }
359- }
360- }
361400}
362401
363402private def bash =
0 commit comments