From 224e299ad7ca0e5b4c60c5b06c6c1eee7324c960 Mon Sep 17 00:00:00 2001 From: Hua Jiang Date: Thu, 20 Jun 2024 17:47:59 +0800 Subject: [PATCH] Fix SbtScriptedScalaTest It was broken by https://github.com/adRise/scripted-scalatest-sbt-plugin/commit/4528e065bfbe05f81b6a578288fc76bbde981ff0. `executeScriptedTestsTask` just created a `Def.Intialize[Task[Unit]]`, and dropped it. --- .../scalatest/SbtScriptedScalaTest.scala | 27 ++++++++++--------- src/sbt-test/sbt-1.0/testFailure/build.sbt | 5 ++++ src/sbt-test/sbt-1.0/testFailure/test | 2 ++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/scala/com/github/daniel/shuy/sbt/scripted/scalatest/SbtScriptedScalaTest.scala b/src/main/scala/com/github/daniel/shuy/sbt/scripted/scalatest/SbtScriptedScalaTest.scala index 93b9f16..8858b52 100644 --- a/src/main/scala/com/github/daniel/shuy/sbt/scripted/scalatest/SbtScriptedScalaTest.scala +++ b/src/main/scala/com/github/daniel/shuy/sbt/scripted/scalatest/SbtScriptedScalaTest.scala @@ -39,36 +39,37 @@ object SbtScriptedScalaTest extends AutoPlugin { } import autoImport._ - private[this] lazy val logger = Def.task[Logger] { - streams.value.log - } - override def projectSettings: Seq[Setting[_]] = Seq( scriptedScalaTestDurations := true, scriptedScalaTestStacks := NoStacks, scriptedScalaTestStats := true, scriptedScalaTestSpec := None, scriptedScalaTest := { + val duration = scriptedScalaTestDurations.value + val stacks = scriptedScalaTestStacks.value + val stats = scriptedScalaTestStats.value + val log = streams.value.log // do nothing if not configured scriptedScalaTestSpec.value match { - case Some(suite) => executeScriptedTestsTask(suite) + case Some(suite) => + executeScriptedTestsTask(suite, duration, stacks, stats) case None => - logger.value.warn( - s"${scriptedScalaTestSpec.key.label} not configured, no tests will be run..." - ) + log.warn(s"${scriptedScalaTestSpec.key.label} not configured, no tests will be run...") } } ) private[this] def executeScriptedTestsTask( - suite: ScriptedScalaTestSuite - ): Unit = Def.task { - val stacks = scriptedScalaTestStacks.value + suite: ScriptedScalaTestSuite, + showDuration: Boolean, + stacks: ScriptedTestStacks, + stats: Boolean, + ): Unit = { val status = suite.executeScripted( - durations = scriptedScalaTestDurations.value, + durations = showDuration, shortstacks = stacks.shortstacks, fullstacks = stacks.fullstacks, - stats = scriptedScalaTestStats.value + stats = stats ) status.waitUntilCompleted() if (!status.succeeds()) { diff --git a/src/sbt-test/sbt-1.0/testFailure/build.sbt b/src/sbt-test/sbt-1.0/testFailure/build.sbt index ebfa701..8242fae 100644 --- a/src/sbt-test/sbt-1.0/testFailure/build.sbt +++ b/src/sbt-test/sbt-1.0/testFailure/build.sbt @@ -1,3 +1,5 @@ +import scala.sys.process._ + import com.github.daniel.shuy.sbt.scripted.scalatest.ScriptedScalaTestSuiteMixin import org.scalatest.Assertions._ import org.scalatest.wordspec.AnyWordSpec @@ -23,6 +25,9 @@ lazy val testFailure = project "scripted" should { "fail on ScalaTest failure" in { + val pidFile = new File("target/pid") + (s"echo ${ProcessHandle.current.pid}" #> pidFile).!! + assertThrows[sbt.Incomplete]( Project.extract(sbtState) .runInputTask(scripted, "", sbtState)) diff --git a/src/sbt-test/sbt-1.0/testFailure/test b/src/sbt-test/sbt-1.0/testFailure/test index 57e380e..fb4759d 100644 --- a/src/sbt-test/sbt-1.0/testFailure/test +++ b/src/sbt-test/sbt-1.0/testFailure/test @@ -1 +1,3 @@ +$ delete target/pid > scriptedScalatest +$ exists target/pid