vlib: fix os.exec().output usages, that may rely on trimmed lines
parent
5af6a685b8
commit
cadde3e9f0
|
@ -70,7 +70,7 @@ fn main() {
|
||||||
|
|
||||||
fn exec(s string) string {
|
fn exec(s string) string {
|
||||||
e := os.exec(s) or { panic(err) }
|
e := os.exec(s) or { panic(err) }
|
||||||
return e.output
|
return e.output.trim_right('\r\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns milliseconds
|
// returns milliseconds
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub fn run(cmd string) string {
|
||||||
}
|
}
|
||||||
verbose_trace_exec_result(x)
|
verbose_trace_exec_result(x)
|
||||||
if x.exit_code == 0 {
|
if x.exit_code == 0 {
|
||||||
return x.output
|
return x.output.trim_right('\r\n')
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,7 @@ fn (mut v Builder) cc() {
|
||||||
if v.pref.is_debug {
|
if v.pref.is_debug {
|
||||||
eword := 'error:'
|
eword := 'error:'
|
||||||
khighlight := if term.can_show_color_on_stdout() { term.red(eword) } else { eword }
|
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)
|
verror(c_error_info)
|
||||||
} else {
|
} else {
|
||||||
if res.output.len < 30 {
|
if res.output.len < 30 {
|
||||||
|
|
|
@ -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 {
|
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)
|
return error(err)
|
||||||
}
|
}
|
||||||
|
res_output := res.output.trim_right('\r\n')
|
||||||
// println('res: "$res"')
|
// 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')
|
println('Unable to find msvc version')
|
||||||
return error('Unable to find vs installation')
|
return error('Unable to find vs installation')
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ fn test_x64() {
|
||||||
mut expected := os.read_file('$dir/${test}.out') or {
|
mut expected := os.read_file('$dir/${test}.out') or {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
expected = expected.trim_space().trim('\n').replace('\r\n', '\n')
|
expected = expected.trim_right('\r\n').replace('\r\n', '\n')
|
||||||
mut found := res.output.trim_space().trim('\n').replace('\r\n', '\n')
|
mut found := res.output.trim_right('\r\n').replace('\r\n', '\n')
|
||||||
found = found.trim_space()
|
found = found.trim_space()
|
||||||
if expected != found {
|
if expected != found {
|
||||||
println(term.red('FAIL'))
|
println(term.red('FAIL'))
|
||||||
|
|
|
@ -46,11 +46,11 @@ fn test_all() {
|
||||||
// println('============')
|
// println('============')
|
||||||
// println(res.output)
|
// println(res.output)
|
||||||
// println('============')
|
// 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 {
|
mut expected := os.read_file(program.replace('.v', '') + '.out') or {
|
||||||
panic(err)
|
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 ================') {
|
if expected.contains('================ V panic ================') {
|
||||||
// panic include backtraces and absolute file paths, so can't do char by char comparison
|
// panic include backtraces and absolute file paths, so can't do char by char comparison
|
||||||
n_found := normalize_panic_message( found, vroot )
|
n_found := normalize_panic_message( found, vroot )
|
||||||
|
|
|
@ -169,7 +169,7 @@ pub fn color_compare_files(diff_cmd, file1, file2 string) string {
|
||||||
x := os.exec(full_cmd) or {
|
x := os.exec(full_cmd) or {
|
||||||
return 'comparison command: `${full_cmd}` failed'
|
return 'comparison command: `${full_cmd}` failed'
|
||||||
}
|
}
|
||||||
return x.output
|
return x.output.trim_right('\r\n')
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue