Skip to content

Commit

Permalink
Return exit code 1 when build fails for test
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Nov 3, 2022
1 parent 5793497 commit 9c12ca1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/build/src/main/scala/scala/build/Builds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final case class Builds(
}
def get(scope: Scope): Option[Build] =
builds.find(_.scope == scope)
def isFail: Boolean = !builds.forall(_.success)

def all: Seq[Build] =
builds ++ crossBuilds.flatten
Expand Down
4 changes: 4 additions & 0 deletions modules/cli/src/main/scala/scala/cli/commands/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ object Test extends ScalaCommand[TestOptions] {
actionableDiagnostics = actionableDiagnostics
)
.orExit(logger)
if (builds.isFail) {
System.err.println("Compilation failed")
sys.exit(1)
}
maybeTest(builds, allowExit = true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9c12ca1

Please sign in to comment.