Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Aug 28, 2024
1 parent 28cbead commit 1a7ce13
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion main/eval/test/src/mill/eval/TaskTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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))
}
}
}

}
Expand Down

0 comments on commit 1a7ce13

Please sign in to comment.