Skip to content

Commit

Permalink
Only compile integration tests once
Browse files Browse the repository at this point in the history
And use a different command than 'test' to run the native flavors of the
ITs, like
```text
$ ./mill -i integration.test.native
$ ./mill -i integration.test.nativeStatic
$ ./mill -i integration.test.nativeMostlyStatic
```

The JVM ITs can be run in a few equivalent ways:
```text
$ ./mill -i integration.test
$ ./mill -i integration.test.test
$ ./mill -i integration.test.jvm
```

Note that `./mill __.test` will only run JVM ITs, not native ones.
  • Loading branch information
alexarchambault committed May 4, 2022
1 parent c4ed68f commit 965edbe
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
./mill -i unitTests
./mill -i bloop-rifle._.test
- name: JVM integration tests
run: ./mill -i integration.jvm.test
run: ./mill -i integration.test.jvm

native-tests:
timeout-minutes: 120
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
if-no-files-found: error
retention-days: 2
- name: Native integration tests
run: ./mill -i integration.native-mostly-static.test
run: ./mill -i integration.test.nativeMostlyStatic
- name: Docker integration tests
run: ./mill integration.docker-slim.test
- name: Login to GitHub Container Registry
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
if-no-files-found: error
retention-days: 2
- name: Native integration tests
run: ./mill -i integration.native-static.test
run: ./mill -i integration.test.nativeStatic
- name: Docker integration tests
run: ./mill integration.docker.test
- name: Login to GitHub Container Registry
Expand Down
4 changes: 2 additions & 2 deletions INTERNALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Run unit tests with

Run integration tests with a JVM-based `scala-cli` with
```bash
./mill integration.jvm.test
./mill integration.test.jvm
```

Run integration tests with a native-image-based `scala-cli` with
```bash
./mill integration.native.test
./mill integration.test.native
```

## General workflow in most `scala-cli` commands
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ The Scala CLI sources ship with Mill launchers, so that Mill itself doesn't need
#### Run integration tests with the JVM launcher

```bash
./mill integration.jvm.test
./mill integration.test.jvm
```

Filter test suites with
```bash
./mill integration.jvm.test 'scala.cli.integration.RunTestsDefault.*'
./mill integration.jvm.test 'scala.cli.integration.RunTestsDefault.Multiple scripts'
./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.*'
./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.Multiple scripts'
```

#### Run integration tests with the native launcher

(generating the launcher can take several minutes)

```bash
./mill integration.native.test
./mill integration.test.native
```

#### Generate native packages
Expand Down
116 changes: 57 additions & 59 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ object `scala-cli-bsp` extends JavaModule with ScalaCliPublishModule {
super.javacOptions() ++ Seq("-target", "8", "-source", "8")
}
}
object integration extends Module {
object integration extends CliIntegration {
object test extends Tests
object docker extends CliIntegrationDocker {
object test extends Tests {
def sources = T.sources {
super.sources() ++ integration.jvm.sources()
super.sources() ++ integration.sources()
}
def tmpDirBase = T.persistent {
PathRef(T.dest / "working-dir")
Expand Down Expand Up @@ -127,27 +128,6 @@ object integration extends Module {
)
}
}
object jvm extends JvmIntegration {
object test extends Tests
}
object native extends NativeIntegration with Bloop.Module {
def skipBloop = true
object test extends Tests with Bloop.Module {
def skipBloop = true
}
}
object `native-static` extends NativeIntegrationStatic with Bloop.Module {
def skipBloop = true
object test extends Tests with Bloop.Module {
def skipBloop = true
}
}
object `native-mostly-static` extends NativeIntegrationMostlyStatic with Bloop.Module {
def skipBloop = true
object test extends Tests with Bloop.Module {
def skipBloop = true
}
}
}

object packager extends ScalaModule with Bloop.Module {
Expand Down Expand Up @@ -679,8 +659,6 @@ trait Cli3 extends Cli {
trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
with ScalaCliScalafixModule {
def scalaVersion = sv
def testLauncher: T[PathRef]
def cliKind: T[String]

def sv = Scala.scala213

Expand Down Expand Up @@ -726,11 +704,9 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
Deps.slf4jNop
)
def forkEnv = super.forkEnv() ++ Seq(
"SCALA_CLI" -> testLauncher().path.toString,
"SCALA_CLI_KIND" -> cliKind(),
"SCALA_CLI_TMP" -> tmpDirBase().path.toString,
"CI" -> "1",
"ACTUAL_CI" -> (if (System.getenv("CI") == null) "" else "1")
"SCALA_CLI_TMP" -> tmpDirBase().path.toString,
"CI" -> "1",
"ACTUAL_CI" -> (if (System.getenv("CI") == null) "" else "1")
)
private def updateRef(name: String, ref: PathRef): PathRef = {
val rawPath = ref.path.toString.replace(
Expand Down Expand Up @@ -790,15 +766,57 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
}
def generatedSources = super.generatedSources() ++ Seq(constantsFile())

def test(args: String*) = T.command {
val res = super.test(args: _*)()
val dotScalaInRoot = os.pwd / workspaceDirName
assert(
!os.isDir(dotScalaInRoot),
s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created"
)
res
private final class TestHelper(
launcherTask: T[PathRef],
cliKind: String
) {
def doTest(args: String*) =
T.command {
val argsTask = T.task {
val launcher = launcherTask().path
val extraArgs = Seq(
s"-Dtest.scala-cli.path=$launcher",
s"-Dtest.scala-cli.kind=$cliKind"
)
args ++ extraArgs
}
testTask(argsTask, T.task(Seq.empty[String]))
}
def test(args: String*) =
T.command {
val res = doTest(args: _*)()
val dotScalaInRoot = os.pwd / workspaceDirName
assert(
!os.isDir(dotScalaInRoot),
s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created"
)
res
}
}

def test(args: String*) =
jvm(args: _*)

def jvm(args: String*) =
new TestHelper(
cli.standaloneLauncher,
"jvm"
).test(args: _*)
def native(args: String*) =
new TestHelper(
cli.nativeImage,
"native"
).test(args: _*)
def nativeStatic(args: String*) =
new TestHelper(
cli.nativeImageStatic,
"native-static"
).test(args: _*)
def nativeMostlyStatic(args: String*) =
new TestHelper(
cli.nativeImageMostlyStatic,
"native-mostly-static"
).test(args: _*)
}
}

Expand All @@ -809,26 +827,6 @@ trait CliIntegrationDocker extends SbtModule with ScalaCliPublishModule with Has
)
}

trait NativeIntegration extends CliIntegration {
def testLauncher = cli.nativeImage()
def cliKind = "native"
}

trait NativeIntegrationStatic extends CliIntegration {
def testLauncher = cli.nativeImageStatic()
def cliKind = "native-static"
}

trait NativeIntegrationMostlyStatic extends CliIntegration {
def testLauncher = cli.nativeImageMostlyStatic()
def cliKind = "native-mostly-static"
}

trait JvmIntegration extends CliIntegration {
def testLauncher = cli.standaloneLauncher()
def cliKind = "jvm"
}

class Runner(val crossScalaVersion: String) extends ScalaCliCrossSbtModule
with ScalaCliPublishModule
with ScalaCliScalafixModule {
Expand Down Expand Up @@ -1029,7 +1027,7 @@ def defaultNativeImage() =

def nativeIntegrationTests() =
T.command {
integration.native.test.test()()
integration.test.native()()
}

def copyDefaultLauncher(directory: String = "artifacts") =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import scala.util.Properties

object TestUtil {

val cliKind = System.getenv("SCALA_CLI_KIND")
val cliKind = sys.props("test.scala-cli.kind")
val isNativeCli = cliKind.startsWith("native")
val isCI = Option(System.getenv("ACTUAL_CI")) match {
case None => System.getenv("CI") != null
case Some(value) => value.nonEmpty
}
val cliPath = System.getenv("SCALA_CLI")
val cliPath = sys.props("test.scala-cli.path")
val cli = cliCommand(cliPath)

def cliCommand(cliPath: String): Seq[String] =
Expand Down

0 comments on commit 965edbe

Please sign in to comment.