vlib: fix os.exec().output usages, that may rely on trimmed lines

pull/5389/head
Delyan Angelov 2020-06-15 15:16:37 +03:00
parent 5af6a685b8
commit cadde3e9f0
7 changed files with 10 additions and 9 deletions

View File

@ -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

View File

@ -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 ''
}

View File

@ -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 {

View File

@ -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')
}

View File

@ -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'))

View File

@ -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 )

View File

@ -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 ''
}