summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-10-22 22:06:27 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2017-10-22 22:06:27 -0700
commit822be02a29d7073c7f2fe9b74df7cc42e56d762c (patch)
tree1812e53e1dc8626e13f70300aa34121c23b9e92d /src/test
parentd57ad0b63b54076d9182fdb75df9e38c8b30b58c (diff)
downloadmill-822be02a29d7073c7f2fe9b74df7cc42e56d762c.tar.gz
mill-822be02a29d7073c7f2fe9b74df7cc42e56d762c.tar.bz2
mill-822be02a29d7073c7f2fe9b74df7cc42e56d762c.zip
Swap over to new macro-based `DefCtx` injection, rather than relying on `StaticContext`
This should let us avoid the same `StaticContext` being re-used by multiple implicit use-sites within a block, causing confusion. `ForgeTests.evaluate.anonTriple` still doesn't pass for unrelated reasons
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/forge/ForgeTests.scala117
-rw-r--r--src/test/scala/forge/StaticContextTests.scala36
2 files changed, 59 insertions, 94 deletions
diff --git a/src/test/scala/forge/ForgeTests.scala b/src/test/scala/forge/ForgeTests.scala
index 07e753c6..ae6cfcf4 100644
--- a/src/test/scala/forge/ForgeTests.scala
+++ b/src/test/scala/forge/ForgeTests.scala
@@ -6,28 +6,28 @@ import java.nio.{file => jnio}
object ForgeTests extends TestSuite{
val tests = Tests{
- implicit def fakeStaticContext = DefCtx.StaticContext(true)
val evaluator = new Evaluator(jnio.Paths.get("target/workspace"), implicitly)
object Singleton {
- val single = test()
+ val single = T{ test() }
}
object Pair {
- val up = test()
- val down = test(up)
+ val up = T{ test() }
+ val down = T{ test(up) }
}
+
object AnonTriple{
- val up = test()
- val down = test(test(up))
+ val up = T{ test() }
+ val down = T{ test(test(up)) }
}
object Diamond{
- val up = test()
- val left = test(up)
- val right = test(up)
- val down = test(left, right)
+ val up = T{ test() }
+ val left = T{ test(up) }
+ val right = T{ test(up) }
+ val down = T{ test(left, right) }
}
object AnonDiamond{
- val up = test()
- val down = test(test(up), test(up))
+ val up = T{ test() }
+ val down = T{ test(test(up), test(up)) }
}
'topoSortedTransitiveTargets - {
@@ -35,6 +35,7 @@ object ForgeTests extends TestSuite{
val result = Evaluator.topoSortedTransitiveTargets(targets)
assert(result == expected)
}
+
'singleton - check(
targets = Seq(Singleton.single),
expected = Seq(Singleton.single)
@@ -60,60 +61,60 @@ object ForgeTests extends TestSuite{
Diamond.down
)
)
+ }
+ 'evaluate - {
+ def check(targets: Seq[Target[_]],
+ values: Seq[Any],
+ evaluated: Seq[Target[_]]) = {
+ val Evaluator.Results(returnedValues, returnedEvaluated) = evaluator.evaluate(targets)
+ assert(
+ returnedValues == values,
+ returnedEvaluated == evaluated
+ )
- 'evaluate - {
- def check(targets: Seq[Target[_]],
- values: Seq[Any],
- evaluated: Seq[Target[_]]) = {
- val Evaluator.Results(returnedValues, returnedEvaluated) = evaluator.evaluate(targets)
- assert(
- returnedValues == values,
- returnedEvaluated == evaluated
- )
-
- }
- 'singleton - {
- import Singleton._
- // First time the target is evaluated
- check(Seq(single), values = Seq(0), evaluated = Seq(single))
- // Second time the value is already cached, so no evaluation needed
- check(Seq(single), values = Seq(0), evaluated = Seq())
- single.counter += 1
- // After incrementing the counter, it forces re-evaluation
- check(Seq(single), values = Seq(1), evaluated = Seq(single))
- // Then it's cached again
- check(Seq(single), values = Seq(1), evaluated = Seq())
- }
- 'pair - {
- import Pair._
- check(Seq(down), values = Seq(0), evaluated = Seq(up, down))
- check(Seq(down), values = Seq(0), evaluated = Seq())
+ }
+ 'singleton - {
+ import Singleton._
+ // First time the target is evaluated
+ check(Seq(single), values = Seq(0), evaluated = Seq(single))
+ // Second time the value is already cached, so no evaluation needed
+ check(Seq(single), values = Seq(0), evaluated = Seq())
+ single.counter += 1
+ // After incrementing the counter, it forces re-evaluation
+ check(Seq(single), values = Seq(1), evaluated = Seq(single))
+ // Then it's cached again
+ check(Seq(single), values = Seq(1), evaluated = Seq())
+ }
+ 'pair - {
+ import Pair._
+ check(Seq(down), values = Seq(0), evaluated = Seq(up, down))
+ check(Seq(down), values = Seq(0), evaluated = Seq())
- down.counter += 1
- check(Seq(down), values = Seq(1), evaluated = Seq(down))
- check(Seq(down), values = Seq(1), evaluated = Seq())
+ down.counter += 1
+ check(Seq(down), values = Seq(1), evaluated = Seq(down))
+ check(Seq(down), values = Seq(1), evaluated = Seq())
- up.counter += 1
- check(Seq(down), values = Seq(2), evaluated = Seq(up, down))
- check(Seq(down), values = Seq(2), evaluated = Seq())
- }
- 'anonTriple - {
- import AnonTriple._
- val middle = down.inputs(0)
- check(Seq(down), values = Seq(0), evaluated = Seq(up, middle, down))
- check(Seq(down), values = Seq(0), evaluated = Seq())
+ up.counter += 1
+ check(Seq(down), values = Seq(2), evaluated = Seq(up, down))
+ check(Seq(down), values = Seq(2), evaluated = Seq())
+ }
+ 'anonTriple - {
+ import AnonTriple._
+ val middle = down.inputs(0)
+ check(Seq(down), values = Seq(0), evaluated = Seq(up, middle, down))
+ check(Seq(down), values = Seq(0), evaluated = Seq())
- down.counter += 1
- check(Seq(down), values = Seq(1), evaluated = Seq(middle, down))
- check(Seq(down), values = Seq(1), evaluated = Seq())
+ down.counter += 1
+ check(Seq(down), values = Seq(1), evaluated = Seq(middle, down))
+ check(Seq(down), values = Seq(1), evaluated = Seq())
- up.counter += 1
- check(Seq(down), values = Seq(2), evaluated = Seq(up, middle, down))
- check(Seq(down), values = Seq(2), evaluated = Seq())
- }
+ up.counter += 1
+ check(Seq(down), values = Seq(2), evaluated = Seq(up, middle, down))
+ check(Seq(down), values = Seq(2), evaluated = Seq())
}
}
+
// 'full - {
// val sourceRoot = Target.path(jnio.Paths.get("src/test/resources/example/src"))
// val resourceRoot = Target.path(jnio.Paths.get("src/test/resources/example/resources"))
diff --git a/src/test/scala/forge/StaticContextTests.scala b/src/test/scala/forge/StaticContextTests.scala
deleted file mode 100644
index 0e764fef..00000000
--- a/src/test/scala/forge/StaticContextTests.scala
+++ /dev/null
@@ -1,36 +0,0 @@
-package forge
-import DefCtx.StaticContext
-import utest._
-class Helper{
- val static = implicitly[StaticContext]
- object Nested {
- val static = implicitly[StaticContext]
- }
- def method = implicitly[StaticContext]
-}
-object StaticContextTests extends TestSuite{
- val static = implicitly[StaticContext]
- object Nested{
- val static = implicitly[StaticContext]
- def method = implicitly[StaticContext]
- class Helper{
- val static = implicitly[StaticContext]
- }
- }
-
- def method = implicitly[StaticContext]
- val tests = Tests{
- val helper = new Helper()
- 'inObject - assert(static.value)
- 'inClass- assert(!helper.static.value)
- 'inMethod - assert(!method.value)
-
- 'inObjectObject - assert(Nested.static.value)
- 'inObjectClass- assert(!helper.static.value)
- 'inObjectMethod- assert(!Nested.method.value)
-
- 'inClassObject - assert(!helper.Nested.static.value)
- 'inClassMethod- assert(!helper.method.value)
-
- }
-}