Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly strip Windows paths from error messages #304

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions jvm/src/test/scala/io/kaitai/struct/ErrorMessagesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I think it will be meaningful to pass File object to localFileToSpecs, but that method is called also in test generator in https://github.com/kaitai-io/kaitai_struct_tests repository, so I doesn't touch it yet.

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))

Expand Down
Loading