v.util: use a normalised relative file path in the error messages with /, even on windows, to make the compiler error tests more robust
parent
d02c0636d8
commit
a054f868a0
|
@ -68,6 +68,8 @@ fn color(kind string, msg string) string {
|
||||||
return term.magenta(msg)
|
return term.magenta(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/'
|
||||||
|
|
||||||
// formatted_error - `kind` may be 'error' or 'warn'
|
// formatted_error - `kind` may be 'error' or 'warn'
|
||||||
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
|
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
|
||||||
emsg := omsg.replace('main.', '')
|
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' {
|
if verror_paths_override == 'absolute' {
|
||||||
path = os.real_path(path)
|
path = os.real_path(path)
|
||||||
} else {
|
} else {
|
||||||
// Get relative path
|
// always use `/` in the error paths, to ensure the compiler output does not vary in the tests:
|
||||||
workdir := os.getwd() + os.path_separator
|
path = path.replace('\\', '/')
|
||||||
if path.starts_with(workdir) {
|
if path.starts_with(util.normalised_workdir) {
|
||||||
path = path.replace(workdir, '')
|
// Get a relative path to the compiler's workdir, when possible:
|
||||||
|
path = path.replace_once(util.normalised_workdir, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue