test: Migrate CacheSpec to verify.BasicTestSuite (#8474)

Migrate CacheSpec from ScalaTest AnyFlatSpec to verify.BasicTestSuite
following the project's test framework standardization.

Changes:
- Convert class to object extending BasicTestSuite
- Replace ScalaTest 'should/in' syntax with test() method
- Replace fail() with assert(false, message)
- Replace === with ==
- Use Scala 3 indentation-based syntax
- Remove ScalaTest import, add verify.BasicTestSuite import

All tests pass successfully.

Fixes #8466

Generated-by: Cascade (AI pair programmer)
This commit is contained in:
MkDev11 2026-01-11 04:19:22 -08:00 committed by GitHub
parent bbeeb25422
commit db06acb31e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 32 deletions

View File

@ -10,61 +10,50 @@ package sbt.util
import sbt.io.IO
import sbt.io.syntax.*
import verify.BasicTestSuite
import CacheImplicits.given
import org.scalatest.flatspec.AnyFlatSpec
object CacheSpec extends BasicTestSuite:
class CacheSpec extends AnyFlatSpec {
"A cache" should "NOT throw an exception if read without being written previously" in {
test("A cache should NOT throw an exception if read without being written previously"):
testCache[String, Int] { (cache, store) =>
cache(store)("missing") match {
case Hit(_) => fail()
cache(store)("missing") match
case Hit(_) => assert(false, "Expected Miss but got Hit")
case Miss(_) => ()
}
}
}
it should "write a very simple value" in {
test("A cache should write a very simple value"):
testCache[String, Int] { (cache, store) =>
cache(store)("missing") match {
case Hit(_) => fail()
cache(store)("missing") match
case Hit(_) => assert(false, "Expected Miss but got Hit")
case Miss(update) => update(5)
}
}
}
it should "be updatable" in {
test("A cache should be updatable"):
testCache[String, Int] { (cache, store) =>
val value = 5
cache(store)("someKey") match {
case Hit(_) => fail()
cache(store)("someKey") match
case Hit(_) => assert(false, "Expected Miss but got Hit")
case Miss(update) => update(value)
}
cache(store)("someKey") match {
case Hit(read) => assert(read === value); ()
case Miss(_) => fail()
}
cache(store)("someKey") match
case Hit(read) => assert(read == value)
case Miss(_) => assert(false, "Expected Hit but got Miss")
}
}
it should "return the value that has been previously written" in {
test("A cache should return the value that has been previously written"):
testCache[String, Int] { (cache, store) =>
val key = "someKey"
val value = 5
cache(store)(key) match {
case Hit(_) => fail()
cache(store)(key) match
case Hit(_) => assert(false, "Expected Miss but got Hit")
case Miss(update) => update(value)
}
cache(store)(key) match {
case Hit(read) => assert(read === value); ()
case Miss(_) => fail()
}
cache(store)(key) match
case Hit(read) => assert(read == value)
case Miss(_) => assert(false, "Expected Hit but got Miss")
}
}
private def testCache[K, V](f: (Cache[K, V], CacheStore) => Unit)(using
cache: Cache[K, V]
@ -74,4 +63,4 @@ class CacheSpec extends AnyFlatSpec {
f(cache, store)
}
}
end CacheSpec