diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-02 23:58:00 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-03 00:24:46 -0800 |
commit | bfd64f104a283b70ad57a66c8ac7d4dc3bda9e6f (patch) | |
tree | bda95b847b7f8e520565b05dacd14c7bffaae1bd /core/test | |
parent | 4c76e9668ab9683dad1966bcd6fb5031a81f8460 (diff) | |
download | mill-bfd64f104a283b70ad57a66c8ac7d4dc3bda9e6f.tar.gz mill-bfd64f104a283b70ad57a66c8ac7d4dc3bda9e6f.tar.bz2 mill-bfd64f104a283b70ad57a66c8ac7d4dc3bda9e6f.zip |
Make `TestEvaluator` infer it's `outPath` from the `sourcecode.FullName` and `utest.framework.TestPath`
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/src/mill/define/CacherTests.scala | 3 | ||||
-rw-r--r-- | core/test/src/mill/eval/CrossTests.scala | 20 | ||||
-rw-r--r-- | core/test/src/mill/eval/EvaluationTests.scala | 12 | ||||
-rw-r--r-- | core/test/src/mill/eval/FailureTests.scala | 13 | ||||
-rw-r--r-- | core/test/src/mill/eval/JavaCompileJarTests.scala | 15 | ||||
-rw-r--r-- | core/test/src/mill/eval/ModuleTests.scala | 12 | ||||
-rw-r--r-- | core/test/src/mill/eval/TaskTests.scala | 15 | ||||
-rw-r--r-- | core/test/src/mill/util/TestEvaluator.scala | 26 |
8 files changed, 51 insertions, 65 deletions
diff --git a/core/test/src/mill/define/CacherTests.scala b/core/test/src/mill/define/CacherTests.scala index a14f2f34..ce97202b 100644 --- a/core/test/src/mill/define/CacherTests.scala +++ b/core/test/src/mill/define/CacherTests.scala @@ -28,8 +28,7 @@ object CacherTests extends TestSuite{ val tests = Tests{ def eval[T <: TestUtil.TestBuild, V](mapping: T, v: Task[V]) (implicit discover: Discover[T], tp: TestPath) = { - val workspace = ammonite.ops.pwd / 'target / 'workspace / tp.value - val evaluator = new TestEvaluator(mapping, workspace) + val evaluator = new TestEvaluator(mapping) evaluator(v).right.get._1 } diff --git a/core/test/src/mill/eval/CrossTests.scala b/core/test/src/mill/eval/CrossTests.scala index af13474b..c9f7cb70 100644 --- a/core/test/src/mill/eval/CrossTests.scala +++ b/core/test/src/mill/eval/CrossTests.scala @@ -11,10 +11,7 @@ import utest._ object CrossTests extends TestSuite{ val tests = Tests{ 'singleCross - { - val check = new TestEvaluator( - singleCross, - pwd / 'target / 'workspace / "cross-tests" / "inputs" - ) + val check = new TestEvaluator(singleCross) val Right(("210", 1)) = check.apply(singleCross.cross("210").suffix) val Right(("211", 1)) = check.apply(singleCross.cross("211").suffix) @@ -22,10 +19,7 @@ object CrossTests extends TestSuite{ } 'crossResolved - { - val check = new TestEvaluator( - crossResolved, - pwd / 'target / 'workspace / "cross-tests" / "crossResolved" - ) + val check = new TestEvaluator(crossResolved) val Right(("2.10", 1)) = check.apply(crossResolved.foo("2.10").suffix) val Right(("2.11", 1)) = check.apply(crossResolved.foo("2.11").suffix) @@ -38,10 +32,7 @@ object CrossTests extends TestSuite{ 'doubleCross - { - val check = new TestEvaluator( - doubleCross, - pwd / 'target / 'workspace / "cross-tests" / "doubleCross" - ) + val check = new TestEvaluator(doubleCross) val Right(("210_jvm", 1)) = check.apply(doubleCross.cross("210", "jvm").suffix) val Right(("210_js", 1)) = check.apply(doubleCross.cross("210", "js").suffix) @@ -53,10 +44,7 @@ object CrossTests extends TestSuite{ } 'nestedCrosses - { - val check = new TestEvaluator( - nestedCrosses, - pwd / 'target / 'workspace / "cross-tests" / "nestedCrosses" - ) + val check = new TestEvaluator(nestedCrosses) val Right(("210_jvm", 1)) = check.apply(nestedCrosses.cross("210").cross2("jvm").suffix) val Right(("210_js", 1)) = check.apply(nestedCrosses.cross("210").cross2("js").suffix) diff --git a/core/test/src/mill/eval/EvaluationTests.scala b/core/test/src/mill/eval/EvaluationTests.scala index 9fabe623..5b9936cb 100644 --- a/core/test/src/mill/eval/EvaluationTests.scala +++ b/core/test/src/mill/eval/EvaluationTests.scala @@ -13,11 +13,9 @@ import ammonite.ops._ object EvaluationTests extends TestSuite{ class Checker[T <: TestUtil.TestBuild](module: T) (implicit tp: TestPath, discover: Discover[T]) { - val workspace = pwd / 'target / 'workspace / tp.value - rm(Path(workspace, pwd)) // Make sure data is persisted even if we re-create the evaluator each time - def evaluator = new TestEvaluator(module, workspace).evaluator + def evaluator = new TestEvaluator(module).evaluator def apply(target: Task[_], expValue: Any, expEvaled: Agg[Task[_]], @@ -209,9 +207,9 @@ object EvaluationTests extends TestSuite{ checker(foo, Seq("base", "object"), Agg(foo), extraEvaled = -1) - val public = ammonite.ops.read(checker.workspace / 'foo / "meta.json") + val public = ammonite.ops.read(checker.evaluator.outPath / 'foo / "meta.json") val overriden = ammonite.ops.read( - checker.workspace / 'foo / + checker.evaluator.outPath / 'foo / 'overriden / "mill.util.TestGraphs.BaseModule#foo" / "meta.json" ) assert( @@ -237,9 +235,9 @@ object EvaluationTests extends TestSuite{ secondRunNoOp = false ) - val public = ammonite.ops.read(checker.workspace / 'cmd / "meta.json") + val public = ammonite.ops.read(checker.evaluator.outPath / 'cmd / "meta.json") val overriden = ammonite.ops.read( - checker.workspace / 'cmd / + checker.evaluator.outPath / 'cmd / 'overriden / "mill.util.TestGraphs.BaseModule#cmd" / "meta.json" ) assert( diff --git a/core/test/src/mill/eval/FailureTests.scala b/core/test/src/mill/eval/FailureTests.scala index e7c231ee..48209b4e 100644 --- a/core/test/src/mill/eval/FailureTests.scala +++ b/core/test/src/mill/eval/FailureTests.scala @@ -7,18 +7,12 @@ import utest.framework.TestPath import mill.util.TestEvaluator.implicitDisover object FailureTests extends TestSuite{ - def workspace(implicit tp: TestPath) = { - ammonite.ops.pwd / 'target / 'workspace / 'failure / implicitly[TestPath].value - } - - val tests = Tests{ val graphs = new mill.util.TestGraphs() import graphs._ 'evaluateSingle - { - ammonite.ops.rm(ammonite.ops.Path(workspace, ammonite.ops.pwd)) - val check = new TestEvaluator(singleton, workspace) + val check = new TestEvaluator(singleton) check.fail( target = singleton.single, expectedFailCount = 0, @@ -53,8 +47,7 @@ object FailureTests extends TestSuite{ ) } 'evaluatePair - { - val check = new TestEvaluator(pair, workspace) - rm(Path(workspace, pwd)) + val check = new TestEvaluator(pair) check.fail( pair.down, expectedFailCount = 0, @@ -95,7 +88,7 @@ object FailureTests extends TestSuite{ def right = T{ task() + left() + T.ctx().dest.toString().length } } - val check = new TestEvaluator(build, workspace) + val check = new TestEvaluator(build) val Right(_) = check(build.left) val Left(Result.Exception(e, _)) = check(build.right) assert(e.getMessage.contains("`dest` can only be used in one place")) diff --git a/core/test/src/mill/eval/JavaCompileJarTests.scala b/core/test/src/mill/eval/JavaCompileJarTests.scala index ba80cc3c..9d1134b8 100644 --- a/core/test/src/mill/eval/JavaCompileJarTests.scala +++ b/core/test/src/mill/eval/JavaCompileJarTests.scala @@ -21,11 +21,10 @@ object JavaCompileJarTests extends TestSuite{ val tests = Tests{ 'javac { - val workspacePath = pwd / 'target / 'workspace / 'javac val javacSrcPath = pwd / 'core / 'test / 'resources / 'examples / 'javac - val javacDestPath = workspacePath / 'src + val javacDestPath = TestEvaluator.getOutPath() / 'src - mkdir(pwd / 'target / 'workspace / 'javac) + mkdir(javacDestPath / up) cp(javacSrcPath, javacDestPath) object Build extends TestUtil.BaseModule{ @@ -49,12 +48,11 @@ object JavaCompileJarTests extends TestSuite{ import Build._ + var evaluator = new TestEvaluator(Build) def eval[T](t: Task[T]) = { - val evaluator = new TestEvaluator(Build, workspacePath) evaluator.apply(t) } def check(targets: Agg[Task[_]], expected: Agg[Task[_]]) = { - val evaluator = new TestEvaluator(Build, workspacePath) evaluator.check(targets, expected) } @@ -90,6 +88,9 @@ object JavaCompileJarTests extends TestSuite{ append(resourceRootPath / "hello.txt", " ") check(targets = Agg(jar), expected = Agg(jar)) + // You can swap evaluators halfway without any ill effects + evaluator = new TestEvaluator(Build) + // Asking for an intermediate target forces things to be build up to that // target only; these are re-used for any downstream targets requested append(sourceRootPath / "Bar.java", "\nclass BarTwo{}") @@ -104,7 +105,7 @@ object JavaCompileJarTests extends TestSuite{ check(targets = Agg(allSources), expected = Agg(allSources)) check(targets = Agg(jar), expected = Agg(classFiles, jar)) - val jarContents = %%('jar, "-tf", workspacePath/'jar/'dest/"out.jar")(workspacePath).out.string + val jarContents = %%('jar, "-tf", evaluator.outPath/'jar/'dest/"out.jar")(evaluator.outPath).out.string val expectedJarContents = """META-INF/MANIFEST.MF |hello.txt @@ -116,7 +117,7 @@ object JavaCompileJarTests extends TestSuite{ |""".stripMargin assert(jarContents == expectedJarContents) - val executed = %%('java, "-cp", workspacePath/'jar/'dest/"out.jar", "test.Foo")(workspacePath).out.string + val executed = %%('java, "-cp", evaluator.outPath/'jar/'dest/"out.jar", "test.Foo")(evaluator.outPath).out.string assert(executed == (31337 + 271828) + "\n") for(i <- 0 until 3){ diff --git a/core/test/src/mill/eval/ModuleTests.scala b/core/test/src/mill/eval/ModuleTests.scala index c7e85169..b452a854 100644 --- a/core/test/src/mill/eval/ModuleTests.scala +++ b/core/test/src/mill/eval/ModuleTests.scala @@ -20,17 +20,13 @@ object ModuleTests extends TestSuite{ val tests = Tests { rm(TestEvaluator.externalOutPath) 'externalModuleTargetsAreNamespacedByModulePackagePath - { - val check = new TestEvaluator( - Build, - pwd / 'target / 'external - ) + val check = new TestEvaluator(Build) val Right((30, 1)) = check.apply(Build.z) - val base = check.evaluator.outPath assert( - read(base / 'z / "meta.json").contains("30"), - read(base / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"), - read(base / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'inner / 'y / "meta.json").contains("17") + read(check.evaluator.outPath / 'z / "meta.json").contains("30"), + read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"), + read(TestEvaluator.externalOutPath / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'inner / 'y / "meta.json").contains("17") ) } 'externalModuleMustBeGlobalStatic - { diff --git a/core/test/src/mill/eval/TaskTests.scala b/core/test/src/mill/eval/TaskTests.scala index af2e19a9..114a2910 100644 --- a/core/test/src/mill/eval/TaskTests.scala +++ b/core/test/src/mill/eval/TaskTests.scala @@ -56,10 +56,7 @@ object TaskTests extends TestSuite{ '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" - ) + val check = new TestEvaluator(build) val Right((1, 1)) = check.apply(build.taskInput) val Right((2, 1)) = check.apply(build.taskInput) @@ -72,10 +69,7 @@ object TaskTests extends TestSuite{ 'persistent - { // Persistent tasks keep the working dir around between runs - val check = new TestEvaluator( - build, - pwd / 'target / 'workspace / "task-tests" / "persistent" - ) + val check = new TestEvaluator(build) val Right((1, 1)) = check.apply(build.persistent) val Right((2, 1)) = check.apply(build.persistent) val Right((3, 1)) = check.apply(build.persistent) @@ -87,10 +81,7 @@ object TaskTests extends TestSuite{ 'worker - { // Persistent task - def check = new TestEvaluator( - build, - pwd / 'target / 'workspace / "task-tests" / "worker" - ) + def check = new TestEvaluator(build) val Right((2, 1)) = check.apply(build.noisyWorkerDownstream) val Right((3, 1)) = check.apply(build.noisyWorkerDownstream) diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala index dd113b55..5684b4fd 100644 --- a/core/test/src/mill/util/TestEvaluator.scala +++ b/core/test/src/mill/util/TestEvaluator.scala @@ -6,17 +6,37 @@ import mill.define.{Discover, Input, Target, Task} import mill.eval.{Evaluator, Result} import mill.util.Strict.Agg import utest.assert +import utest.framework.TestPath import language.experimental.macros object TestEvaluator{ implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T] val externalOutPath = pwd / 'target / 'external + + def getOutPath()(implicit fullName: sourcecode.FullName, + tp: TestPath) = { + pwd / 'target / 'workspace / (fullName.value.split('.') ++ tp.value) + } + def getOutPathStatic()(implicit fullName: sourcecode.FullName) = { + pwd / 'target / 'workspace / fullName.value.split('.') + } + + def static[T <: TestUtil.TestBuild](module: T) + (implicit discover: Discover[T], + fullName: sourcecode.FullName) = { + new TestEvaluator[T](module)(discover, fullName, TestPath(Nil)) + } } -class TestEvaluator[T <: TestUtil.TestBuild](module: T, workspacePath: Path) - (implicit discover: Discover[T]){ + +class TestEvaluator[T <: TestUtil.TestBuild](module: T) + (implicit discover: Discover[T], + fullName: sourcecode.FullName, + tp: TestPath){ + val outPath = TestEvaluator.getOutPath() + // val logger = DummyLogger val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err) - val evaluator = new Evaluator(workspacePath, TestEvaluator.externalOutPath, module, discover, logger) + val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, discover, logger) def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { val evaluated = evaluator.evaluate(Agg(t)) |