Skip to content

Commit

Permalink
Deal with Windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Sep 10, 2024
1 parent c9b63ce commit 0ef1d84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions munit/shared/src/main/scala/munit/internal/console/Lines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions tests/shared/src/test/scala/munit/LinesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 0ef1d84

Please sign in to comment.