1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.util: use a normalised relative file path in the error messages with /, even on windows, to make the compiler error tests more robust

This commit is contained in:
Delyan Angelov 2022-02-04 17:56:02 +02:00
parent d02c0636d8
commit a054f868a0
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -68,6 +68,8 @@ fn color(kind string, msg string) string {
return term.magenta(msg)
}
const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/'
// formatted_error - `kind` may be 'error' or 'warn'
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
emsg := omsg.replace('main.', '')
@ -76,10 +78,11 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos)
if verror_paths_override == 'absolute' {
path = os.real_path(path)
} else {
// Get relative path
workdir := os.getwd() + os.path_separator
if path.starts_with(workdir) {
path = path.replace(workdir, '')
// always use `/` in the error paths, to ensure the compiler output does not vary in the tests:
path = path.replace('\\', '/')
if path.starts_with(util.normalised_workdir) {
// Get a relative path to the compiler's workdir, when possible:
path = path.replace_once(util.normalised_workdir, '')
}
}
//