From 7045878bcd8a7f4a38f27298efc5cd54198fb224 Mon Sep 17 00:00:00 2001 From: Mingun Date: Thu, 18 Apr 2024 19:32:37 +0500 Subject: [PATCH] Correctly strip Windows paths from error messages --- .../io/kaitai/struct/ErrorMessagesSpec.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/jvm/src/test/scala/io/kaitai/struct/ErrorMessagesSpec.scala b/jvm/src/test/scala/io/kaitai/struct/ErrorMessagesSpec.scala index 14a9794b4..164b195b9 100644 --- a/jvm/src/test/scala/io/kaitai/struct/ErrorMessagesSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/ErrorMessagesSpec.scala @@ -14,12 +14,12 @@ class ErrorMessagesSpec extends AnyFunSuite with SimpleMatchers { // version info KSVersion.current = Version.version - val FORMATS_ERR_DIR = "../tests/formats_err" + val FORMATS_ERR_DIR = new File("../tests/formats_err") val CHARSET_UTF8 = Charset.forName("UTF-8") val DEFAULT_CONFIG = CLIConfig() - def getExpected(fn: String): List[String] = { - val fis = new FileInputStream(fn) + def getExpected(f: File): List[String] = { + val fis = new FileInputStream(f) val isr = new InputStreamReader(fis, CHARSET_UTF8) val br = new BufferedReader(isr) @@ -38,23 +38,22 @@ class ErrorMessagesSpec extends AnyFunSuite with SimpleMatchers { def testOne(f: File): Unit = { val fileName = f.getName val testName = fileName.stripSuffix(".ksy") - val fn = FORMATS_ERR_DIR + "/" + fileName test(testName) { - val expected = getExpected(fn) - val (_, problems) = JavaKSYParser.localFileToSpecs(fn, DEFAULT_CONFIG) + val expected = getExpected(f) + val (_, problems) = JavaKSYParser.localFileToSpecs(f.getPath(), DEFAULT_CONFIG) val problemsStr = problems.map(problem => // replace version-dependent message with a moniker problem.message.replace( s"but you have ${KSVersion.current}", "but you have $KS_VERSION" - ).replace(FORMATS_ERR_DIR + "/", "") + ).replace(FORMATS_ERR_DIR.getPath() + File.separator, "") ) problemsStr.mkString("\n") shouldEqualPlainly expected.mkString("\n") } } - new File(FORMATS_ERR_DIR).listFiles. + FORMATS_ERR_DIR.listFiles. filter((f) => f.isFile && f.getName.endsWith(".ksy")). sorted.foreach((f) => testOne(f))