diff --git a/main/eval/test/src/mill/eval/TaskTests.scala b/main/eval/test/src/mill/eval/TaskTests.scala index 95d9eb6b0e7..7d424cdd82b 100644 --- a/main/eval/test/src/mill/eval/TaskTests.scala +++ b/main/eval/test/src/mill/eval/TaskTests.scala @@ -2,7 +2,7 @@ package mill.eval import utest._ import mill.T -import mill.define.{Module, Worker} +import mill.define.{Module, Task, Worker} import mill.testkit.UnitTester import mill.testkit.UnitTester.Result import mill.testkit.TestBaseModule @@ -121,6 +121,16 @@ trait TaskTests extends TestSuite { superBuildTargetOverrideWithInputCount } + def sometimesFailing(fail: Boolean): Task[String] = T.task { + if (!fail) mill.api.Result.Success("Success") + else mill.api.Result.Failure("Failure") + } + + def sometimesFailingWithException(fail: Boolean): Task[String] = T.task { + if (!fail) "Success" + else T.fail("Failure") + } + // Reproduction of issue https://github.com/com-lihaoyi/mill/issues/2958 object repro2958 extends Module { val task1 = T.task { "task1" } @@ -258,6 +268,23 @@ trait TaskTests extends TestSuite { test("duplicateTaskInResult-issue2958") - withEnv { (build, check) => check(build.repro2958.command()) ==> Right(Result("task1,task1", 3)) } + + test("sometimeFailing") { + test("success") - withEnv { (build, check) => + check(build.sometimesFailing(false)) ==> Right(Result("Success", 0)) + } + test("failure") - withEnv { (build, check) => + check(build.sometimesFailing(true)) ==> Left(mill.api.Result.Failure("Failure", None)) + } + } + test("sometimeFailingWithException") { + test("success") - withEnv { (build, check) => + check(build.sometimesFailingWithException(false)) ==> Right(Result("Success", 0)) + } + test("failure") - withEnv { (build, check) => + check(build.sometimesFailingWithException(true)) ==> Left(mill.api.Result.Failure("Failure", None)) + } + } } }