Skip to content

Commit

Permalink
Use portable-scala-reflect instead of the deprecated TestUtils.
Browse files Browse the repository at this point in the history
`TestUtils` is deprecated in Scala.js 0.6.25. It has been replaced
by the more general portable-scala-reflect library. This commit
migrates to using the latter.

Since portable-scala-reflect does not support Scala Native yet, we
need a bit more stuff in `PlatformShims`. These won't be necessary
when Scala Native implements
scala-native/scala-native#1279 and
portable-scala-reflect starts supporting Scala Native.
  • Loading branch information
sjrd committed Sep 14, 2018
1 parent 1eb9b66 commit fe76a02
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ lazy val utest = crossProject(JSPlatform, JVMPlatform, NativePlatform)

)
.jsSettings(
libraryDependencies += "org.scala-js" %% "scalajs-test-interface" % scalaJSVersion
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-test-interface" % scalaJSVersion,
"org.portable-scala" %%% "portable-scala-reflect" % "0.1.0"
)
)
.jvmSettings(
libraryDependencies ++= Seq(
"org.scala-sbt" % "test-interface" % "1.0",
"org.scala-js" %% "scalajs-stubs" % scalaJSVersion % "provided"
"org.portable-scala" %%% "portable-scala-reflect" % "0.1.0"
),
resolvers += Resolver.sonatypeRepo("snapshots")
)
Expand Down
11 changes: 11 additions & 0 deletions utest/js/src/main/scala/utest/PlatformShims.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utest

import scala.concurrent.Future
import org.portablescala.reflect.Reflect

/**
* Platform specific stuff that differs between JVM and JS
Expand All @@ -14,4 +15,14 @@ object PlatformShims {
)
}
}

type EnableReflectiveInstantiation =
org.portablescala.reflect.annotation.EnableReflectiveInstantiation

def loadModule(name: String, loader: ClassLoader): Any = {
Reflect
.lookupLoadableModuleClass(name + "$", loader)
.getOrElse(throw new ClassNotFoundException(name))
.loadModule()
}
}
13 changes: 11 additions & 2 deletions utest/jvm/src/main/scala/utest/PlatformShims.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package utest

import scala.concurrent.{Await, Future}
import scala.util.{Failure, Success}
import concurrent.duration._
import java.io.{PrintWriter, StringWriter}
import org.portablescala.reflect.Reflect

/**
* Platform specific stuff that differs between JVM and JS
*/
object PlatformShims {
def await[T](f: Future[T]): T = Await.result(f, 10.hours)

type EnableReflectiveInstantiation =
org.portablescala.reflect.annotation.EnableReflectiveInstantiation

def loadModule(name: String, loader: ClassLoader): Any = {
Reflect
.lookupLoadableModuleClass(name + "$", loader)
.getOrElse(throw new ClassNotFoundException(name))
.loadModule()
}
}
7 changes: 7 additions & 0 deletions utest/native/src/main/scala/utest/PlatformShims.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utest
// Taken from the implementation for JS

import scala.concurrent.Future
import org.scalajs.testinterface.TestUtils

/**
* Platform specific stuff that differs between JVM and Native
Expand All @@ -16,4 +17,10 @@ object PlatformShims {
)
}
}

type EnableReflectiveInstantiation =
scala.scalajs.reflect.annotation.EnableReflectiveInstantiation

def loadModule(name: String, loader: ClassLoader): Any =
TestUtils.loadModule(name, loader)
}
3 changes: 2 additions & 1 deletion utest/shared/src/main/scala/utest/TestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import utest.framework.Formatter
import scala.concurrent.{ExecutionContext, Future}
import scala.reflect.macros.Context
import scala.language.experimental.macros
import scala.scalajs.reflect.annotation.EnableReflectiveInstantiation

import PlatformShims.EnableReflectiveInstantiation

/**
* Marker class used to mark an `object` as something containing tests. Used
Expand Down
3 changes: 1 addition & 2 deletions utest/shared/src/main/scala/utest/runner/BaseRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package runner
import sbt.testing._

import scala.util.Failure
import org.scalajs.testinterface.TestUtils
import utest.framework.{StackMarker, Tree}
object BaseRunner{
/**
Expand Down Expand Up @@ -106,7 +105,7 @@ abstract class BaseRunner(val args: Array[String],
try {
Right(
StackMarker.dropOutside(
TestUtils.loadModule(suiteName, testClassLoader).asInstanceOf[TestSuite]
PlatformShims.loadModule(suiteName, testClassLoader).asInstanceOf[TestSuite]
)
)
} catch{case e: Throwable => Left(e)}
Expand Down

0 comments on commit fe76a02

Please sign in to comment.