diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 17:06:30 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 17:06:30 -0800 |
commit | b1ae941cb360218a7208709d696aae439567168d (patch) | |
tree | f260220e78b9a68bcf275a011047b3544e682bbe | |
parent | a4fb53e33a9ea49592f3d039a5d1bfbdee5d8a30 (diff) | |
download | mill-b1ae941cb360218a7208709d696aae439567168d.tar.gz mill-b1ae941cb360218a7208709d696aae439567168d.tar.bz2 mill-b1ae941cb360218a7208709d696aae439567168d.zip |
Refactor `eval/FailureTests` to DRY it up
-rw-r--r-- | core/src/test/scala/mill/eval/FailureTests.scala | 84 |
1 files changed, 48 insertions, 36 deletions
diff --git a/core/src/test/scala/mill/eval/FailureTests.scala b/core/src/test/scala/mill/eval/FailureTests.scala index 682f5e16..8963031a 100644 --- a/core/src/test/scala/mill/eval/FailureTests.scala +++ b/core/src/test/scala/mill/eval/FailureTests.scala @@ -1,5 +1,6 @@ package mill.eval +import mill.define.Target import mill.discover.Discovered import mill.util.OSet import utest._ @@ -10,76 +11,87 @@ object FailureTests extends TestSuite{ val tests = Tests{ val graphs = new mill.util.TestGraphs() import graphs._ + def check[T: Discovered](base: T) + (target: T => Target[_], expectedFailCount: Int, expectedRawValues: Seq[Result[_]]) + (implicit tp: TestPath) = { + val workspace = ammonite.ops.pwd / 'target / 'workspace / 'failure / implicitly[TestPath].value + val evaluator = new Evaluator(workspace, Discovered.mapping(base), _ => ()) + val res = evaluator.evaluate(OSet(target(base))) + assert( + res.rawValues == expectedRawValues, + res.failing.keyCount == expectedFailCount + ) + + } '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)) + check(singleton)( + target = _.single, + expectedFailCount = 0, + expectedRawValues = 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")) + check(singleton)( + target = _.single, + expectedFailCount = 1, + expectedRawValues = 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)) + check(singleton)( + target = _.single, + expectedFailCount = 0, + expectedRawValues = 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)) + + check(singleton)( + target = _.single, + expectedFailCount = 1, + expectedRawValues = 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)) + check(pair)( + _.down, + expectedFailCount = 0, + expectedRawValues = 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) + check(pair)( + _.down, + expectedFailCount = 1, + expectedRawValues = 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)) + check(pair)( + _.down, + expectedFailCount = 0, + expectedRawValues = 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) + check(pair)( + _.down, + expectedFailCount = 1, + expectedRawValues = Seq(Result.Skipped) ) } } |