Merge pull request #8105 from eed3si9n/wip/cache-test

[2.x] Add cache tests
This commit is contained in:
eugene yokota 2025-05-04 17:14:14 -04:00 committed by GitHub
commit 2ea0aac1bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,2 @@
@main def main(args: String*) =
assert(args(0).toInt == A.x )

View File

@ -0,0 +1,16 @@
import sbt.internal.util.CacheEventSummary
lazy val checkMiss = taskKey[Unit]("")
Global / localCacheDirectory := baseDirectory.value / "diskcache"
scalaVersion := "3.6.4"
checkMiss := {
val s = streams.value
val config = Def.cacheConfiguration.value
val prev = config.cacheEventLog.previous match
case s: CacheEventSummary.Data => s
case _ => sys.error(s"empty event log")
s.log.info(prev.missCount.toString)
assert(prev.missCount == 2, s"prev.missCount = ${prev.missCount}")
}

View File

@ -0,0 +1 @@
object A { final val x = 1 }

View File

@ -0,0 +1 @@
object A { final val x = 2 }

View File

@ -0,0 +1,7 @@
$ copy-file changes/A1.scala A.scala
> run 1
> checkMiss
$ copy-file changes/A2.scala A.scala
> run 2
> checkMiss

View File

@ -0,0 +1,19 @@
import sbt.internal.util.CacheEventSummary
lazy val checkHit = taskKey[Unit]("")
lazy val verify = "com.eed3si9n.verify" %% "verify" % "1.0.0"
Global / localCacheDirectory := baseDirectory.value / "diskcache"
scalaVersion := "3.6.4"
libraryDependencies += verify % Test
testFrameworks += new TestFramework("verify.runner.Framework")
checkHit := {
val s = streams.value
val config = Def.cacheConfiguration.value
val prev = config.cacheEventLog.previous match
case s: CacheEventSummary.Data => s
case _ => sys.error(s"empty event log")
assert(prev.missCount == 0, s"prev.missCount = ${prev.missCount}")
}

View File

@ -0,0 +1,5 @@
package example
object MathFunction:
def times2(i: Int): Int = 2 * 2
end MathFunction

View File

@ -0,0 +1,5 @@
package example
object MathFunction:
def times2(i: Int): Int = i * 2
end MathFunction

View File

@ -0,0 +1,6 @@
package example
object MathFunctionTest extends verify.BasicTestSuite:
test("times2 should double the input"):
assert(MathFunction.times2(4) == 8)
end MathFunctionTest

View File

@ -0,0 +1,7 @@
> test
> test
> checkHit
$ copy-file changed/MathFunction.scala src/test/scala/MathFunction.scala
-> test