summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-18 16:42:37 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-18 16:42:37 -0800
commite9a7bcf8b8009db9a2a2ecf6f1d4b7f655a23f04 (patch)
tree0cae99f4babf16221b9d997dcfcda3f768764996 /core
parenta56cc38ff068fa2efd5df066dd3a8143f7f76fea (diff)
downloadmill-e9a7bcf8b8009db9a2a2ecf6f1d4b7f655a23f04.tar.gz
mill-e9a7bcf8b8009db9a2a2ecf6f1d4b7f655a23f04.tar.bz2
mill-e9a7bcf8b8009db9a2a2ecf6f1d4b7f655a23f04.zip
Add some basic tests for failure/exception handling during evaluation...
Diffstat (limited to 'core')
-rw-r--r--core/src/test/scala/mill/eval/FailureTests.scala87
-rw-r--r--core/src/test/scala/mill/util/TestUtil.scala9
2 files changed, 94 insertions, 2 deletions
diff --git a/core/src/test/scala/mill/eval/FailureTests.scala b/core/src/test/scala/mill/eval/FailureTests.scala
new file mode 100644
index 00000000..682f5e16
--- /dev/null
+++ b/core/src/test/scala/mill/eval/FailureTests.scala
@@ -0,0 +1,87 @@
+package mill.eval
+
+import mill.discover.Discovered
+import mill.util.OSet
+import utest._
+import utest.framework.TestPath
+
+object FailureTests extends TestSuite{
+
+ val tests = Tests{
+ val graphs = new mill.util.TestGraphs()
+ import graphs._
+ 'evaluateSingle - {
+ val workspace = ammonite.ops.pwd / 'target / 'workspace / 'failure / implicitly[TestPath].value
+ ammonite.ops.rm(ammonite.ops.Path(workspace, ammonite.ops.pwd))
+
+ val evaluator = new Evaluator(workspace, Discovered.mapping(singleton), _ => ())
+
+ val res1 = evaluator.evaluate(OSet(singleton.single))
+ assert(
+ res1.failing.keyCount == 0,
+ res1.rawValues == Seq(Result.Success(0))
+ )
+ singleton.single.failure = Some("lols")
+
+ val res2 = evaluator.evaluate(OSet(singleton.single))
+ assert(
+ res2.failing.keyCount == 1,
+ res2.rawValues == Seq(Result.Failure("lols"))
+ )
+
+ singleton.single.failure = None
+
+ val res3 = evaluator.evaluate(OSet(singleton.single))
+ assert(
+ res3.failing.keyCount == 0,
+ res3.rawValues == Seq(Result.Success(0))
+ )
+
+ val ex = new IndexOutOfBoundsException()
+ singleton.single.exception = Some(ex)
+
+ val res4 = evaluator.evaluate(OSet(singleton.single))
+ assert(
+ res4.failing.keyCount == 1,
+ res4.rawValues == Seq(Result.Exception(ex))
+ )
+ }
+ 'evaluatePair - {
+ val workspace = ammonite.ops.pwd / 'target / 'workspace / 'failure / implicitly[TestPath].value
+ ammonite.ops.rm(ammonite.ops.Path(workspace, ammonite.ops.pwd))
+
+ val evaluator = new Evaluator(workspace, Discovered.mapping(pair), _ => ())
+
+ val res1 = evaluator.evaluate(OSet(pair.down))
+ assert(
+ res1.failing.keyCount == 0,
+ res1.rawValues == Seq(Result.Success(0))
+ )
+
+ pair.up.failure = Some("lols")
+
+ val res2 = evaluator.evaluate(OSet(pair.down))
+ assert(
+ res2.failing.keyCount == 1,
+ res2.rawValues == Seq(Result.Skipped)
+ )
+
+ pair.up.failure = None
+
+ val res3 = evaluator.evaluate(OSet(pair.down))
+ assert(
+ res3.failing.keyCount == 0,
+ res1.rawValues == Seq(Result.Success(0))
+ )
+
+ pair.up.exception = Some(new IndexOutOfBoundsException())
+
+ val res4 = evaluator.evaluate(OSet(pair.down))
+ assert(
+ res4.failing.keyCount == 1,
+ res4.rawValues == Seq(Result.Skipped)
+ )
+ }
+ }
+}
+
diff --git a/core/src/test/scala/mill/util/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala
index 23603238..be6bb8e9 100644
--- a/core/src/test/scala/mill/util/TestUtil.scala
+++ b/core/src/test/scala/mill/util/TestUtil.scala
@@ -1,6 +1,7 @@
package mill.util
import mill.define.{Target, Task}
+import mill.eval.Result
import utest.assert
import scala.collection.mutable
@@ -18,11 +19,15 @@ object TestUtil {
class Test(override val inputs: Seq[Task[Int]],
val pure: Boolean) extends Target[Int]{
var counter = 0
+ var failure = Option.empty[String]
+ var exception = Option.empty[Throwable]
override def evaluate(args: Args) = {
- counter + args.args.map(_.asInstanceOf[Int]).sum
+ failure.map(Result.Failure) orElse
+ exception.map(Result.Exception) getOrElse
+ Result.Success(counter + args.args.map(_.asInstanceOf[Int]).sum)
}
- override def sideHash = counter
+ override def sideHash = counter + failure.hashCode() + exception.hashCode()
}
def checkTopological(targets: OSet[Task[_]]) = {
val seen = mutable.Set.empty[Task[_]]