diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 11:20:28 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 11:20:28 -0800 |
commit | 8e8173e3afe60e162067fdc3440e451cc2d0da9c (patch) | |
tree | 037314d3102391839e1e3642b489f023d1aa9904 /core/src | |
parent | 435c578c4571fcff697ab2f601d399854950393a (diff) | |
download | mill-8e8173e3afe60e162067fdc3440e451cc2d0da9c.tar.gz mill-8e8173e3afe60e162067fdc3440e451cc2d0da9c.tar.bz2 mill-8e8173e3afe60e162067fdc3440e451cc2d0da9c.zip |
Organize `core/test`s into subfolders
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/test/scala/mill/TestMain.scala | 80 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/ApplicativeTests.scala (renamed from core/src/test/scala/mill/ApplicativeTests.scala) | 9 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/CacherTests.scala (renamed from core/src/test/scala/mill/CacherTests.scala) | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/CrossTests.scala (renamed from core/src/test/scala/mill/CrossTests.scala) | 3 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/GraphTests.scala (renamed from core/src/test/scala/mill/GraphTests.scala) | 8 | ||||
-rw-r--r-- | core/src/test/scala/mill/define/MacroErrorTests.scala | 79 | ||||
-rw-r--r-- | core/src/test/scala/mill/discover/DiscoveredTests.scala (renamed from core/src/test/scala/mill/DiscoveredTests.scala) | 7 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/EvaluationTests.scala (renamed from core/src/test/scala/mill/EvaluationTests.scala) | 9 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/JavaCompileJarTests.scala (renamed from core/src/test/scala/mill/JavaCompileJarTests.scala) | 7 | ||||
-rw-r--r-- | core/src/test/scala/mill/eval/TarjanTests.scala (renamed from core/src/test/scala/mill/TarjanTests.scala) | 5 | ||||
-rw-r--r-- | core/src/test/scala/mill/util/TestGraphs.scala (renamed from core/src/test/scala/mill/TestGraphs.scala) | 7 | ||||
-rw-r--r-- | core/src/test/scala/mill/util/TestUtil.scala (renamed from core/src/test/scala/mill/TestUtil.scala) | 3 |
12 files changed, 108 insertions, 113 deletions
diff --git a/core/src/test/scala/mill/TestMain.scala b/core/src/test/scala/mill/TestMain.scala index c8fb3148..80e7e627 100644 --- a/core/src/test/scala/mill/TestMain.scala +++ b/core/src/test/scala/mill/TestMain.scala @@ -1,86 +1,6 @@ package mill -import java.io.FileInputStream - -import ammonite.ops._ -import java.lang.annotation.Annotation -import java.util.zip.ZipInputStream - -import sbt.testing._ object TestMain { - def listClassFiles(base: Path): Iterator[String] = { - if (base.isDir) ls.rec(base).toIterator.filter(_.ext == "class").map(_.relativeTo(base).toString) - else { - val zip = new ZipInputStream(new FileInputStream(base.toIO)) - Iterator.continually(zip.getNextEntry).takeWhile(_ != null).map(_.getName).filter(_.endsWith(".class")) - } - } - def runTests(framework: Framework, - targets: Seq[Path]) = { - - - val fingerprints = framework.fingerprints() - val testClasses = targets.flatMap { base => - listClassFiles(base).flatMap { path => - val cls = Class.forName(path.stripSuffix(".class").replace('/', '.')) - fingerprints.find { - case f: SubclassFingerprint => - Class.forName(f.superclassName()).isAssignableFrom(cls) - case f: AnnotatedFingerprint => - cls.isAnnotationPresent( - Class.forName(f.annotationName()).asInstanceOf[Class[Annotation]] - ) - }.map { f => (cls, f) } - } - } - testClasses - } def main(args: Array[String]): Unit = { - - val framework = Class.forName("mill.UTestFramework") - .newInstance() - .asInstanceOf[sbt.testing.Framework] - - val testClasses = runTests( - framework, - Seq(pwd/'core/'target/"scala-2.12"/"test-classes") - ) - - pprint.log(testClasses) - - val runner = framework.runner(Array(), Array(), getClass.getClassLoader) - println(runner) - - val tasks = runner.tasks( - for((cls, fingerprint) <- testClasses.toArray) - yield { - new TaskDef(cls.getName.stripSuffix("$"), fingerprint, true, Array()) - } - ) - for(t <- tasks){ - t.execute( - new EventHandler { - def handle(event: Event) = () - }, - Array( - new Logger { - def debug(msg: String) = println(msg) - - def error(msg: String) = println(msg) - - def ansiCodesSupported() = true - - def warn(msg: String) = println(msg) - - def trace(t: Throwable) = println(t) - - def info(msg: String) = println(msg) - }) - ) - } - val doneMsg = runner.done() - if (doneMsg.trim.nonEmpty){ - println(doneMsg) - } } } diff --git a/core/src/test/scala/mill/ApplicativeTests.scala b/core/src/test/scala/mill/define/ApplicativeTests.scala index bd930f93..7e31b08e 100644 --- a/core/src/test/scala/mill/ApplicativeTests.scala +++ b/core/src/test/scala/mill/define/ApplicativeTests.scala @@ -1,13 +1,14 @@ -package mill -import mill.define.Applicative +package mill.define + import utest._ -import language.experimental.macros + +import scala.language.experimental.macros object ApplicativeTests extends TestSuite { implicit def optionToOpt[T](o: Option[T]): Opt[T] = new Opt(o) class Opt[T](val o: Option[T]) extends Applicative.Applyable[T] - object Opt extends define.Applicative.Applyer[Opt, Option, Applicative.Id, String]{ + object Opt extends Applicative.Applyer[Opt, Option, Applicative.Id, String]{ val injectedCtx = "helloooo" def underlying[A](v: Opt[A]) = v.o diff --git a/core/src/test/scala/mill/CacherTests.scala b/core/src/test/scala/mill/define/CacherTests.scala index 6e0087b1..f3d07a29 100644 --- a/core/src/test/scala/mill/CacherTests.scala +++ b/core/src/test/scala/mill/define/CacherTests.scala @@ -1,9 +1,9 @@ -package mill +package mill.define -import mill.define.Task import mill.discover.Discovered import mill.eval.Evaluator import mill.util.OSet +import mill.T import utest._ import utest.framework.TestPath diff --git a/core/src/test/scala/mill/CrossTests.scala b/core/src/test/scala/mill/define/CrossTests.scala index 76cde1e9..07545d44 100644 --- a/core/src/test/scala/mill/CrossTests.scala +++ b/core/src/test/scala/mill/define/CrossTests.scala @@ -1,6 +1,5 @@ -package mill +package mill.define -import mill.define.Cross import utest._ object CrossTests extends TestSuite{ diff --git a/core/src/test/scala/mill/GraphTests.scala b/core/src/test/scala/mill/define/GraphTests.scala index 00ea3cc3..cc7bd3c2 100644 --- a/core/src/test/scala/mill/GraphTests.scala +++ b/core/src/test/scala/mill/define/GraphTests.scala @@ -1,10 +1,9 @@ -package mill +package mill.define -import utest._ -import mill.define.{Target, Task} import mill.discover.Discovered import mill.eval.Evaluator -import mill.util.OSet +import mill.util.{OSet, TestGraphs, TestUtil} +import utest._ object GraphTests extends TestSuite{ @@ -13,7 +12,6 @@ object GraphTests extends TestSuite{ val graphs = new TestGraphs() import graphs._ - 'failConsistencyChecks - { // Make sure these fail because `def`s without `Cacher` will re-evaluate // each time, returning different sets of targets. diff --git a/core/src/test/scala/mill/define/MacroErrorTests.scala b/core/src/test/scala/mill/define/MacroErrorTests.scala new file mode 100644 index 00000000..b0d687fe --- /dev/null +++ b/core/src/test/scala/mill/define/MacroErrorTests.scala @@ -0,0 +1,79 @@ +package mill.define + +import utest._ +import mill.{T, Module} +import mill.util.TestUtil +object MacroErrorTests extends TestSuite{ + + val tests = Tests{ + + 'errors{ + val expectedMsg = + "T{} members must be defs defined in a Cacher class/trait/object body" + + val err = compileError("object Foo extends Module{ val x = T{1} }") + assert(err.msg == expectedMsg) + } + + 'badTmacro - { + // Make sure we can reference values from outside the T{...} block as part + // of our `Target#apply()` calls, but we cannot reference any values that + // come from inside the T{...} block + 'pos - { + val e = compileError(""" + val a = T{ 1 } + val arr = Array(a) + val b = { + val c = 0 + T{ + arr(c)() + } + } + """) + assert(e.msg.contains("must be defs")) + } + 'neg - { + + val expectedMsg = + "Target#apply() call cannot use `value n` defined within the T{...} block" + val err = compileError("""new Module{ + def a = T{ 1 } + val arr = Array(a) + def b = { + T{ + val n = 0 + arr(n)() + } + } + }""") + assert(err.msg == expectedMsg) + } + 'neg2 - { + + val expectedMsg = + "Target#apply() call cannot use `value x` defined within the T{...} block" + val err = compileError("""new Module{ + def a = T{ 1 } + val arr = Array(a) + def b = { + T{ + arr.map{x => x()} + } + } + }""") + assert(err.msg == expectedMsg) + } + 'neg3{ + val borkedCachedDiamond1 = utest.compileError(""" + object borkedCachedDiamond1 { + def up = T{ TestUtil.test() } + def left = T{ TestUtil.test(up) } + def right = T{ TestUtil.test(up) } + def down = T{ TestUtil.test(left, right) } + } + """) + assert(borkedCachedDiamond1.msg.contains("must be defs")) + } + } + } +} diff --git a/core/src/test/scala/mill/DiscoveredTests.scala b/core/src/test/scala/mill/discover/DiscoveredTests.scala index 96c84d1b..dae7ff1b 100644 --- a/core/src/test/scala/mill/DiscoveredTests.scala +++ b/core/src/test/scala/mill/discover/DiscoveredTests.scala @@ -1,9 +1,8 @@ -package mill +package mill.discover import utest._ -import TestUtil.test -import mill.discover.{Discovered, Mirror} - +import mill.Module +import mill.util.TestUtil.test object DiscoveredTests extends TestSuite{ val tests = Tests{ diff --git a/core/src/test/scala/mill/EvaluationTests.scala b/core/src/test/scala/mill/eval/EvaluationTests.scala index 9c856152..3b268911 100644 --- a/core/src/test/scala/mill/EvaluationTests.scala +++ b/core/src/test/scala/mill/eval/EvaluationTests.scala @@ -1,11 +1,12 @@ -package mill +package mill.eval -import mill.TestUtil.{Test, test} +import mill.util.TestUtil.{Test, test} import mill.define.{Target, Task} +import mill.{Module, T} import mill.discover.Discovered import mill.eval.Evaluator -import mill.util.OSet +import mill.util.{OSet, TestUtil} import utest._ import utest.framework.TestPath @@ -60,7 +61,7 @@ object EvaluationTests extends TestSuite{ } val tests = Tests{ - val graphs = new TestGraphs() + val graphs = new mill.util.TestGraphs() import graphs._ 'evaluateSingle - { diff --git a/core/src/test/scala/mill/JavaCompileJarTests.scala b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala index 80df57b6..6ec03cf3 100644 --- a/core/src/test/scala/mill/JavaCompileJarTests.scala +++ b/core/src/test/scala/mill/eval/JavaCompileJarTests.scala @@ -1,12 +1,11 @@ -package mill - +package mill.eval +import ammonite.ops.ImplicitWd._ import ammonite.ops._ -import ImplicitWd._ import mill.define.{Target, Task} import mill.discover.Discovered -import mill.eval.{Evaluator, Result} import mill.modules.Jvm.jarUp +import mill.{T, Module} import mill.util.OSet import utest._ diff --git a/core/src/test/scala/mill/TarjanTests.scala b/core/src/test/scala/mill/eval/TarjanTests.scala index 7ae7dd04..2f9d0a4d 100644 --- a/core/src/test/scala/mill/TarjanTests.scala +++ b/core/src/test/scala/mill/eval/TarjanTests.scala @@ -1,6 +1,7 @@ -package mill -import mill.eval.Tarjans +package mill.eval + import utest._ + object TarjanTests extends TestSuite{ def check(input: Seq[Seq[Int]], expected: Seq[Seq[Int]]) = { val result = Tarjans(input).map(_.sorted) diff --git a/core/src/test/scala/mill/TestGraphs.scala b/core/src/test/scala/mill/util/TestGraphs.scala index 094496c1..f93b6152 100644 --- a/core/src/test/scala/mill/TestGraphs.scala +++ b/core/src/test/scala/mill/util/TestGraphs.scala @@ -1,7 +1,6 @@ -package mill - -import mill.TestUtil.test - +package mill.util +import TestUtil.test +import mill.{Module, T} class TestGraphs(){ // single object singleton { diff --git a/core/src/test/scala/mill/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala index 006198a4..23603238 100644 --- a/core/src/test/scala/mill/TestUtil.scala +++ b/core/src/test/scala/mill/util/TestUtil.scala @@ -1,7 +1,6 @@ -package mill +package mill.util import mill.define.{Target, Task} -import mill.util.{Args, OSet} import utest.assert import scala.collection.mutable |