Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test example #22

Merged
merged 4 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 14 additions & 42 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,15 @@ jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Mill cache
uses: actions/cache@v2
- uses: actions/checkout@v3
with:
path: ~/.mill
key: mill-${{ hashFiles('.mill-version') }}
- name: Ivy cache
uses: actions/cache@v2
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: actions/setup-java@v3
with:
path: ~/.cache/coursier
key: ivy-${{ hashFiles('build.sc') }}
restore-keys: |
ivy-${{ hashFiles('build.sc') }}
ivy
- name: Compilation cache
uses: actions/cache@v2
with:
path: ./out
key: out
- uses: actions/setup-java@v1
with:
java-version: '8'
architecture: x64
java-version: "8"
architecture: "x64"
distribution: "temurin"
- name: Check formatting
run:
./mill --no-server --disable-ticker mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources
Expand Down Expand Up @@ -65,29 +51,15 @@ jobs:
LC_MESSAGES: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
steps:
- uses: actions/checkout@v2
- name: Mill cache
uses: actions/cache@v2
with:
path: ~/.mill
key: mill-${{ hashFiles('.mill-version') }}
- name: Ivy cache
uses: actions/cache@v2
with:
path: ~/.cache/coursier
key: ivy-${{ hashFiles('build.sc') }}
restore-keys: |
ivy-${{ hashFiles('build.sc') }}
ivy
- name: Compilation cache
uses: actions/cache@v2
- uses: actions/checkout@v3
with:
path: ./out
key: out
- uses: actions/setup-java@v1
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: actions/setup-java@v3
with:
java-version: '8'
architecture: x64
java-version: "8"
architecture: "x64"
distribution: "temurin"
- name: Publish to Maven Central
run: |
if [[ $(git tag --points-at HEAD) != '' ]]; then
Expand Down
88 changes: 68 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Here you can see a basic example using mill-crossplatform

```scala
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.3`
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import com.github.lolgab.mill.crossplatform._

trait Common extends ScalaModule {
def scalaVersion = "2.13.11"
def scalaVersion = "2.13.12"
}

trait CommonNative extends ScalaNativeModule {
def scalaNativeVersion = "0.4.14"
def scalaNativeVersion = "0.4.15"
}
trait CommonJS extends ScalaJSModule {
def scalaJSVersion = "1.13.1"
def scalaJSVersion = "1.14.0"
}

object core extends CrossPlatform {
Expand Down Expand Up @@ -81,17 +81,17 @@ to cross-compile for multiple Scala versions.

```scala
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.3`
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import com.github.lolgab.mill.crossplatform._

trait CommonNative extends ScalaNativeModule {
def scalaNativeVersion = "0.4.14"
def scalaNativeVersion = "0.4.15"
}
trait CommonJS extends ScalaJSModule {
def scalaJSVersion = "1.13.1"
def scalaJSVersion = "1.14.0"
}

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaVersions = Seq("2.13.12", "3.3.1")

object core extends Cross[CoreModule](scalaVersions)
trait CoreModule extends CrossPlatform {
Expand Down Expand Up @@ -120,13 +120,13 @@ import $ivy.`com.github.lolgab::mill-crossplatform::0.2.2`
import com.github.lolgab.mill.crossplatform._

trait CommonNative extends ScalaNativeModule {
def scalaNativeVersion = "0.4.14"
def scalaNativeVersion = "0.4.15"
}
trait CommonJS extends ScalaJSModule {
def scalaJSVersion = "1.13.1"
def scalaJSVersion = "1.14.0"
}

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaVersions = Seq("2.13.12", "3.3.1")

object core extends Cross[CoreModule](scalaVersions: _*)
class CoreModule(val crossScalaVersion: String) extends CrossPlatform {
Expand Down Expand Up @@ -157,11 +157,11 @@ Root `moduleDeps` and `compileModuleDeps` work as expected

```scala
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.3`
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import com.github.lolgab.mill.crossplatform._

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaJSVersions = Seq("1.13.1")
val scalaVersions = Seq("2.13.12", "3.3.1")
val scalaJSVersions = Seq("1.14.0")

object core extends Cross[CoreModule](scalaVersions)
trait CoreModule extends CrossPlatform {
Expand All @@ -179,8 +179,8 @@ import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.2`
import com.github.lolgab.mill.crossplatform._

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaJSVersions = Seq("1.13.1")
val scalaVersions = Seq("2.13.12", "3.3.1")
val scalaJSVersions = Seq("1.14.0")

object core extends Cross[CoreModule](scalaVersions: _*)
class CoreModule(val crossScalaVersion: String) extends CrossPlatform {
Expand All @@ -205,7 +205,7 @@ import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.2`
import com.github.lolgab.mill.crossplatform._

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaVersions = Seq("2.13.12", "3.3.1")

object core extends Cross[CoreModule](scalaVersions)
trait CoreModule extends CrossPlatform {
Expand All @@ -216,7 +216,7 @@ trait CoreModule extends CrossPlatform {

object jvm extends Shared
object js extends Shared with ScalaJSModule {
def scalaJSVersion = "1.13.1"
def scalaJSVersion = "1.14.0"
}
object native extends Shared with ScalaNativeModule {
def scalaNativeVersion = "0.4.12"
Expand All @@ -231,7 +231,7 @@ import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.2`
import com.github.lolgab.mill.crossplatform._

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaVersions = Seq("2.13.12", "3.3.1")

object core extends Cross[CoreModule](scalaVersions: _*)
class CoreModule(crossScalaVersion: String) extends CrossPlatform {
Expand All @@ -242,10 +242,58 @@ class CoreModule(crossScalaVersion: String) extends CrossPlatform {

object jvm extends Shared
object js extends Shared with ScalaJSModule {
def scalaJSVersion = "1.13.1"
def scalaJSVersion = "1.14.0"
}
object native extends Shared with ScalaNativeModule {
def scalaNativeVersion = "0.4.12"
}
}
```

### Test modules

For tests, you need to have platform specific test modules

#### With Mill 0.11

```scala
import mill._, mill.scalalib._, mill.scalajslib._, mill.scalanativelib._
import $ivy.`com.github.lolgab::mill-crossplatform::0.2.4`
import com.github.lolgab.mill.crossplatform._

trait Common extends ScalaModule {
def scalaVersion = "3.3.1"
}
trait CommonNative extends ScalaNativeModule {
def scalaNativeVersion = "0.4.15"
}
trait CommonJS extends ScalaJSModule {
def scalaJSVersion = "1.14.0"
}
trait CommonTests extends TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.scalameta::munit::1.0.0-M10"
)
}

object core extends CrossPlatform {
trait Shared extends CrossPlatformScalaModule with Common {
// common `core` settings here
trait SharedTests extends CommonTests {
// common `core` test settings here
}
}
object jvm extends Shared {
// jvm specific settings here
object test extends ScalaTests with SharedTests
}
object js extends Shared with CommonJS {
// js specific settings here
object test extends ScalaJSTests with SharedTests
}
object native extends Shared with CommonNative {
// native specific settings here
object test extends ScalaNativeTests with SharedTests
}
}
```
4 changes: 2 additions & 2 deletions itest/src/disable-platform/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mill.scalanativelib._
import com.github.lolgab.mill.crossplatform._

trait CommonJVM extends ScalaModule {
def scalaVersion = "2.13.11"
def scalaVersion = "2.13.12"
}
trait CommonJS extends CommonJVM with ScalaJSModule {
def scalaJSVersion = "1.12.0"
Expand Down Expand Up @@ -70,7 +70,7 @@ def verify(ev: Evaluator) = T.command {
.get
._2
.str
assert(result == "2.13.11", s"Wrong result: $result")
assert(result == "2.13.12", s"Wrong result: $result")
}

locally {
Expand Down
22 changes: 11 additions & 11 deletions itest/src/simple/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mill.scalajslib._
import mill.scalanativelib._
import com.github.lolgab.mill.crossplatform._

val scalaVersions = Seq("2.13.11", "3.3.0")
val scalaVersions = Seq("2.13.12", "3.3.1")

trait CommonJVM extends ScalaModule
trait CommonJS extends ScalaJSModule {
Expand All @@ -21,7 +21,7 @@ trait CommonNative extends ScalaNativeModule {

object normal extends CrossPlatform {
object jvm extends CrossPlatformScalaModule {
def scalaVersion = "3.3.0"
def scalaVersion = "3.3.1"
}
}

Expand Down Expand Up @@ -55,14 +55,14 @@ trait CrossScalaJSNative extends CrossPlatform {
def moduleDeps = Seq(core())
trait Shared extends CrossPlatformCrossScalaModule
object jvm extends Shared with CommonJVM
object js extends Cross[JS]("1.13.1")
object js extends Cross[JS]("1.14.0")
trait JS extends Shared with CrossScalaJSModule
object native extends Cross[Native]("0.4.14")
object native extends Cross[Native]("0.4.15")
trait Native extends Shared with CrossScalaNativeModule
}

def verify(ev: Evaluator) = T.command {
`no-native`("3.3.0").jvm.compile()
`no-native`("3.3.1").jvm.compile()

locally {
val result = ev.evalOrThrow()(normal.jvm.artifactName)
Expand All @@ -73,7 +73,7 @@ def verify(ev: Evaluator) = T.command {
}

locally {
val result = ev.evalOrThrow()(core("3.3.0").jvm.artifactName)
val result = ev.evalOrThrow()(core("3.3.1").jvm.artifactName)
assert(
result == "core",
s"Wrong artifactName: $result"
Expand All @@ -82,7 +82,7 @@ def verify(ev: Evaluator) = T.command {

locally {
val result = ev.evalOrThrow()(
crossScalaJSNative("3.3.0").native("0.4.14").artifactName
crossScalaJSNative("3.3.1").native("0.4.15").artifactName
)
assert(
result == "crossScalaJSNative",
Expand All @@ -92,7 +92,7 @@ def verify(ev: Evaluator) = T.command {

locally {
val result =
ev.evalOrThrow()(crossScalaJSNative("3.3.0").js("1.13.1").artifactName)
ev.evalOrThrow()(crossScalaJSNative("3.3.1").js("1.14.0").artifactName)
assert(
result == "crossScalaJSNative",
s"Wrong artifactName: $result"
Expand All @@ -101,9 +101,9 @@ def verify(ev: Evaluator) = T.command {

locally {
val result =
ev.evalOrThrow()(crossScalaJSNative("3.3.0").js("1.13.1").scalaVersion)
ev.evalOrThrow()(crossScalaJSNative("3.3.1").js("1.14.0").scalaVersion)
assert(
result == "3.3.0",
result == "3.3.1",
s"Wrong artifactName: $result"
)
}
Expand All @@ -117,7 +117,7 @@ def verify(ev: Evaluator) = T.command {
}

locally {
val path = ev.evalOrThrow()(core("3.3.0").jvm.sources).head.path / os.up
val path = ev.evalOrThrow()(core("3.3.1").jvm.sources).head.path / os.up
assert(
path.last == "core",
s"Wrong millSourcePath: $path"
Expand Down
48 changes: 48 additions & 0 deletions itest/src/with-tests/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import $file.plugins

import mill._
import mill.api.Result
import mill.eval._
import mill.main.MainModule
import mill.scalalib._
import mill.scalajslib._
import mill.scalanativelib._
import com.github.lolgab.mill.crossplatform._

trait Common extends ScalaModule {
def scalaVersion = "3.3.1"
}
trait CommonJVM extends Common
trait CommonJS extends Common with ScalaJSModule {
def scalaJSVersion = "1.14.0"
}
trait CommonNative extends Common with ScalaNativeModule {
def scalaNativeVersion = "0.4.16"
}
trait CommonTests extends TestModule.Munit {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.scalameta::munit::1.0.0-M10"
)
}
object core extends CrossPlatform {
trait Shared extends CrossPlatformScalaModule {
trait SharedTests extends CommonTests
}
object jvm extends Shared with CommonJVM {
object test extends ScalaTests with SharedTests
}
object js extends Shared with CommonJS {
object test extends ScalaJSTests with SharedTests
}
object native extends Shared with CommonNative {
object test extends ScalaNativeTests with SharedTests
}
}

def verify(ev: Evaluator) = T.command {
ev.evalOrThrow()(core.jvm.test.test())
ev.evalOrThrow()(core.js.test.test())
ev.evalOrThrow()(core.native.test.test())

()
}
Loading