From f1d8908bc0a2819ed1b8f8a4d34a96314b42e80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wro=C5=84ski?= Date: Thu, 3 Nov 2022 15:28:16 +0100 Subject: [PATCH] Return exit code 1 when build fails for test --- .../src/main/scala/scala/build/Builds.scala | 1 + .../main/scala/scala/cli/commands/Test.scala | 4 ++++ .../cli/integration/TestTestDefinitions.scala | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/modules/build/src/main/scala/scala/build/Builds.scala b/modules/build/src/main/scala/scala/build/Builds.scala index f62811b843..c00986e63c 100644 --- a/modules/build/src/main/scala/scala/build/Builds.scala +++ b/modules/build/src/main/scala/scala/build/Builds.scala @@ -14,6 +14,7 @@ final case class Builds( } def get(scope: Scope): Option[Build] = builds.find(_.scope == scope) + def anyFailed: Boolean = !all.forall(_.success) def all: Seq[Build] = builds ++ crossBuilds.flatten diff --git a/modules/cli/src/main/scala/scala/cli/commands/Test.scala b/modules/cli/src/main/scala/scala/cli/commands/Test.scala index af8528d860..5b457a5f8c 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/Test.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/Test.scala @@ -153,6 +153,10 @@ object Test extends ScalaCommand[TestOptions] { actionableDiagnostics = actionableDiagnostics ) .orExit(logger) + if (builds.anyFailed) { + System.err.println("Compilation failed") + sys.exit(1) + } maybeTest(builds, allowExit = true) } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala index afdd67dc40..17111b6de5 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala @@ -314,6 +314,25 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String]) } } + test("failing test return code when compiling error") { + val inputs = TestInputs( + os.rel / "MyTests.scala" -> + """//> using lib "org.scalameta::munit::0.7.29" + | + |class SomeTest extends munit.FunSuite { + | test("failig") { + | val s: String = 1 + | assert(true == true) + | } + |} + |""".stripMargin + ) + inputs.fromRoot { root => + val res = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root, check = false) + expect(res.exitCode == 1) + } + } + test("utest") { successfulUtestInputs.fromRoot { root => val output = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root).out.text()