Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SbtScriptedScalaTest #39

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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