Skip to content

Commit

Permalink
Fix SbtScriptedScalaTest
Browse files Browse the repository at this point in the history
It was broken by adRise@4528e06. `executeScriptedTestsTask` just created a `Def.Intialize[Task[Unit]]`, and dropped it.
  • Loading branch information
huajiang-tubi committed Jun 20, 2024
1 parent 19d8f16 commit 224e299
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 5 additions & 0 deletions src/sbt-test/sbt-1.0/testFailure/build.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-1.0/testFailure/test
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
$ delete target/pid
> scriptedScalatest
$ exists target/pid

0 comments on commit 224e299

Please sign in to comment.