Skip to content

Commit

Permalink
Add log if someone try to run test without zio-test-sbt (#505)
Browse files Browse the repository at this point in the history
* Add log if someone try to run test without zio-test-sbt
  • Loading branch information
lwronski committed Dec 17, 2021
1 parent a9ed146 commit c1afee7
Show file tree
Hide file tree
Showing 2 changed files with 34 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
35 changes: 33 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,49 @@ object Test extends ScalaCommand[TestOptions] {
}
}
case Platform.JVM =>
val classPath = build.fullClassPath

val testFrameworkOpt0 = testFrameworkOpt.orElse {
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 ++
testFrameworkOpt0.map(fw => s"--test-framework=$fw").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 classPath0 = classPath.map(_.toString)

// https://github.com/VirtusLab/scala-cli/issues/426
if (
classPath0.exists(_.contains("zio-test")) && !classPath0.exists(_.contains("zio-test-sbt"))
) {
val parentInspector = new AsmTestRunner.ParentInspector(classPath)
Runner.frameworkName(classPath, parentInspector) match {
case Right(f) => Some(f)
case Left(_) =>
logger.message(
"zio-test found in the class path, zio-test-sbt should be added to run zio tests with Scala CLI."
)
None
}
}
else
None
}

}

0 comments on commit c1afee7

Please sign in to comment.