Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ErrorMessagesSpec: fix broken tests on Windows
In 2b84e0a, I reverted a previous change that was replacing all backslashes `\` to forward slashes `/` in file paths used in error messages (meaning that backslashes are kept since then if present in input paths). However, until now I didn't notice that this broke `ErrorMessagesSpec` tests on Windows. This is because compile error messages actually include the full path to the `.ksy` spec, for example: ``` ../tests/formats_err/attr_bad_size.ksy: /seq/0/size: error: invalid type: expected integer, got CalcStrType ``` However, in `formats_err` specs, only the base name is specified (see https://github.com/kaitai-io/kaitai_struct_tests/blob/73486eef/formats_err/attr_bad_size.ksy below): ``` # attr_bad_size.ksy: /seq/0/size: # error: invalid type: expected integer, got CalcStrType # meta: id: attr_bad_size seq: # ... ``` The `../tests/formats_err/` prefix in the actual message is supposed to be removed by `.replace(FORMATS_ERR_DIR + "/", "")` in `ErrorMessagesSpec` (line 53). Note that the string to be removed always uses forward slashes `/`. The problem is that on Windows, `f.toString` (which returns a file path with the backslash `\` as name separator - this is explained at kaitai-io/kaitai_struct#507 (comment)) is passed to the compiler as the .ksy spec to process. Since the path normalization (i.e. `\` -> `/` conversion) was removed, error messages will start like `..\tests\formats_err\attr_bad_size.ksy: ...`. This means the `.replace(FORMATS_ERR_DIR + "/", "")` call won't do anything, because it looks for ``../tests/formats_err/`, which is not there. The fix is to pass forward slash `/` paths to the compiler even on Windows.
- Loading branch information