From 0ef1d84d6fb22a7f533afa45fd6022a87e6816d5 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Tue, 10 Sep 2024 13:08:45 -0400 Subject: [PATCH] Deal with Windows paths --- .../src/main/scala/munit/internal/console/Lines.scala | 10 ++++++++-- tests/shared/src/test/scala/munit/LinesSuite.scala | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/munit/shared/src/main/scala/munit/internal/console/Lines.scala b/munit/shared/src/main/scala/munit/internal/console/Lines.scala index 6cc97211..fffc9913 100644 --- a/munit/shared/src/main/scala/munit/internal/console/Lines.scala +++ b/munit/shared/src/main/scala/munit/internal/console/Lines.scala @@ -19,11 +19,17 @@ class Lines extends Serializable { def findPath(cwd: String, path: String, max: Int): Path = { val p = Paths.get(cwd).resolve(path) + def getParentPath(somePath: String, sep: String): String = { + val somePath1 = + if (somePath.endsWith(sep)) somePath.dropRight(sep.length) + else somePath + somePath1.split(sep).dropRight(1).mkString(sep) + } if (Files.exists(p)) p else if (max < 1) sys.error(s"$path was not found") else if (cwd.contains("\\")) - findPath(cwd.split("\\").dropRight(1).mkString("\\"), path, max - 1) - else findPath(cwd.split("/").dropRight(1).mkString("/"), path, max - 1) + findPath(getParentPath(cwd, "\\"), path, max - 1) + else findPath(getParentPath(cwd, "/"), path, max - 1) } def formatLine(location: Location, message: String, clues: Clues): String = { diff --git a/tests/shared/src/test/scala/munit/LinesSuite.scala b/tests/shared/src/test/scala/munit/LinesSuite.scala index 5bfa1cc0..59f6ef3a 100644 --- a/tests/shared/src/test/scala/munit/LinesSuite.scala +++ b/tests/shared/src/test/scala/munit/LinesSuite.scala @@ -39,6 +39,7 @@ class LinesSuite extends FunSuite { test(options) { val obtained = munitLines .formatLine(location, message) + .replace(raw"""tests\shared\src\test\scala\munit\""", "tests/shared/src/test/scala/munit/") // for Windows assertNoDiff(obtained, expected) } }