From 5322a2569007c8feb211db4407d03027bf07393c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 13 Jul 2021 22:24:38 +0300 Subject: [PATCH] tests: detect missing -o v.c files earlier --- cmd/tools/vtest-all.v | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/tools/vtest-all.v b/cmd/tools/vtest-all.v index aacdb7a1b8..0afbb86697 100644 --- a/cmd/tools/vtest-all.v +++ b/cmd/tools/vtest-all.v @@ -57,6 +57,11 @@ fn get_all_commands() []Command { okmsg: 'V can compile hello world.' rmfile: 'examples/hello_world' } + res << Command{ + line: '$vexe -o hhww.c examples/hello_world.v' + okmsg: 'V can output a .c file, without compiling further.' + rmfile: 'hhww.c' + } res << Command{ line: '$vexe -o vtmp cmd/v' okmsg: 'V can compile itself.' @@ -126,7 +131,7 @@ fn get_all_commands() []Command { okmsg: '`v -usecache` works.' rmfile: 'examples/tetris/tetris' } - $if macos { + $if macos || linux { res << Command{ line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf a.out' label: 'v.c should be buildable with no warnings...' @@ -152,13 +157,24 @@ fn (mut cmd Command) run() { return } if cmd.rmfile != '' { - os.rm(cmd.rmfile) or {} + mut file_existed := rm_existing(cmd.rmfile) if os.user_os() == 'windows' { - os.rm(cmd.rmfile + '.exe') or {} + file_existed = file_existed || rm_existing(cmd.rmfile + '.exe') + } + if !file_existed { + eprintln('Expected file did not exist: $cmd.rmfile') + cmd.ecode = 999 } } } +// try to remove a file, return if it existed before the removal attempt +fn rm_existing(path string) bool { + existed := os.exists(path) + os.rm(path) or {} + return existed +} + fn term_highlight(s string) string { return term.colorize(term.yellow, term.colorize(term.bold, s)) }