Skip to content

Commit

Permalink
replace testFrameworksJvmClasspath and testClasspathJvm with just run…
Browse files Browse the repository at this point in the history
…Classpath (#627)
  • Loading branch information
lihaoyi authored Jun 8, 2019
1 parent 26a18d8 commit 102ddfd
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions scalanativelib/src/ScalaNativeModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule { testOute
// The test frameworks run under the JVM and communicate with the native binary over a socket
// therefore the test framework is loaded from a JVM classloader
val testClassloader =
new URLClassLoader(testClasspathJvm().map(_.path.toIO.toURI.toURL).toArray,
new URLClassLoader(runClasspath().map(_.path.toIO.toURI.toURL).toArray,
this.getClass.getClassLoader)
val frameworkInstances = TestRunner.frameworks(testFrameworks())(testClassloader)
val testBinary = testRunnerNative.nativeLink().toIO
Expand All @@ -186,33 +186,14 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule { testOute

val (doneMsg, results) = TestRunner.runTests(
nativeFrameworks,
testClasspathJvm().map(_.path),
runClasspath().map(_.path),
Agg(compile().classes.path),
args
)

TestModule.handleResults(doneMsg, results)
}

private val supportedTestFrameworks = Set("utest", "scalatest")

// get the JVM classpath entries for supported test frameworks
def testFrameworksJvmClasspath = T{
Lib.resolveDependencies(
repositories,
Lib.depToDependency(_, scalaVersion(), ""),
transitiveIvyDeps().filter(d => d.cross.isBinary && supportedTestFrameworks(d.dep.module.name.value)),
ctx = Some(implicitly[mill.util.Ctx.Log])
)
}

def testClasspathJvm = T{
localClasspath() ++
transitiveLocalClasspath() ++
unmanagedClasspath() ++
testFrameworksJvmClasspath()
}

// creates a specific binary used for running tests - has a different (generated) main class
// which knows the names of all the tests and references to invoke them
object testRunnerNative extends ScalaNativeModule {
Expand Down Expand Up @@ -243,7 +224,7 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule { testOute
val frameworkInstances = TestRunner.frameworks(testFrameworks()) _

val testClasses =
Jvm.inprocess(testClasspathJvm().map(_.path), classLoaderOverrideSbtTesting = true, isolated = true, closeContextClassLoaderWhenDone = true,
Jvm.inprocess(runClasspath().map(_.path), classLoaderOverrideSbtTesting = true, isolated = true, closeContextClassLoaderWhenDone = true,
cl => {
frameworkInstances(cl).flatMap { framework =>
val df = Lib.discoverTests(cl, framework, Agg(compile().classes.path))
Expand Down

0 comments on commit 102ddfd

Please sign in to comment.