From 33e4dc3ad39ea1cff75f6667d515a46be2ff32c9 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 31 Jul 2021 14:40:58 +0300 Subject: [PATCH] ci: fix coutput_test.v on windows by fixing `-o -` on windows --- vlib/v/builder/cc.v | 2 +- vlib/v/builder/compile.v | 2 +- vlib/v/gen/c/coutput_test.v | 33 +++++++++------------------------ vlib/v/pref/pref.v | 4 ++++ 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index b537e3ae76..95f77ab88e 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -479,7 +479,7 @@ fn (mut v Builder) cc() { } return } - if v.pref.out_name.ends_with('/-') { + if v.pref.should_output_to_stdout() { // output to stdout content := os.read_file(v.out_name_c) or { panic(err) } println(content) diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index 7128b13d01..2c2c02050c 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -107,7 +107,7 @@ fn (mut b Builder) run_compiled_executable_and_exit() { if b.pref.only_check_syntax { return } - if b.pref.out_name.ends_with('/-') { + if b.pref.should_output_to_stdout() { return } if b.pref.os == .ios { diff --git a/vlib/v/gen/c/coutput_test.v b/vlib/v/gen/c/coutput_test.v index 8563a6b3e9..516dc374fd 100644 --- a/vlib/v/gen/c/coutput_test.v +++ b/vlib/v/gen/c/coutput_test.v @@ -12,15 +12,7 @@ const testdata_folder = os.join_path(vroot, 'vlib', 'v', 'gen', 'c', 'testdata') const diff_cmd = diff.find_working_diff_command() or { '' } -fn test_windows() ? { - $if windows { - eprintln('this test can not run on windows for now') - exit(0) - } -} - fn test_out_files() ? { - eprintln('> vroot: $vroot') println(term.colorize(term.green, '> testing whether .out files match:')) os.chdir(vroot) output_path := os.join_path(os.temp_dir(), 'coutput', 'out') @@ -41,7 +33,7 @@ fn test_out_files() ? { print(term.colorize(term.magenta, 'v run $relpath') + ' == ' + term.colorize(term.magenta, out_relpath) + ' ') pexe := os.join_path(output_path, '${basename}.exe') - compilation := os.execute('VCOLORS=never $vexe -o $pexe $path') + compilation := os.execute('$vexe -o $pexe $path') ensure_compilation_succeeded(compilation) res := os.execute(pexe) if res.exit_code < 0 { @@ -108,7 +100,7 @@ fn test_c_must_have_files() ? { basename, path, relpath, must_have_relpath := target2paths(must_have_path, '.c.must_have') print(term.colorize(term.magenta, 'v -o - $relpath') + ' matches all line paterns in ' + term.colorize(term.magenta, must_have_relpath) + ' ') - compilation := os.execute('VCOLORS=never $vexe -o - $path') + compilation := os.execute('$vexe -o - $path') ensure_compilation_succeeded(compilation) expected_lines := os.read_lines(must_have_path) or { [] } generated_c_lines := compilation.output.split_into_lines() @@ -128,6 +120,9 @@ fn test_c_must_have_files() ? { } if nmatches == expected_lines.len { println(term.green('OK')) + } else { + eprintln('> ALL lines:') + eprintln(compilation.output) } } assert total_errors == 0 @@ -154,8 +149,10 @@ fn normalize_panic_message(message string, vroot string) string { return msg } -fn vroot_relative(path string) string { - return path.replace(os.path_separator, '/').replace('$vroot/', '').replace('./', '') +fn vroot_relative(opath string) string { + nvroot := vroot.replace(os.path_separator, '/') + '/' + npath := opath.replace(os.path_separator, '/') + return npath.replace(nvroot, '') } fn ensure_compilation_succeeded(compilation os.Result) { @@ -167,23 +164,11 @@ fn ensure_compilation_succeeded(compilation os.Result) { } } -[if etrace ?] -fn etrace(msg string) { - eprintln(msg) -} - fn target2paths(target_path string, postfix string) (string, string, string, string) { - etrace('') - etrace('> target2paths $target_path | postfix: $postfix') basename := os.file_name(target_path).replace(postfix, '') - etrace(' basename: $basename') target_dir := os.dir(target_path) - etrace(' target_dir: $target_dir') path := os.join_path(target_dir, '${basename}.vv') - etrace(' path: $path') relpath := vroot_relative(path) - etrace(' relpath: $relpath') target_relpath := vroot_relative(target_path) - etrace(' target_relpath: $target_relpath') return basename, path, relpath, target_relpath } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 4462c18d97..8ca843ac2a 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -695,6 +695,10 @@ pub fn (pref &Preferences) vrun_elog(s string) { } } +pub fn (pref &Preferences) should_output_to_stdout() bool { + return pref.out_name.ends_with('/-') || pref.out_name.ends_with(r'\-') +} + pub fn arch_from_string(arch_str string) ?Arch { match arch_str { 'amd64', 'x86_64', 'x64', 'x86' { // amd64 recommended