Skip to content

Commit

Permalink
Add support for Scala Native - Scala 3 (#259)
Browse files Browse the repository at this point in the history
* Add support for Scala Native - Scala 3

* Use Scala 3.0 version on JVM and JS

* Avoid running workflow twice on PRs

* Fix TestUtil.isDotty for Scala 3
  • Loading branch information
lolgab authored Jan 23, 2022
1 parent 71ffa5e commit 28119e6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: ci

on:
push:
branches:
- master
tags:
- '*'
pull_request:
branches:
- master
Expand Down
23 changes: 10 additions & 13 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import mill._, scalalib._, scalajslib._, scalanativelib._, publish._
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.9:0.1.1`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.4`
import de.tobiasroeser.mill.vcs.version.VcsVersion
import $ivy.`com.github.lolgab::mill-mima_mill0.9:0.0.4`
import $ivy.`com.github.lolgab::mill-mima::0.0.9`
import com.github.lolgab.mill.mima._

val dottyVersions = sys.props.get("dottyVersion").toList

val scalaVersions = "2.11.12" :: "2.12.13" :: "2.13.4" :: "3.0.0" :: dottyVersions
val scala2Versions = scalaVersions.filter(_.startsWith("2."))
val scala2VersionsAndDotty = "2.11.12" :: "2.12.13" :: "2.13.4" :: dottyVersions
val scala30 = "3.0.0"

val scalaJSVersions = for {
scalaV <- scalaVersions
scalaV <- scala30 :: scala2VersionsAndDotty
scalaJSV <- Seq("0.6.33", "1.5.1")
if scalaV.startsWith("2.") || scalaJSV.startsWith("1.")
} yield (scalaV, scalaJSV)

val scalaNativeVersions = for {
scalaV <- scala2Versions
scalaNativeV <- Seq("0.4.0")
scalaV <- "3.1.1" :: scala2VersionsAndDotty
scalaNativeV <- Seq("0.4.3")
} yield (scalaV, scalaNativeV)

trait UtestModule extends PublishModule with Mima {
Expand All @@ -32,10 +32,7 @@ trait UtestModule extends PublishModule with Mima {
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/utest",
licenses = Seq(License.MIT),
scm = SCM(
"git://github.com/lihaoyi/utest.git",
"scm:git://github.com/lihaoyi/utest.git"
),
versionControl = VersionControl.github(owner = "com-lihaoyi", repo = "utest"),
developers = Seq(
Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi")
)
Expand Down Expand Up @@ -67,7 +64,7 @@ abstract class UtestMainModule(crossScalaVersion: String) extends CrossScalaModu

trait UtestTestModule extends ScalaModule with TestModule {
def crossScalaVersion: String
def testFrameworks = Seq("test.utest.CustomFramework")
def testFramework = "test.utest.CustomFramework"
def offset: os.RelPath = os.rel
def millSourcePath = super.millSourcePath / os.up

Expand All @@ -85,7 +82,7 @@ trait UtestTestModule extends ScalaModule with TestModule {
}

object utest extends Module {
object jvm extends Cross[JvmUtestModule](scalaVersions: _*)
object jvm extends Cross[JvmUtestModule](scala30 :: scala2VersionsAndDotty: _*)
class JvmUtestModule(val crossScalaVersion: String)
extends UtestMainModule(crossScalaVersion) with ScalaModule with UtestModule {
def ivyDeps = Agg(
Expand Down
11 changes: 6 additions & 5 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.9.8
DEFAULT_MILL_VERSION=0.10.0

set -e

if [ -z "$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then
elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=$DEFAULT_MILL_VERSION
Expand All @@ -28,13 +28,14 @@ version_remainder="$MILL_VERSION"
MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"

if [ ! -x "$MILL_EXEC_PATH" ] ; then
mkdir -p $MILL_DOWNLOAD_PATH
if [ ! -s "$MILL_EXEC_PATH" ] ; then
mkdir -p "$MILL_DOWNLOAD_PATH"
if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION${ASSEMBLY}"
MILL_VERSION_TAG=$(echo $MILL_VERSION | sed 's/\([^-]+\)\(-M[0-9]+\)?\(-.*\)?/\1\2/')
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
Expand Down
7 changes: 7 additions & 0 deletions utest/native/test/src-3/test/utest/TestUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utest

object TestUtil {

lazy val isDotty = true

}
6 changes: 4 additions & 2 deletions utest/src/utest/runner/BaseRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object BaseRunner{
}

abstract class BaseRunner(val args: Array[String],
val remoteArgs: Array[String],
_remoteArgs: Array[String],
testClassLoader: ClassLoader,
useSbtLoggers: Boolean,
formatter: utest.framework.Formatter,
Expand All @@ -48,6 +48,8 @@ abstract class BaseRunner(val args: Array[String],
formatter: utest.framework.Formatter) =
this(args, remoteArgs, testClassLoader, useSbtLoggers, formatter, None)

def remoteArgs(): Array[String] = _remoteArgs

lazy val path = args.headOption.filter(_(0) != '-')
lazy val query = path
.map(TestQueryParser(_))
Expand Down Expand Up @@ -186,6 +188,6 @@ abstract class BaseRunner(val args: Array[String],
makeTask(deserializer(task))

def serializeTask(task: sbt.testing.Task, serializer: TaskDef => String): String =
serializer(task.taskDef)
serializer(task.taskDef())

}
6 changes: 3 additions & 3 deletions utest/src/utest/runner/Fingerprint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sbt.testing.SubclassFingerprint


object Fingerprint extends SubclassFingerprint {
def superclassName = "utest.TestSuite"
def isModule = true
def requireNoArgConstructor = true
def superclassName() = "utest.TestSuite"
def isModule() = true
def requireNoArgConstructor() = true
}
4 changes: 2 additions & 2 deletions utest/src/utest/runner/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import scala.concurrent.{Await, Future}
import concurrent.duration._
import utest.framework.{ExecutionContext, Tree}

class Task(val taskDef: TaskDef,
class Task(_taskDef: TaskDef,
runUTestTask: (Seq[Logger], EventHandler) => Future[Unit])
extends sbt.testing.Task{


def taskDef(): TaskDef = _taskDef

def tags(): Array[String] = Array()

Expand Down

0 comments on commit 28119e6

Please sign in to comment.