From cadde3e9f09226e0f8749aceb06fcf93e438f086 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 15 Jun 2020 15:16:37 +0300 Subject: [PATCH] vlib: fix os.exec().output usages, that may rely on trimmed lines --- cmd/tools/fast/fast.v | 2 +- cmd/tools/modules/scripting/scripting.v | 2 +- vlib/v/builder/cc.v | 2 +- vlib/v/builder/msvc.v | 3 ++- vlib/v/gen/x64/tests/x64_test.v | 4 ++-- vlib/v/tests/inout/compiler_test.v | 4 ++-- vlib/v/util/errors.v | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 35ca11ea27..e4e48fd9f3 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -70,7 +70,7 @@ fn main() { fn exec(s string) string { e := os.exec(s) or { panic(err) } - return e.output + return e.output.trim_right('\r\n') } // returns milliseconds diff --git a/cmd/tools/modules/scripting/scripting.v b/cmd/tools/modules/scripting/scripting.v index 1e23175c47..3cd8bdba95 100644 --- a/cmd/tools/modules/scripting/scripting.v +++ b/cmd/tools/modules/scripting/scripting.v @@ -58,7 +58,7 @@ pub fn run(cmd string) string { } verbose_trace_exec_result(x) if x.exit_code == 0 { - return x.output + return x.output.trim_right('\r\n') } return '' } diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 682748f40e..113ff0a80b 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -403,7 +403,7 @@ fn (mut v Builder) cc() { if v.pref.is_debug { eword := 'error:' khighlight := if term.can_show_color_on_stdout() { term.red(eword) } else { eword } - println(res.output.replace(eword, khighlight)) + println(res.output.trim_right('\r\n').replace(eword, khighlight)) verror(c_error_info) } else { if res.output.len < 30 { diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index c592d4693d..8d23ac2879 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -138,8 +138,9 @@ fn find_vs(vswhere_dir, host_arch string) ?VsInstallation { res := os.exec('"$vswhere_dir\\Microsoft Visual Studio\\Installer\\vswhere.exe" -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') or { return error(err) } + res_output := res.output.trim_right('\r\n') // println('res: "$res"') - version := os.read_file('$res.output\\VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt') or { + version := os.read_file('$res_output\\VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt') or { println('Unable to find msvc version') return error('Unable to find vs installation') } diff --git a/vlib/v/gen/x64/tests/x64_test.v b/vlib/v/gen/x64/tests/x64_test.v index 6ff28606de..45fcc48106 100644 --- a/vlib/v/gen/x64/tests/x64_test.v +++ b/vlib/v/gen/x64/tests/x64_test.v @@ -48,8 +48,8 @@ fn test_x64() { mut expected := os.read_file('$dir/${test}.out') or { panic(err) } - expected = expected.trim_space().trim('\n').replace('\r\n', '\n') - mut found := res.output.trim_space().trim('\n').replace('\r\n', '\n') + expected = expected.trim_right('\r\n').replace('\r\n', '\n') + mut found := res.output.trim_right('\r\n').replace('\r\n', '\n') found = found.trim_space() if expected != found { println(term.red('FAIL')) diff --git a/vlib/v/tests/inout/compiler_test.v b/vlib/v/tests/inout/compiler_test.v index 98fda6917d..a84d7b3d90 100644 --- a/vlib/v/tests/inout/compiler_test.v +++ b/vlib/v/tests/inout/compiler_test.v @@ -46,11 +46,11 @@ fn test_all() { // println('============') // println(res.output) // println('============') - mut found := res.output.trim_space().trim('\n').replace('\r\n', '\n') + mut found := res.output.trim_right('\r\n').replace('\r\n', '\n') mut expected := os.read_file(program.replace('.v', '') + '.out') or { panic(err) } - expected = expected.trim_space().trim('\n').replace('\r\n', '\n') + expected = expected.trim_right('\r\n').replace('\r\n', '\n') if expected.contains('================ V panic ================') { // panic include backtraces and absolute file paths, so can't do char by char comparison n_found := normalize_panic_message( found, vroot ) diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index 181f4ac175..4725fd5c83 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -169,7 +169,7 @@ pub fn color_compare_files(diff_cmd, file1, file2 string) string { x := os.exec(full_cmd) or { return 'comparison command: `${full_cmd}` failed' } - return x.output + return x.output.trim_right('\r\n') } return '' }