tools: cleanup generated executables by `v test-all`

pull/10468/head
Delyan Angelov 2021-06-15 14:22:18 +03:00
parent 48b3ab831b
commit af60eba5e6
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 29 additions and 6 deletions

2
.gitignore vendored
View File

@ -23,6 +23,8 @@ a.out
/v.c /v.c
/v.*.c /v.*.c
/v.c.out /v.c.out
/v_old
/v_old.exe
.vrepl_temp.v .vrepl_temp.v
fns.txt fns.txt
.noprefix.vrepl_temp.v .noprefix.vrepl_temp.v

View File

@ -4,12 +4,15 @@ import os
import term import term
import time import time
const ( const vexe = os.getenv('VEXE')
vexe = os.getenv('VEXE')
vroot = os.dir(vexe) const vroot = os.dir(vexe)
args_string = os.args[1..].join(' ')
vargs = args_string.all_before('test-all') const args_string = os.args[1..].join(' ')
)
const vargs = args_string.all_before('test-all')
const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool()
fn main() { fn main() {
mut commands := get_all_commands() mut commands := get_all_commands()
@ -44,6 +47,7 @@ mut:
ecode int ecode int
okmsg string okmsg string
errmsg string errmsg string
rmfile string
} }
fn get_all_commands() []Command { fn get_all_commands() []Command {
@ -51,26 +55,32 @@ fn get_all_commands() []Command {
res << Command{ res << Command{
line: '$vexe examples/hello_world.v' line: '$vexe examples/hello_world.v'
okmsg: 'V can compile hello world.' okmsg: 'V can compile hello world.'
rmfile: 'examples/hello_world'
} }
res << Command{ res << Command{
line: '$vexe -o vtmp cmd/v' line: '$vexe -o vtmp cmd/v'
okmsg: 'V can compile itself.' okmsg: 'V can compile itself.'
rmfile: 'vtmp'
} }
res << Command{ res << Command{
line: '$vexe -o vtmp_werror -cstrict cmd/v' line: '$vexe -o vtmp_werror -cstrict cmd/v'
okmsg: 'V can compile itself with -cstrict.' okmsg: 'V can compile itself with -cstrict.'
rmfile: 'vtmp_werror'
} }
res << Command{ res << Command{
line: '$vexe -o vtmp_autofree -autofree cmd/v' line: '$vexe -o vtmp_autofree -autofree cmd/v'
okmsg: 'V can compile itself with -autofree.' okmsg: 'V can compile itself with -autofree.'
rmfile: 'vtmp_autofree'
} }
res << Command{ res << Command{
line: '$vexe -o vtmp_prealloc -prealloc cmd/v' line: '$vexe -o vtmp_prealloc -prealloc cmd/v'
okmsg: 'V can compile itself with -prealloc.' okmsg: 'V can compile itself with -prealloc.'
rmfile: 'vtmp_prealloc'
} }
res << Command{ res << Command{
line: '$vexe -o vtmp_unused -skip-unused cmd/v' line: '$vexe -o vtmp_unused -skip-unused cmd/v'
okmsg: 'V can compile itself with -skip-unused.' okmsg: 'V can compile itself with -skip-unused.'
rmfile: 'vtmp_unused'
} }
res << Command{ res << Command{
line: '$vexe $vargs -progress test-cleancode' line: '$vexe $vargs -progress test-cleancode'
@ -107,12 +117,14 @@ fn get_all_commands() []Command {
res << Command{ res << Command{
line: '$vexe -usecache examples/tetris/tetris.v' line: '$vexe -usecache examples/tetris/tetris.v'
okmsg: '`v -usecache` works.' okmsg: '`v -usecache` works.'
rmfile: 'examples/tetris/tetris'
} }
$if macos { $if macos {
res << Command{ res << Command{
line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c' line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c'
label: 'v.c should be buildable with no warnings...' label: 'v.c should be buildable with no warnings...'
okmsg: 'v.c can be compiled without warnings. This is good :)' okmsg: 'v.c can be compiled without warnings. This is good :)'
rmfile: 'v.c'
} }
} }
return res return res
@ -129,6 +141,15 @@ fn (mut cmd Command) run() {
cmd.ecode = os.system(cmd.line) cmd.ecode = os.system(cmd.line)
spent := sw.elapsed().milliseconds() spent := sw.elapsed().milliseconds()
println(term_highlight('> Running: "$cmd.line" took: $spent ms.')) println(term_highlight('> Running: "$cmd.line" took: $spent ms.'))
if vtest_nocleanup {
return
}
if cmd.rmfile != '' {
os.rm(cmd.rmfile) or {}
if os.user_os() == 'windows' {
os.rm(cmd.rmfile + '.exe') or {}
}
}
} }
fn term_highlight(s string) string { fn term_highlight(s string) string {