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 1 commit
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
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 testFrameworkOpt0 = testFrameworkOpt match {
case Some(fw) => Some(fw)
case None => findTestFramework(classPath, logger)
}
lwronski marked this conversation as resolved.
Show resolved Hide resolved

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(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)
lwronski marked this conversation as resolved.
Show resolved Hide resolved
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."
lwronski marked this conversation as resolved.
Show resolved Hide resolved
)
None
}
else
None
}

}