Skip to content

Commit e5deeb2

Browse files
committed
Fix errors tied to munit 1.0.2 location paths changing from absolute to relative
1 parent 8f91e6c commit e5deeb2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

modules/build/src/test/scala/scala/build/tests/TestUtil.scala

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@ import java.util.concurrent.TimeUnit
88
import scala.concurrent.duration.FiniteDuration
99

1010
object TestUtil {
11+
1112
abstract class ScalaCliBuildSuite extends munit.FunSuite {
13+
extension (munitContext: BeforeEach | AfterEach) {
14+
def locationAbsolutePath: os.Path =
15+
os.pwd / os.RelPath {
16+
(munitContext match {
17+
case beforeEach: BeforeEach => beforeEach.test
18+
case afterEach: AfterEach => afterEach.test
19+
}).location.path
20+
}
21+
}
1222
override def munitTimeout = new FiniteDuration(120, TimeUnit.SECONDS)
1323
val testStartEndLogger = new Fixture[Unit]("files") {
1424
def apply(): Unit = ()
1525

1626
override def beforeEach(context: BeforeEach): Unit = {
17-
val fileName = os.Path(context.test.location.path).baseName
27+
val fileName = context.locationAbsolutePath.baseName
1828
System.err.println(
1929
s">==== ${Console.CYAN}Running '${context.test.name}' from $fileName${Console.RESET}"
2030
)
2131
}
2232

2333
override def afterEach(context: AfterEach): Unit = {
24-
val fileName = os.Path(context.test.location.path).baseName
34+
val fileName = context.locationAbsolutePath.baseName
2535
System.err.println(
2636
s"X==== ${Console.CYAN}Finishing '${context.test.name}' from $fileName${Console.RESET}"
2737
)

modules/integration/src/test/scala/scala/cli/integration/ScalaCliSuite.scala

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ import java.util.concurrent.TimeUnit
55
import scala.concurrent.duration.{Duration, FiniteDuration}
66

77
abstract class ScalaCliSuite extends munit.FunSuite {
8-
val testStartEndLogger = new Fixture[Unit]("files") {
8+
implicit class BeforeEachOpts(munitContext: BeforeEach) {
9+
def locationAbsolutePath: os.Path = os.pwd / os.RelPath(munitContext.test.location.path)
10+
}
11+
12+
implicit class AfterEachOpts(munitContext: AfterEach) {
13+
def locationAbsolutePath: os.Path = os.pwd / os.RelPath(munitContext.test.location.path)
14+
}
15+
val testStartEndLogger: Fixture[Unit] = new Fixture[Unit]("files") {
916
def apply(): Unit = ()
1017

1118
override def beforeEach(context: BeforeEach): Unit = {
12-
val fileName = os.Path(context.test.location.path).baseName
19+
val fileName = context.locationAbsolutePath.baseName
1320
System.err.println(
1421
s">==== ${Console.CYAN}Running '${context.test.name}' from $fileName${Console.RESET}"
1522
)
1623
}
1724

1825
override def afterEach(context: AfterEach): Unit = {
19-
val fileName = os.Path(context.test.location.path).baseName
26+
val fileName = context.locationAbsolutePath.baseName
2027
System.err.println(
2128
s"X==== ${Console.CYAN}Finishing '${context.test.name}' from $fileName${Console.RESET}"
2229
)

0 commit comments

Comments
 (0)