Skip to content

Commit

Permalink
Add log if someone try to run test without zio-test-sbt
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Dec 16, 2021
1 parent 8d8248c commit 5aa6b4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ object Runner {
}
}

private def frameworkName(
def frameworkName(
classPath: Seq[Path],
parentInspector: AsmTestRunner.ParentInspector
): Either[NoTestFrameworkFoundError, String] = {
Expand Down
33 changes: 31 additions & 2 deletions modules/cli/src/main/scala/scala/cli/commands/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package scala.cli.commands

import caseapp._

import java.nio.file.Path

import scala.build.EitherCps.{either, value}
import scala.build.Ops._
import scala.build.errors.{BuildException, CompositeBuildException}
import scala.build.internal.{Constants, Runner}
import scala.build.options.{Platform, Scope}
import scala.build.testrunner.AsmTestRunner
import scala.build.{Build, Builds, CrossKey, Logger}
import scala.cli.CurrentParams

Expand Down Expand Up @@ -162,21 +165,47 @@ object Test extends ScalaCommand[TestOptions] {
}
}
case Platform.JVM =>
val classPath = build.fullClassPath

val frameworkOpt = testFrameworkOpt match {
case Some(fw) => Some(fw)
case None => findTestFramework(classPath, logger)
}

val extraArgs =
(if (requireTests) Seq("--require-tests") else Nil) ++
build.options.internal.verbosity.map(v => s"--verbosity=$v") ++
testFrameworkOpt.map(fw => s"--test-framework=$fw").toSeq ++
frameworkOpt.map(f => s"--test-framework=$f").toSeq ++
Seq("--") ++ args

Runner.runJvm(
build.options.javaHome().value.javaCommand,
build.options.javaOptions.javaOpts.map(_.value),
build.fullClassPath.map(_.toFile),
classPath.map(_.toFile),
Constants.testRunnerMainClass,
extraArgs,
logger,
allowExecve = allowExecve
)
}
}

def findTestFramework(classPath: Seq[Path], logger: Logger): Option[String] = {
val parentInspector = new AsmTestRunner.ParentInspector(classPath)
val classPath0 = classPath.map(_.toString)

// https://github.com/VirtusLab/scala-cli/issues/426
if (classPath0.exists(_.contains("zio-test")) && !classPath0.exists(_.contains("zio-test-sbt")))
Runner.frameworkName(classPath, parentInspector) match {
case Right(f) => Some(f)
case Left(_) =>
logger.message(
"ScalaCLI detects that you use zio-test, please import zio-test-sbt to run zio tests using scala-cli."
)
None
}
else
None
}

}

0 comments on commit 5aa6b4b

Please sign in to comment.