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) 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, '')
} }
} }
// //