Skip to content

Commit

Permalink
Add extraTestDigests key
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Sep 12, 2024
1 parent 2917780 commit e9c0410
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion main/src/main/scala/sbt/Defaults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ object Defaults extends BuildCommon {
testListeners :== Nil,
testOptions :== Nil,
testResultLogger :== TestResultLogger.Default,
testOnly / testFilter :== (IncrementalTest.selectedFilter _)
testOnly / testFilter :== (IncrementalTest.selectedFilter _),
extraTestDigests :== Nil,
)
)
lazy val testTasks: Seq[Setting[_]] =
Expand All @@ -1333,6 +1334,7 @@ object Defaults extends BuildCommon {
.triggeredBy(compile)
.value,
testQuick / testFilter := IncrementalTest.filterTask.value,
extraTestDigests ++= IncrementalTest.extraTestDigestsTask.value,
executeTests := {
import sbt.TupleSyntax.*
(
Expand Down
1 change: 1 addition & 0 deletions main/src/main/scala/sbt/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ object Keys {
val testResultLogger = settingKey[TestResultLogger]("Logs results after a test task completes.").withRank(DTask)
val testGrouping = taskKey[Seq[Tests.Group]]("Collects discovered tests into groups. Whether to fork and the options for forking are configurable on a per-group basis.").withRank(BMinusTask)
val isModule = AttributeKey[Boolean]("isModule", "True if the target is a module.", DSetting)
val extraTestDigests = taskKey[Seq[Digest]]("Extra digests that would invalidate test caching").withRank(DTask)

// Classpath/Dependency Management Keys
type Classpath = Def.Classpath
Expand Down
22 changes: 11 additions & 11 deletions main/src/main/scala/sbt/internal/IncrementalTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package internal

import java.io.File
import java.util.concurrent.ConcurrentHashMap
import Keys.{ test, compileInputs, fileConverter, fullClasspath, streams }
import Keys.{ test, fileConverter, fullClasspath, streams }
import sbt.Def.Initialize
import sbt.internal.inc.Analysis
import sbt.internal.util.Attributed
Expand Down Expand Up @@ -49,16 +49,7 @@ object IncrementalTest:
val cp = (Keys.test / fullClasspath).value
val testNames = Keys.definedTests.value.map(_.name).toVector.distinct
val converter = fileConverter.value
val sv = Keys.scalaVersion.value
val inputs = (Keys.compile / Keys.compileInputs).value
// by default this captures JVM version
val extraInc = Keys.extraIncOptions.value
// throw in any information useful for runtime invalidation
val salt = s"""$sv
${converter.toVirtualFile(inputs.options.classesDirectory)}
${extraInc.mkString(",")}
"""
val extra = Vector(Digest.sha256Hash(salt.getBytes("UTF-8")))
val extra = Keys.extraTestDigests.value
val stamper = ClassStamper(cp, converter)
// TODO: Potentially do something about JUnit 5 and others which might not use class name
Map((testNames.flatMap: name =>
Expand All @@ -68,6 +59,15 @@ ${extraInc.mkString(",")}
): _*)
}

def extraTestDigestsTask: Initialize[Task[Seq[Digest]]] = Def.cachedTask {
// by default this captures JVM version
val extraInc = Keys.extraIncOptions.value
// throw in any information useful for runtime invalidation
val salt = s"""${extraInc.mkString(",")}
"""
Vector(Digest.sha256Hash(salt.getBytes("UTF-8")))
}

def selectedFilter(args: Seq[String]): Seq[String => Boolean] =
def matches(nfs: Seq[NameFilter], s: String) = nfs.exists(_.accept(s))
val (excludeArgs, includeArgs) = args.partition(_.startsWith("-"))
Expand Down

0 comments on commit e9c0410

Please sign in to comment.