From a054f868a075f8b938eaf0f71fdd34ea57481183 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 4 Feb 2022 17:56:02 +0200 Subject: [PATCH] v.util: use a normalised relative file path in the error messages with /, even on windows, to make the compiler error tests more robust --- vlib/v/util/errors.v | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index 008cc43349..c278fc8678 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -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, '') } } //