diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-23 21:30:25 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-23 21:30:25 -0800 |
commit | c5b54b496af1a4aae2624c2f6d1e551b5026d54b (patch) | |
tree | 887eb5526e60d7b2736622848915ea20ff347d32 | |
parent | 42189d826bc1544013c31bb591ed6a23ccf853b1 (diff) | |
download | mill-c5b54b496af1a4aae2624c2f6d1e551b5026d54b.tar.gz mill-c5b54b496af1a4aae2624c2f6d1e551b5026d54b.tar.bz2 mill-c5b54b496af1a4aae2624c2f6d1e551b5026d54b.zip |
Add some basic tests for `T.{persistent,input,worker}` behavior, including a currently-failing test exposing a bug where `T.worker` unnecessarily invalidates caches
-rw-r--r-- | core/test/src/mill/eval/TaskTests.scala | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/core/test/src/mill/eval/TaskTests.scala b/core/test/src/mill/eval/TaskTests.scala new file mode 100644 index 00000000..3c355fa4 --- /dev/null +++ b/core/test/src/mill/eval/TaskTests.scala @@ -0,0 +1,104 @@ +package mill.eval + +import utest._ +import ammonite.ops._ +import mill.T +import mill.util.TestEvaluator +object TaskTests extends TestSuite{ + val tests = Tests{ + object build extends mill.util.TestUtil.BaseModule{ + var count = 0 + def staticWorker = T.worker{ + new Function1[Int, Int] { + def apply(v1: Int) = v1 + 1 + } + } + def noisyWorker = T.worker{ + new Function1[Int, Int] { + def apply(v1: Int) = input() + 1 + } + } + def input = T.input{ + count += 1 + count + } + def task = T.task{ + count += 1 + count + } + def taskInput = T{ input() } + def taskNoInput = T{ task() } + + def persistent = T.persistent{ + input() // force re-computation + mkdir(T.ctx().dest) + write.append(T.ctx().dest/'count, "hello\n") + read.lines(T.ctx().dest/'count).length + } + def nonPersistent = T{ + input() // force re-computation + mkdir(T.ctx().dest) + write.append(T.ctx().dest/'count, "hello\n") + read.lines(T.ctx().dest/'count).length + } + + def staticWorkerDownstream = T{ + staticWorker().apply(1) + } + def noisyWorkerDownstream = T{ + noisyWorker().apply(1) + } + } + + 'inputs - { + // Inputs always re-evaluate, including forcing downstream cached Targets + // to re-evaluate, but normal Tasks behind a Target run once then are cached + val check = new TestEvaluator( + build, + pwd / 'target / 'workspace / "task-tests" / "inputs", + pwd + ) + + val Right((1, 1)) = check.apply(build.taskInput) + val Right((2, 1)) = check.apply(build.taskInput) + val Right((3, 1)) = check.apply(build.taskInput) + + val Right((4, 1)) = check.apply(build.taskNoInput) + val Right((4, 0)) = check.apply(build.taskNoInput) + val Right((4, 0)) = check.apply(build.taskNoInput) + } + + 'persistent - { + // Persistent tasks keep the working dir around between runs + val check = new TestEvaluator( + build, + pwd / 'target / 'workspace / "task-tests" / "persistent", + pwd + ) + val Right((1, 1)) = check.apply(build.persistent) + val Right((2, 1)) = check.apply(build.persistent) + val Right((3, 1)) = check.apply(build.persistent) + + val Right((1, 1)) = check.apply(build.nonPersistent) + val Right((1, 1)) = check.apply(build.nonPersistent) + val Right((1, 1)) = check.apply(build.nonPersistent) + } + + 'worker - { + // Persistent task + def check = new TestEvaluator( + build, + pwd / 'target / 'workspace / "task-tests" / "worker", + pwd + ) + + val Right((2, 1)) = check.apply(build.noisyWorkerDownstream) + val Right((3, 1)) = check.apply(build.noisyWorkerDownstream) + val Right((4, 1)) = check.apply(build.noisyWorkerDownstream) + + val Right((2, 1)) = check.apply(build.staticWorkerDownstream) + val Right((2, 0)) = check.apply(build.staticWorkerDownstream) + val Right((2, 0)) = check.apply(build.staticWorkerDownstream) + } + } +} |