Skip to content

Commit 857f06a

Browse files
committed
Add more logging for running tests with the test sub-command
1 parent 60d5362 commit 857f06a

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

modules/build/src/main/scala/scala/build/internal/Runner.scala

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scala.build.internal
33
import coursier.jvm.Execve
44
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
55
import org.scalajs.jsenv.nodejs.NodeJSEnv
6-
import org.scalajs.jsenv.{Input, RunConfig}
6+
import org.scalajs.jsenv.{Input, JSEnv, RunConfig}
77
import org.scalajs.testing.adapter.TestAdapter as ScalaJsTestAdapter
88
import sbt.testing.{Framework, Status}
99

@@ -378,14 +378,27 @@ object Runner {
378378

379379
def frameworkNames(
380380
classPath: Seq[Path],
381-
parentInspector: AsmTestRunner.ParentInspector
381+
parentInspector: AsmTestRunner.ParentInspector,
382+
logger: Logger
382383
): Either[NoTestFrameworkFoundError, Seq[String]] = {
383-
val foundFrameworkServices = AsmTestRunner.findFrameworkServices(classPath)
384+
logger.debug("Looking for test framework services on the classpath...")
385+
val foundFrameworkServices =
386+
AsmTestRunner.findFrameworkServices(classPath)
387+
.map(_.replace('/', '.').replace('\\', '.'))
388+
logger.debug(s"Found ${foundFrameworkServices.length} test framework services.")
389+
if foundFrameworkServices.nonEmpty then
390+
logger.debug(s" - ${foundFrameworkServices.mkString("\n - ")}")
391+
logger.debug("Looking for more test frameworks on the classpath...")
384392
val foundFrameworks =
385393
AsmTestRunner.findFrameworks(classPath, TestRunner.commonTestFrameworks, parentInspector)
386-
val frameworks: Seq[String] =
387-
(foundFrameworkServices ++ foundFrameworks)
388394
.map(_.replace('/', '.').replace('\\', '.'))
395+
logger.debug(s"Found ${foundFrameworks.length} additional test frameworks")
396+
if foundFrameworks.nonEmpty then
397+
logger.debug(s" - ${foundFrameworks.mkString("\n - ")}")
398+
val frameworks: Seq[String] = foundFrameworkServices ++ foundFrameworks
399+
logger.log(s"Found ${frameworks.length} test frameworks in total")
400+
if frameworks.nonEmpty then
401+
logger.debug(s" - ${frameworks.mkString("\n - ")}")
389402
if frameworks.nonEmpty then Right(frameworks) else Left(new NoTestFrameworkFoundError)
390403
}
391404

@@ -401,23 +414,30 @@ object Runner {
401414
): Either[TestError, Int] = either {
402415
import org.scalajs.jsenv.Input
403416
import org.scalajs.jsenv.nodejs.NodeJSEnv
417+
logger.debug("Preparing to run tests with Scala.js...")
418+
logger.debug(s"Scala.js tests class path: $classPath")
404419
val nodePath = findInPath("node").fold("node")(_.toString)
405-
val jsEnv =
406-
if jsDom then
420+
logger.debug(s"Node found at $nodePath")
421+
val jsEnv: JSEnv =
422+
if jsDom then {
423+
logger.log("Loading JS environment with JS DOM...")
407424
new JSDOMNodeJSEnv(
408425
JSDOMNodeJSEnv.Config()
409426
.withExecutable(nodePath)
410427
.withArgs(Nil)
411428
.withEnv(Map.empty)
412429
)
413-
else
430+
}
431+
else {
432+
logger.log("Loading JS environment with Node...")
414433
new NodeJSEnv(
415434
NodeJSEnv.Config()
416435
.withExecutable(nodePath)
417436
.withArgs(Nil)
418437
.withEnv(Map.empty)
419438
.withSourceMap(NodeJSEnv.SourceMap.Disable)
420439
)
440+
}
421441
val adapterConfig = ScalaJsTestAdapter.Config().withLogger(logger.scalaJsLogger)
422442
val inputs =
423443
Seq(if esModule then Input.ESModule(entrypoint.toPath) else Input.Script(entrypoint.toPath))
@@ -428,7 +448,7 @@ object Runner {
428448
val parentInspector = new AsmTestRunner.ParentInspector(classPath)
429449
val foundFrameworkNames: List[String] = testFrameworkOpt match {
430450
case some @ Some(_) => some.toList
431-
case None => value(frameworkNames(classPath, parentInspector)).toList
451+
case None => value(frameworkNames(classPath, parentInspector, logger)).toList
432452
}
433453

434454
val res =
@@ -470,12 +490,13 @@ object Runner {
470490
args: Seq[String],
471491
logger: Logger
472492
): Either[TestError, Int] = either {
493+
logger.debug("Preparing to run tests with Scala Native...")
473494
logger.debug(s"Native tests class path: $classPath")
474495

475496
val parentInspector = new AsmTestRunner.ParentInspector(classPath)
476497
val foundFrameworkNames: List[String] = frameworkNameOpt match {
477498
case Some(fw) => List(fw)
478-
case None => value(frameworkNames(classPath, parentInspector)).toList
499+
case None => value(frameworkNames(classPath, parentInspector, logger)).toList
479500
}
480501

481502
val config = ScalaNativeTestAdapter.Config()

modules/cli/src/main/scala/scala/cli/commands/test/Test.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ object Test extends ScalaCommand[TestOptions] {
273273
if classPath0.exists(_.contains("zio-test")) && !classPath0.exists(_.contains("zio-test-sbt"))
274274
then {
275275
val parentInspector = new AsmTestRunner.ParentInspector(classPath)
276-
Runner.frameworkNames(classPath, parentInspector) match {
276+
Runner.frameworkNames(classPath, parentInspector, logger) match {
277277
case Right(f) => f.headOption
278278
case Left(_) =>
279279
logger.message(

modules/cli/src/main/scala/scala/cli/exportCmd/MillProjectDescriptor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ final case class MillProjectDescriptor(
149149
}
150150
val parentInspector = new AsmTestRunner.ParentInspector(testClassPath)
151151
val frameworkName0 = options.testOptions.frameworkOpt.orElse {
152-
frameworkNames(testClassPath, parentInspector).toOption
152+
frameworkNames(testClassPath, parentInspector, logger).toOption
153153
.flatMap(_.headOption) // TODO: handle multiple frameworks here
154154
}
155155

modules/cli/src/main/scala/scala/cli/exportCmd/SbtProjectDescriptor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ final case class SbtProjectDescriptor(
262262

263263
val parentInspector = new AsmTestRunner.ParentInspector(testClassPath)
264264
val frameworkName0 = options.testOptions.frameworkOpt.orElse {
265-
frameworkNames(testClassPath, parentInspector).toOption
265+
frameworkNames(testClassPath, parentInspector, logger).toOption
266266
.flatMap(_.headOption) // TODO: handle multiple frameworks here
267267
}
268268

modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,10 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
936936
|}
937937
|""".stripMargin
938938
).fromRoot { root =>
939-
val r = os.proc(TestUtil.cli, "test", extraOptions, ".", platformOptions).call(cwd = root)
939+
val r =
940+
os.proc(TestUtil.cli, "test", extraOptions, ".", platformOptions, "-v", "-v").call(cwd =
941+
root
942+
)
940943
val output = r.out.trim()
941944
expect(output.nonEmpty)
942945
expectedMessages.foreach { expectedMessage =>

0 commit comments

Comments
 (0)