Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log if someone try to run test without zio-test-sbt #505

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

}