Skip to content

Commit

Permalink
build(sbt): use taskDyn for stryker task (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-vrijswijk authored Jan 8, 2024
1 parent 670aef7 commit e1b6912
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ object ReporterStub {
val onRunFinishedCallsRef = Ref.unsafe[IO, Seq[FinishedRunEvent]](Seq.empty)
new ReporterStub {

def mutantTestedCalls: IO[Seq[MutantTestedEvent]] = mutantTestedCallsRef.get
def onRunFinishedCalls: IO[Seq[FinishedRunEvent]] = onRunFinishedCallsRef.get
def mutantTestedCalls: IO[Seq[MutantTestedEvent]] = IO.cede *> mutantTestedCallsRef.get
def onRunFinishedCalls: IO[Seq[FinishedRunEvent]] = IO.cede *> onRunFinishedCallsRef.get

override def mutantTested: Pipe[IO, MutantTestedEvent, Nothing] =
_.evalMap(in => mutantTestedCallsRef.update(_ :+ in)).drain
override def onRunFinished(runReport: FinishedRunEvent): IO[Unit] = onRunFinishedCallsRef.update(_ :+ runReport)
_.evalMap(in => mutantTestedCallsRef.update(_ :+ in) *> IO.cede).drain
override def onRunFinished(runReport: FinishedRunEvent): IO[Unit] =
onRunFinishedCallsRef.update(_ :+ runReport) *> IO.cede
}
}

Expand Down
36 changes: 20 additions & 16 deletions modules/sbt/src/main/scala/stryker4s/sbt/Stryker4sMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@ object Stryker4sMain extends AutoPlugin {
.matches(VersionNumber(sbtVersion.value))
)

lazy val strykerTask = Def.task {
lazy val strykerTask = Def.taskDyn {
// Call logLevel so it shows up as a used setting when set
val _ = (stryker / logLevel).value
val sbtLog = streams.value.log

if (!strykerIsSupported.value) {
throw new UnsupportedSbtVersionException(
s"Sbt version ${sbtVersion.value} is not supported by Stryker4s. Please upgrade to a later version. The lowest supported version is ${strykerMinimumSbtVersion.value}. If you know what you are doing you can override this with the 'strykerIsSupported' sbt setting."
)
}
// Call logLevel so it shows up as a used setting when set
val _ = (stryker / logLevel).value

implicit val runtime: IORuntime = IORuntime.global
implicit val logger: Logger = new SbtLogger(streams.value.log)
Def.task {
implicit val runtime: IORuntime = IORuntime.global
implicit val logger: Logger = new SbtLogger(sbtLog)

val sources =
Seq((Compile / scalaSource).value, (Compile / javaSource).value).map(_.toPath()).map(file.Path.fromNioPath)
val targetPath = file.Path.fromNioPath(target.value.toPath())
val sources =
Seq((Compile / scalaSource).value, (Compile / javaSource).value).map(_.toPath()).map(file.Path.fromNioPath)
val targetPath = file.Path.fromNioPath(target.value.toPath())

Deferred[IO, FiniteDuration] // Create shared timeout between testrunners
.map(new Stryker4sSbtRunner(state.value, _, sources, targetPath))
.flatMap(_.run())
.map {
case ErrorStatus => throw new MessageOnlyException("Mutation score is below configured threshold")
case _ => ()
}
.unsafeRunSync()
Deferred[IO, FiniteDuration] // Create shared timeout between testrunners
.map(new Stryker4sSbtRunner(state.value, _, sources, targetPath))
.flatMap(_.run())
.map {
case ErrorStatus => throw new MessageOnlyException("Mutation score is below configured threshold")
case _ => ()
}
.unsafeRunSync()
}
}

private class UnsupportedSbtVersionException(s: String)
Expand Down

0 comments on commit e1b6912

Please sign in to comment.