diff --git a/util-tracking/src/main/scala/sbt/util/Tracked.scala b/util-tracking/src/main/scala/sbt/util/Tracked.scala index cfc1d089f..c6286a832 100644 --- a/util-tracking/src/main/scala/sbt/util/Tracked.scala +++ b/util-tracking/src/main/scala/sbt/util/Tracked.scala @@ -100,7 +100,7 @@ object Tracked { val changed = help.changed(store, initial) val result = f(changed, initial) if (changed) { - help.save(store, initial) + help.save(store, p()) } result } @@ -178,7 +178,7 @@ object Tracked { def save(store: CacheStore, value: I): Unit = { Hasher.hash(value) match { case Success(keyHash) => store.write[Long](keyHash.toLong) - case Failure(e) => () + case Failure(_) => () } } diff --git a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala index 7db275d1a..8f88cc53a 100644 --- a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala +++ b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala @@ -1,12 +1,11 @@ package sbt.util +import org.scalatest.FlatSpec import sbt.io.IO import sbt.io.syntax._ +import sbt.util.CacheImplicits._ -import CacheImplicits._ - -import sjsonnew.IsoString -import org.scalatest.FlatSpec +import scala.concurrent.Promise class TrackedSpec extends FlatSpec { "lastOutput" should "store the last output" in { @@ -19,14 +18,14 @@ class TrackedSpec extends FlatSpec { case (in, None) => assert(in === value) in - case (in, Some(_)) => + case (_, Some(_)) => fail() }(implicitly)(value) assert(res0 === value) val res1 = Tracked.lastOutput[Int, Int](store) { - case (in, None) => + case (_, None) => fail() case (in, Some(read)) => assert(in === otherValue) @@ -37,7 +36,7 @@ class TrackedSpec extends FlatSpec { val res2 = Tracked.lastOutput[Int, Int](store) { - case (in, None) => + case (_, None) => fail() case (in, Some(read)) => assert(in === otherValue) @@ -45,6 +44,8 @@ class TrackedSpec extends FlatSpec { read }(implicitly)(otherValue) assert(res2 === value) + + () } } @@ -57,14 +58,14 @@ class TrackedSpec extends FlatSpec { case (true, in) => assert(in === input0) in - case (false, in) => + case (false, _) => fail() }(implicitly, implicitly)(input0) assert(res0 === input0) val res1 = Tracked.inputChanged[String, String](store) { - case (true, in) => + case (true, _) => fail() case (false, in) => assert(in === input0) @@ -72,6 +73,7 @@ class TrackedSpec extends FlatSpec { }(implicitly, implicitly)(input0) assert(res1 === input0) + () } } @@ -85,7 +87,7 @@ class TrackedSpec extends FlatSpec { case (true, in) => assert(in === input0) in - case (false, in) => + case (false, _) => fail() }(implicitly, implicitly)(input0) assert(res0 === input0) @@ -95,39 +97,52 @@ class TrackedSpec extends FlatSpec { case (true, in) => assert(in === input1) in - case (false, in) => + case (false, _) => fail() }(implicitly, implicitly)(input1) assert(res1 === input1) + () } } "outputChanged" should "detect that the output has not changed" in { withStore { store => - val input0: String = "foo" - val p0: () => String = () => input0 + val beforeCompletion: String = "before-completion" + val afterCompletion: String = "after-completion" + val sideEffectCompleted = Promise[Unit] + val p0: () => String = () => { + if (sideEffectCompleted.isCompleted) { + afterCompletion + } else { + sideEffectCompleted.success(()) + beforeCompletion + } + } + val firstExpectedResult = "first-result" + val secondExpectedResult = "second-result" val res0 = Tracked.outputChanged[String, String](store) { case (true, in) => - assert(in === input0) - in - case (false, in) => + assert(in === beforeCompletion) + firstExpectedResult + case (false, _) => fail() }(implicitly)(p0) - assert(res0 === input0) + assert(res0 === firstExpectedResult) val res1 = Tracked.outputChanged[String, String](store) { - case (true, in) => + case (true, _) => fail() case (false, in) => - assert(in === input0) - in + assert(in === afterCompletion) + secondExpectedResult }(implicitly)(p0) - assert(res1 === input0) + assert(res1 === secondExpectedResult) + () } } @@ -136,6 +151,8 @@ class TrackedSpec extends FlatSpec { Tracked.tstamp(store) { last => assert(last === 0) } + + () } } @@ -149,6 +166,8 @@ class TrackedSpec extends FlatSpec { val difference = System.currentTimeMillis - last assert(difference < 1000) } + + () } }