2021-01-17 15:04:08 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import term
|
|
|
|
import time
|
|
|
|
|
2021-06-15 13:22:18 +02:00
|
|
|
const vexe = os.getenv('VEXE')
|
|
|
|
|
|
|
|
const vroot = os.dir(vexe)
|
|
|
|
|
|
|
|
const args_string = os.args[1..].join(' ')
|
|
|
|
|
|
|
|
const vargs = args_string.all_before('test-all')
|
|
|
|
|
|
|
|
const vtest_nocleanup = os.getenv('VTEST_NOCLEANUP').bool()
|
2021-01-17 15:04:08 +01:00
|
|
|
|
|
|
|
fn main() {
|
2021-01-23 10:40:17 +01:00
|
|
|
mut commands := get_all_commands()
|
|
|
|
// summary
|
|
|
|
sw := time.new_stopwatch({})
|
|
|
|
for mut cmd in commands {
|
|
|
|
cmd.run()
|
|
|
|
}
|
|
|
|
spent := sw.elapsed().milliseconds()
|
|
|
|
oks := commands.filter(it.ecode == 0)
|
|
|
|
fails := commands.filter(it.ecode != 0)
|
|
|
|
println('')
|
2021-05-20 09:03:53 +02:00
|
|
|
println(term.header_left(term_highlight('Summary of `v test-all`:'), '-'))
|
|
|
|
println(term_highlight('Total runtime: $spent ms'))
|
2021-01-23 10:40:17 +01:00
|
|
|
for ocmd in oks {
|
|
|
|
msg := if ocmd.okmsg != '' { ocmd.okmsg } else { ocmd.line }
|
|
|
|
println(term.colorize(term.green, '> OK: $msg '))
|
|
|
|
}
|
|
|
|
for fcmd in fails {
|
|
|
|
msg := if fcmd.errmsg != '' { fcmd.errmsg } else { fcmd.line }
|
|
|
|
println(term.colorize(term.red, '> Failed: $msg '))
|
|
|
|
}
|
|
|
|
if fails.len > 0 {
|
|
|
|
exit(1)
|
|
|
|
}
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Command {
|
|
|
|
mut:
|
|
|
|
line string
|
|
|
|
label string // when set, the label will be printed *before* cmd.line is executed
|
|
|
|
ecode int
|
|
|
|
okmsg string
|
|
|
|
errmsg string
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile string
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_all_commands() []Command {
|
|
|
|
mut res := []Command{}
|
2021-01-29 18:40:39 +01:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe examples/hello_world.v'
|
|
|
|
okmsg: 'V can compile hello world.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'examples/hello_world'
|
2021-01-29 18:40:39 +01:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp cmd/v'
|
|
|
|
okmsg: 'V can compile itself.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'vtmp'
|
2021-01-29 18:40:39 +01:00
|
|
|
}
|
2021-04-05 22:52:39 +02:00
|
|
|
res << Command{
|
2021-04-19 14:38:48 +02:00
|
|
|
line: '$vexe -o vtmp_werror -cstrict cmd/v'
|
2021-05-20 07:09:09 +02:00
|
|
|
okmsg: 'V can compile itself with -cstrict.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'vtmp_werror'
|
2021-05-20 07:09:09 +02:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_autofree -autofree cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -autofree.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'vtmp_autofree'
|
2021-05-20 07:09:09 +02:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_prealloc -prealloc cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -prealloc.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'vtmp_prealloc'
|
2021-05-20 07:09:09 +02:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_unused -skip-unused cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -skip-unused.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'vtmp_unused'
|
2021-04-05 22:52:39 +02:00
|
|
|
}
|
2021-01-17 15:04:08 +01:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe $vargs -progress test-cleancode'
|
2021-05-20 07:09:09 +02:00
|
|
|
okmsg: 'All .v files are invariant when processed with `v fmt`'
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe $vargs -progress test-fmt'
|
2021-05-20 07:09:09 +02:00
|
|
|
okmsg: 'All .v files can be processed with `v fmt`. NB: the result may not always be compilable, but `v fmt` should not crash.'
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-19 09:41:51 +01:00
|
|
|
line: '$vexe $vargs -progress test-self'
|
2021-01-17 15:04:08 +01:00
|
|
|
okmsg: 'There are no _test.v file regressions.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-31 09:43:49 +01:00
|
|
|
line: '$vexe $vargs -progress -W build-tools'
|
2021-01-17 15:04:08 +01:00
|
|
|
okmsg: 'All tools can be compiled.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-31 09:43:49 +01:00
|
|
|
line: '$vexe $vargs -progress -W build-examples'
|
2021-01-17 15:04:08 +01:00
|
|
|
okmsg: 'All examples can be compiled.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-02-05 16:46:20 +01:00
|
|
|
line: '$vexe check-md -hide-warnings .'
|
2021-01-17 15:04:08 +01:00
|
|
|
label: 'Check ```v ``` code examples and formatting of .MD files...'
|
|
|
|
okmsg: 'All .md files look good.'
|
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe install nedpals.args'
|
|
|
|
okmsg: '`v install` works.'
|
|
|
|
}
|
2021-01-29 18:40:39 +01:00
|
|
|
// NB: test that a program that depends on thirdparty libraries with its
|
|
|
|
// own #flags (tetris depends on gg, which uses sokol) can be compiled
|
|
|
|
// with -usecache:
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -usecache examples/tetris/tetris.v'
|
|
|
|
okmsg: '`v -usecache` works.'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'examples/tetris/tetris'
|
2021-01-29 18:40:39 +01:00
|
|
|
}
|
2021-01-17 15:04:08 +01:00
|
|
|
$if macos {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c'
|
|
|
|
label: 'v.c should be buildable with no warnings...'
|
|
|
|
okmsg: 'v.c can be compiled without warnings. This is good :)'
|
2021-06-15 13:22:18 +02:00
|
|
|
rmfile: 'v.c'
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut cmd Command) run() {
|
|
|
|
// Changing the current directory is needed for some of the compiler tests,
|
|
|
|
// vlib/v/tests/local_test.v and vlib/v/tests/repl/repl_test.v
|
|
|
|
os.chdir(vroot)
|
|
|
|
if cmd.label != '' {
|
2021-05-20 09:03:53 +02:00
|
|
|
println(term.header_left(cmd.label, '*'))
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|
|
|
|
sw := time.new_stopwatch({})
|
|
|
|
cmd.ecode = os.system(cmd.line)
|
|
|
|
spent := sw.elapsed().milliseconds()
|
2021-05-20 09:03:53 +02:00
|
|
|
println(term_highlight('> Running: "$cmd.line" took: $spent ms.'))
|
2021-06-15 13:22:18 +02:00
|
|
|
if vtest_nocleanup {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if cmd.rmfile != '' {
|
|
|
|
os.rm(cmd.rmfile) or {}
|
|
|
|
if os.user_os() == 'windows' {
|
|
|
|
os.rm(cmd.rmfile + '.exe') or {}
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 09:03:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn term_highlight(s string) string {
|
|
|
|
return term.colorize(term.yellow, term.colorize(term.bold, s))
|
2021-01-17 15:04:08 +01:00
|
|
|
}
|