mirror of https://github.com/sbt/sbt.git
Add cache tests
This adds scripted test for cached compilation and tests.
This commit is contained in:
parent
4c0ab346a7
commit
f07fa809f5
|
|
@ -0,0 +1,2 @@
|
||||||
|
@main def main(args: String*) =
|
||||||
|
assert(args(0).toInt == A.x )
|
||||||
|
|
@ -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}")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
object A { final val x = 1 }
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
object A { final val x = 2 }
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
$ copy-file changes/A1.scala A.scala
|
||||||
|
> run 1
|
||||||
|
> checkMiss
|
||||||
|
|
||||||
|
$ copy-file changes/A2.scala A.scala
|
||||||
|
> run 2
|
||||||
|
> checkMiss
|
||||||
|
|
@ -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}")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package example
|
||||||
|
|
||||||
|
object MathFunction:
|
||||||
|
def times2(i: Int): Int = 2 * 2
|
||||||
|
end MathFunction
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package example
|
||||||
|
|
||||||
|
object MathFunction:
|
||||||
|
def times2(i: Int): Int = i * 2
|
||||||
|
end MathFunction
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package example
|
||||||
|
|
||||||
|
object MathFunctionTest extends verify.BasicTestSuite:
|
||||||
|
test("times2 should double the input"):
|
||||||
|
assert(MathFunction.times2(4) == 8)
|
||||||
|
end MathFunctionTest
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
> test
|
||||||
|
|
||||||
|
> test
|
||||||
|
> checkHit
|
||||||
|
|
||||||
|
$ copy-file changed/MathFunction.scala src/test/scala/MathFunction.scala
|
||||||
|
-> test
|
||||||
Loading…
Reference in New Issue