From 141d9357cc9fd7810d0c6681f871a00d74267f78 Mon Sep 17 00:00:00 2001 From: "Brian P. Holt" Date: Fri, 27 Jul 2018 11:31:58 -0500 Subject: [PATCH 1/2] invoke output value function again, after executing output effect fixes #168 --- .../src/main/scala/sbt/util/Tracked.scala | 2 +- .../src/test/scala/sbt/util/TrackedSpec.scala | 39 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/util-tracking/src/main/scala/sbt/util/Tracked.scala b/util-tracking/src/main/scala/sbt/util/Tracked.scala index cfc1d089f..e0e5c77e7 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 } diff --git a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala index 7db275d1a..f2ef1bfb0 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 { @@ -105,29 +104,41 @@ class TrackedSpec extends FlatSpec { "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) + () } } From 6f2b78b6a8ecf9f750814367613b0c1d3d4d096b Mon Sep 17 00:00:00 2001 From: "Brian P. Holt" Date: Fri, 27 Jul 2018 11:35:26 -0500 Subject: [PATCH 2/2] clean up compiler warnings in util-tracking --- .../src/main/scala/sbt/util/Tracked.scala | 2 +- .../src/test/scala/sbt/util/TrackedSpec.scala | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/util-tracking/src/main/scala/sbt/util/Tracked.scala b/util-tracking/src/main/scala/sbt/util/Tracked.scala index e0e5c77e7..c6286a832 100644 --- a/util-tracking/src/main/scala/sbt/util/Tracked.scala +++ b/util-tracking/src/main/scala/sbt/util/Tracked.scala @@ -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 f2ef1bfb0..8f88cc53a 100644 --- a/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala +++ b/util-tracking/src/test/scala/sbt/util/TrackedSpec.scala @@ -18,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) @@ -36,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) @@ -44,6 +44,8 @@ class TrackedSpec extends FlatSpec { read }(implicitly)(otherValue) assert(res2 === value) + + () } } @@ -56,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) @@ -71,6 +73,7 @@ class TrackedSpec extends FlatSpec { }(implicitly, implicitly)(input0) assert(res1 === input0) + () } } @@ -84,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) @@ -94,11 +97,12 @@ class TrackedSpec extends FlatSpec { case (true, in) => assert(in === input1) in - case (false, in) => + case (false, _) => fail() }(implicitly, implicitly)(input1) assert(res1 === input1) + () } } @@ -147,6 +151,8 @@ class TrackedSpec extends FlatSpec { Tracked.tstamp(store) { last => assert(last === 0) } + + () } } @@ -160,6 +166,8 @@ class TrackedSpec extends FlatSpec { val difference = System.currentTimeMillis - last assert(difference < 1000) } + + () } }