mirror of https://github.com/sbt/sbt.git
This PR adds a new scripted test `watch-termination-reload` to prevent regression of the fix in PR #7838. The test verifies that the `Reload` action is correctly passed to the `watchOnTermination` callback when a reload is triggered in watch mode, instead of falling back to `CancelWatch` (which was the root cause of issue #7017).
This commit is contained in:
parent
6493707d2f
commit
d2cd284e5e
|
|
@ -0,0 +1,43 @@
|
|||
package sbt.watch.termination.reload
|
||||
|
||||
import sbt._
|
||||
import Keys._
|
||||
import sbt.nio.Keys._
|
||||
import sbt.nio.Watch
|
||||
|
||||
object Build {
|
||||
val checkTerminationAction = inputKey[Unit]("Check that watchOnTermination received the expected action")
|
||||
val checkTerminationActionImpl: Def.Initialize[InputTask[Unit]] = Def.inputTask {
|
||||
val Seq(expectedAction) = Def.spaceDelimited().parsed
|
||||
val logFile = baseDirectory.value / "action-log.txt"
|
||||
val loggedAction = IO.read(logFile).trim
|
||||
assert(loggedAction == expectedAction, s"Expected action '$expectedAction', but got '$loggedAction'")
|
||||
}
|
||||
|
||||
lazy val root = (project in file(".")).settings(
|
||||
checkTerminationAction := checkTerminationActionImpl.evaluated,
|
||||
watchOnTermination := { (count: Int, action: Watch.Action) =>
|
||||
if (action == Watch.Reload) {
|
||||
val logFile = baseDirectory.value / "action-log.txt"
|
||||
IO.write(logFile, action.toString)
|
||||
}
|
||||
},
|
||||
watchOnFileInputEvent := { (count: Int, event: Watch.Event) =>
|
||||
if (event.path.getFileName.toString == "trigger.txt") {
|
||||
val flagFile = baseDirectory.value / "triggered.txt"
|
||||
if (!flagFile.exists) {
|
||||
IO.write(flagFile, "true")
|
||||
Watch.Reload
|
||||
} else {
|
||||
Watch.CancelWatch
|
||||
}
|
||||
} else Watch.Ignore
|
||||
},
|
||||
watchSources += baseDirectory.value / "trigger.txt",
|
||||
Compile / compile := {
|
||||
val trigger = baseDirectory.value / "trigger.txt"
|
||||
IO.write(trigger, System.currentTimeMillis.toString)
|
||||
(Compile / compile).value
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Test {
|
||||
// Minimal source to enable ~compile in watch mode
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# Start watch mode with ~compile, which triggers file modification and reload
|
||||
> ~compile
|
||||
# Check that watchOnTermination received Reload action
|
||||
> checkTerminationAction Reload
|
||||
Loading…
Reference in New Issue