[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 groupSize = 3
val groups = 3 val groups = 3
@transient
val check = TaskKey[Unit]("check", "Check all files were created and remove them.") val check = TaskKey[Unit]("check", "Check all files were created and remove them.")
val scalatest = "org.scalatest" %% "scalatest" % "3.0.5" val munit = "org.scalameta" %% "munit" % "1.0.4"
val scalaxml = "org.scala-lang.modules" %% "scala-xml" % "1.1.1"
def groupId(idx: Int) = "group_" + (idx + 1) def groupId(idx: Int) = "group_" + (idx + 1)
def groupPrefix(idx: Int) = groupId(idx) + "_file_" def groupPrefix(idx: Int) = groupId(idx) + "_file_"
Global / localCacheDirectory := baseDirectory.value / "diskcache" Global / localCacheDirectory := baseDirectory.value / "diskcache"
ThisBuild / scalaVersion := "2.12.21" scalaVersion := "3.8.4"
ThisBuild / organization := "org.example" organization := "com.example"
lazy val root = (project in file(".")) lazy val root = rootProject
.settings( .settings(
Test / testGrouping := Def.uncached { Test / testGrouping := Def.uncached {
val tests = (Test / definedTests).value val tests = (Test / definedTests).value
@ -38,7 +38,15 @@ lazy val root = (project in file("."))
}, },
concurrentRestrictions := Tags.limit(Tags.ForkedTestGroup, 2) :: Nil, concurrentRestrictions := Tags.limit(Tags.ForkedTestGroup, 2) :: Nil,
libraryDependencies ++= List( libraryDependencies ++= List(
scalaxml, munit % Test
scalatest % 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,15 +1,16 @@
import org.scalatest.FlatSpec
import java.io.File import java.io.File
trait Ensemble extends FlatSpec { import munit.FunSuite
def i: Int
def prefix = System.getProperty("group.prefix")
"an ensemble" should "create all files" in { trait Ensemble extends FunSuite:
val f = new File(prefix + i) def i: Int
f.createNewFile 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 Ensemble1 extends Ensemble { def i = 1 }
class Ensemble2 extends Ensemble { def i = 2 } class Ensemble2 extends Ensemble { def i = 2 }

View File

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