From e621ebe678c5d568e4035855b1f0958d4e7b2c3a Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Thu, 15 Aug 2019 17:07:24 -0700 Subject: [PATCH] Ensure correct scripted plugin implementation exists When running the scripted tests on my vm, I noticed that one of the watch tests warned that the InstrumentScripted.scala file had changed after the project had initialized. The test then hung and I had to kill it. To try and prevent this from happening, I moved the creation of the plugin file to right before the call to ";reload;setUpScripted". --- .../main/scala/sbt/scriptedtest/ScriptedTests.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala index c5080006c..f83f02093 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala @@ -19,12 +19,14 @@ import scala.collection.parallel.ForkJoinTaskSupport import scala.util.control.NonFatal import sbt.internal.scripted._ import sbt.internal.io.Resources -import sbt.internal.util.{ BufferedLogger, FullLogger, ConsoleOut } +import sbt.internal.util.{ BufferedLogger, ConsoleOut, FullLogger } import sbt.io.syntax._ import sbt.io.{ DirectoryFilter, HiddenFileFilter, IO } import sbt.io.FileFilter._ import sbt.util.{ AbstractLogger, Level, Logger } +import scala.util.Try + final class ScriptedTests( resourceBaseDirectory: File, bufferLog: Boolean, @@ -325,7 +327,8 @@ final class ScriptedTests( val runTest = () => { // Reload and initialize (to reload contents of .sbtrc files) val pluginImplementation = createAutoPlugin(name) - IO.write(tempTestDir / "project" / "InstrumentScripted.scala", pluginImplementation) + val pluginFile = tempTestDir / "project" / "InstrumentScripted.scala" + IO.write(pluginFile, pluginImplementation) def sbtHandlerError = sys error "Missing sbt handler. Scripted is misconfigured." val sbtHandler = handlers.getOrElse('>', sbtHandlerError) val commandsToRun = ";reload;setUpScripted" @@ -334,6 +337,9 @@ final class ScriptedTests( // Run reload inside the hook to reuse error handling for pending tests val wrapHook = (file: File) => { preHook(file) + while (!Try(IO.read(pluginFile)).toOption.contains(pluginImplementation)) { + IO.write(pluginFile, pluginImplementation) + } try runner.processStatement(sbtHandler, statement, states) catch { case t: Throwable =>