[2.x] test: Add test for Test/baseDirectory (#9544)

This commit is contained in:
eugene yokota 2026-08-03 03:32:19 -04:00 committed by GitHub
parent 731e666603
commit 67faa44a1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 19 deletions

View File

@ -4,18 +4,18 @@ import Defaults._
val groupSize = 3
val groups = 3
@transient
val check = TaskKey[Unit]("check", "Check all files were created and remove them.")
val scalatest = "org.scalatest" %% "scalatest" % "3.0.5"
val scalaxml = "org.scala-lang.modules" %% "scala-xml" % "1.1.1"
val munit = "org.scalameta" %% "munit" % "1.0.4"
def groupId(idx: Int) = "group_" + (idx + 1)
def groupPrefix(idx: Int) = groupId(idx) + "_file_"
Global / localCacheDirectory := baseDirectory.value / "diskcache"
ThisBuild / scalaVersion := "2.12.21"
ThisBuild / organization := "org.example"
scalaVersion := "3.8.4"
organization := "com.example"
lazy val root = (project in file("."))
lazy val root = rootProject
.settings(
Test / testGrouping := Def.uncached {
val tests = (Test / definedTests).value
@ -38,7 +38,15 @@ lazy val root = (project in file("."))
},
concurrentRestrictions := Tags.limit(Tags.ForkedTestGroup, 2) :: Nil,
libraryDependencies ++= List(
scalaxml,
scalatest % Test
munit % Test
)
)
lazy val core = project
.settings(
Test / fork := true,
libraryDependencies ++= List(
munit % Test
),
Test / baseDirectory := (LocalRootProject / baseDirectory).value,
)

View File

@ -0,0 +1,10 @@
import java.io.File
import munit.FunSuite
class FileTest extends FunSuite:
test("test baseDirectory") {
val x = new File("foo").getAbsoluteFile().getParentFile()
assert(x.getName() != "core", s"actual ${x.getName()}")
}
end FileTest

View File

@ -1,16 +1,17 @@
import org.scalatest.FlatSpec
import java.io.File
trait Ensemble extends FlatSpec {
def i: Int
def prefix = System.getProperty("group.prefix")
import munit.FunSuite
"an ensemble" should "create all files" in {
val f = new File(prefix + i)
f.createNewFile
}
}
trait Ensemble extends FunSuite:
def i: Int
def prefix = System.getProperty("group.prefix")
test("an ensemble should create all files") {
val f = new File(prefix + i)
f.createNewFile
}
end Ensemble
class Ensemble1 extends Ensemble { def i = 1 }
class Ensemble2 extends Ensemble { def i = 2 }
class Ensemble3 extends Ensemble { def i = 3 }
class Ensemble3 extends Ensemble { def i = 3 }

View File

@ -1,2 +1,4 @@
> test
> check
> testFull
> check
> core/testFull