2021-01-17 17:04:08 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import os
|
|
|
|
import term
|
|
|
|
import time
|
|
|
|
|
2022-01-22 22:56:01 +03:00
|
|
|
const vexe_path = os.getenv('VEXE')
|
2021-06-15 14:22:18 +03:00
|
|
|
|
2022-01-22 22:56:01 +03:00
|
|
|
const vroot = os.dir(vexe_path)
|
|
|
|
|
|
|
|
const vexe = os.quoted_path(vexe_path)
|
2021-06-15 14:22:18 +03:00
|
|
|
|
|
|
|
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 17:04:08 +03:00
|
|
|
|
|
|
|
fn main() {
|
2021-01-23 12:40:17 +03:00
|
|
|
mut commands := get_all_commands()
|
|
|
|
// summary
|
2021-07-20 11:17:08 +03:00
|
|
|
sw := time.new_stopwatch()
|
2021-01-23 12:40:17 +03:00
|
|
|
for mut cmd in commands {
|
|
|
|
cmd.run()
|
|
|
|
}
|
|
|
|
spent := sw.elapsed().milliseconds()
|
|
|
|
oks := commands.filter(it.ecode == 0)
|
|
|
|
fails := commands.filter(it.ecode != 0)
|
2022-06-22 12:45:24 +03:00
|
|
|
flush_stdout()
|
2021-01-23 12:40:17 +03:00
|
|
|
println('')
|
2021-05-20 10:03:53 +03:00
|
|
|
println(term.header_left(term_highlight('Summary of `v test-all`:'), '-'))
|
|
|
|
println(term_highlight('Total runtime: $spent ms'))
|
2021-01-23 12:40:17 +03: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 }
|
2021-07-15 09:52:22 +03:00
|
|
|
println(term.failed('> Failed:') + ' $msg')
|
2021-01-23 12:40:17 +03:00
|
|
|
}
|
2022-06-22 12:45:24 +03:00
|
|
|
flush_stdout()
|
2021-01-23 12:40:17 +03:00
|
|
|
if fails.len > 0 {
|
|
|
|
exit(1)
|
|
|
|
}
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
|
|
|
|
2022-01-02 10:39:18 +03:00
|
|
|
enum RunCommandKind {
|
|
|
|
system
|
|
|
|
execute
|
|
|
|
}
|
|
|
|
|
|
|
|
const expect_nothing = '<nothing>'
|
|
|
|
|
2022-04-25 11:58:26 +03:00
|
|
|
const starts_with_nothing = '<nothing>'
|
|
|
|
|
|
|
|
const ends_with_nothing = '<nothing>'
|
|
|
|
|
|
|
|
const contains_nothing = '<nothing>'
|
|
|
|
|
2021-01-17 17:04:08 +03:00
|
|
|
struct Command {
|
|
|
|
mut:
|
2022-04-25 11:58:26 +03:00
|
|
|
line string
|
|
|
|
label string // when set, the label will be printed *before* cmd.line is executed
|
|
|
|
ecode int
|
|
|
|
okmsg string
|
|
|
|
errmsg string
|
|
|
|
rmfile string
|
|
|
|
runcmd RunCommandKind = .system
|
|
|
|
expect string = expect_nothing
|
|
|
|
starts_with string = starts_with_nothing
|
|
|
|
ends_with string = ends_with_nothing
|
|
|
|
contains string = contains_nothing
|
|
|
|
output string
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_all_commands() []Command {
|
|
|
|
mut res := []Command{}
|
2021-01-29 20:40:39 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe examples/hello_world.v'
|
|
|
|
okmsg: 'V can compile hello world.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'examples/hello_world'
|
2021-01-29 20:40:39 +03:00
|
|
|
}
|
2021-07-13 22:24:38 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o hhww.c examples/hello_world.v'
|
|
|
|
okmsg: 'V can output a .c file, without compiling further.'
|
|
|
|
rmfile: 'hhww.c'
|
|
|
|
}
|
2022-07-11 11:02:17 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -skip-unused examples/hello_world.v'
|
|
|
|
okmsg: 'V can compile hello world with -skip-unused.'
|
|
|
|
rmfile: 'examples/hello_world'
|
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -skip-unused -profile - examples/hello_world.v'
|
|
|
|
okmsg: 'V can compile hello world with both -skip-unused and -profile .'
|
|
|
|
rmfile: 'examples/hello_world'
|
|
|
|
}
|
2021-07-18 15:46:02 +03:00
|
|
|
$if linux || macos {
|
2022-01-02 10:39:18 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe run examples/hello_world.v'
|
|
|
|
okmsg: 'V can run hello world.'
|
|
|
|
runcmd: .execute
|
|
|
|
expect: 'Hello, World!\n'
|
|
|
|
}
|
2022-04-21 00:12:17 +03:00
|
|
|
if os.getenv('V_CI_MUSL').len == 0 {
|
|
|
|
for compiler_name in ['clang', 'gcc'] {
|
|
|
|
if _ := os.find_abs_path_of_executable(compiler_name) {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -cc $compiler_name -gc boehm run examples/hello_world.v'
|
|
|
|
okmsg: '`v -cc $compiler_name -gc boehm run examples/hello_world.v` works'
|
|
|
|
runcmd: .execute
|
|
|
|
expect: 'Hello, World!\n'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-02 10:39:18 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe interpret examples/hello_world.v'
|
|
|
|
okmsg: 'V can interpret hello world.'
|
|
|
|
runcmd: .execute
|
|
|
|
expect: 'Hello, World!\n'
|
|
|
|
}
|
2022-04-25 11:58:26 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe interpret examples/hanoi.v'
|
|
|
|
okmsg: 'V can interpret hanoi.v'
|
|
|
|
runcmd: .execute
|
|
|
|
starts_with: 'Disc 1 from A to C...\n'
|
|
|
|
ends_with: 'Disc 1 from A to C...\n'
|
|
|
|
contains: 'Disc 7 from A to C...\n'
|
|
|
|
}
|
2021-07-18 15:46:02 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
|
|
|
|
okmsg: 'V prints the generated source code to stdout with `-o -` .'
|
|
|
|
}
|
2021-10-12 19:22:16 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe run examples/v_script.vsh > /dev/null'
|
|
|
|
okmsg: 'V can run the .VSH script file examples/v_script.vsh'
|
|
|
|
}
|
2021-11-30 12:49:30 +03:00
|
|
|
$if linux {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -b native run examples/native/hello_world.v > /dev/null'
|
|
|
|
okmsg: 'V compiles and runs examples/native/hello_world.v on the native backend for linux'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// only compilation:
|
2021-11-26 20:03:15 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -os linux -b native -o hw.linux examples/hello_world.v'
|
|
|
|
okmsg: 'V compiles hello_world.v on the native backend for linux'
|
|
|
|
rmfile: 'hw.linux'
|
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -os macos -b native -o hw.macos examples/hello_world.v'
|
|
|
|
okmsg: 'V compiles hello_world.v on the native backend for macos'
|
|
|
|
rmfile: 'hw.macos'
|
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -os windows -b native -o hw.exe examples/hello_world.v'
|
|
|
|
okmsg: 'V compiles hello_world.v on the native backend for windows'
|
|
|
|
rmfile: 'hw.exe'
|
|
|
|
}
|
|
|
|
//
|
2021-10-12 19:22:16 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -b js -o hw.js examples/hello_world.v'
|
|
|
|
okmsg: 'V compiles hello_world.v on the JS backend'
|
|
|
|
rmfile: 'hw.js'
|
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -skip-unused -b js -o hw_skip_unused.js examples/hello_world.v'
|
|
|
|
okmsg: 'V compiles hello_world.v on the JS backend, with -skip-unused'
|
|
|
|
rmfile: 'hw_skip_unused.js'
|
|
|
|
}
|
2022-09-20 08:03:03 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -skip-unused examples/2048'
|
|
|
|
okmsg: 'V can compile 2048 with -skip-unused.'
|
|
|
|
rmfile: 'examples/2048/2048'
|
|
|
|
}
|
2021-09-10 12:43:53 +03:00
|
|
|
}
|
2021-01-29 20:40:39 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp cmd/v'
|
|
|
|
okmsg: 'V can compile itself.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'vtmp'
|
2021-01-29 20:40:39 +03:00
|
|
|
}
|
2021-04-05 23:52:39 +03:00
|
|
|
res << Command{
|
2021-04-19 15:38:48 +03:00
|
|
|
line: '$vexe -o vtmp_werror -cstrict cmd/v'
|
2021-05-20 08:09:09 +03:00
|
|
|
okmsg: 'V can compile itself with -cstrict.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'vtmp_werror'
|
2021-05-20 08:09:09 +03:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_autofree -autofree cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -autofree.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'vtmp_autofree'
|
2021-05-20 08:09:09 +03:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_prealloc -prealloc cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -prealloc.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'vtmp_prealloc'
|
2021-05-20 08:09:09 +03:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -o vtmp_unused -skip-unused cmd/v'
|
|
|
|
okmsg: 'V can compile itself with -skip-unused.'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'vtmp_unused'
|
2021-04-05 23:52:39 +03:00
|
|
|
}
|
2021-06-23 13:33:16 +03:00
|
|
|
$if linux {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -cc gcc -keepc -freestanding -o bel vlib/os/bare/bare_example_linux.v'
|
|
|
|
okmsg: 'V can compile with -freestanding on Linux with GCC.'
|
|
|
|
rmfile: 'bel'
|
|
|
|
}
|
2022-01-06 15:10:37 +03:00
|
|
|
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -cc gcc -keepc -freestanding -o str_array vlib/strconv/bare/str_array_example.v'
|
|
|
|
okmsg: 'V can compile & allocate memory with -freestanding on Linux with GCC.'
|
|
|
|
rmfile: 'str_array'
|
|
|
|
}
|
2021-06-23 13:33:16 +03:00
|
|
|
}
|
2021-01-17 17:04:08 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe $vargs -progress test-cleancode'
|
2021-05-20 08:09:09 +03:00
|
|
|
okmsg: 'All .v files are invariant when processed with `v fmt`'
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe $vargs -progress test-fmt'
|
2022-03-06 20:01:22 +03:00
|
|
|
okmsg: 'All .v files can be processed with `v fmt`. Note: the result may not always be compilable, but `v fmt` should not crash.'
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-19 11:41:51 +03:00
|
|
|
line: '$vexe $vargs -progress test-self'
|
2021-01-17 17:04:08 +03:00
|
|
|
okmsg: 'There are no _test.v file regressions.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-31 11:43:49 +03:00
|
|
|
line: '$vexe $vargs -progress -W build-tools'
|
2021-01-17 17:04:08 +03:00
|
|
|
okmsg: 'All tools can be compiled.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-01-31 11:43:49 +03:00
|
|
|
line: '$vexe $vargs -progress -W build-examples'
|
2021-01-17 17:04:08 +03:00
|
|
|
okmsg: 'All examples can be compiled.'
|
|
|
|
}
|
|
|
|
res << Command{
|
2021-02-05 18:46:20 +03:00
|
|
|
line: '$vexe check-md -hide-warnings .'
|
2021-01-17 17:04:08 +03: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-08-15 08:35:26 +03:00
|
|
|
res << Command{
|
|
|
|
line: '$vexe -usecache -cg examples/hello_world.v'
|
|
|
|
okmsg: '`v -usecache -cg` works.'
|
|
|
|
rmfile: 'examples/hello_world'
|
|
|
|
}
|
2022-03-06 20:01:22 +03:00
|
|
|
// Note: test that a program that depends on thirdparty libraries with its
|
2021-01-29 20:40:39 +03:00
|
|
|
// 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 14:22:18 +03:00
|
|
|
rmfile: 'examples/tetris/tetris'
|
2021-01-29 20:40:39 +03:00
|
|
|
}
|
2021-07-13 22:24:38 +03:00
|
|
|
$if macos || linux {
|
2021-01-17 17:04:08 +03:00
|
|
|
res << Command{
|
2022-04-21 00:12:50 +03:00
|
|
|
line: '$vexe -o v.c cmd/v && cc -Werror v.c -lpthread -lm && rm -rf a.out'
|
2021-01-17 17:04:08 +03:00
|
|
|
label: 'v.c should be buildable with no warnings...'
|
|
|
|
okmsg: 'v.c can be compiled without warnings. This is good :)'
|
2021-06-15 14:22:18 +03:00
|
|
|
rmfile: 'v.c'
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
|
|
|
}
|
2022-10-11 15:19:36 +03:00
|
|
|
$if linux {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe vlib/v/tests/bench/bench_stbi_load.v && prlimit -v10485760 vlib/v/tests/bench/bench_stbi_load'
|
|
|
|
okmsg: 'STBI load does not leak with GC on, when loading images multiple times (use < 10MB)'
|
|
|
|
runcmd: .execute
|
|
|
|
contains: 'logo.png 1000 times.'
|
|
|
|
rmfile: 'vlib/v/tests/bench/bench_stbi_load'
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 15:52:18 +03:00
|
|
|
$if !windows {
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -raw-vsh-tmp-prefix tmp vlib/v/tests/script_with_no_extension'
|
|
|
|
okmsg: 'V can crun a script, that lacks a .vsh extension'
|
|
|
|
runcmd: .execute
|
|
|
|
expect: 'Test\n'
|
|
|
|
rmfile: 'vlib/v/tests/tmp.script_with_no_extension'
|
|
|
|
}
|
|
|
|
|
|
|
|
res << Command{
|
|
|
|
line: '$vexe -raw-vsh-tmp-prefix tmp run vlib/v/tests/script_with_no_extension'
|
|
|
|
okmsg: 'V can run a script, that lacks a .vsh extension'
|
|
|
|
runcmd: .execute
|
|
|
|
expect: 'Test\n'
|
|
|
|
}
|
|
|
|
}
|
2021-01-17 17:04:08 +03: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
|
2021-08-28 12:44:03 +03:00
|
|
|
os.chdir(vroot) or {}
|
2021-01-17 17:04:08 +03:00
|
|
|
if cmd.label != '' {
|
2021-05-20 10:03:53 +03:00
|
|
|
println(term.header_left(cmd.label, '*'))
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|
2021-07-20 11:17:08 +03:00
|
|
|
sw := time.new_stopwatch()
|
2022-01-02 10:39:18 +03:00
|
|
|
if cmd.runcmd == .system {
|
|
|
|
cmd.ecode = os.system(cmd.line)
|
|
|
|
cmd.output = ''
|
|
|
|
}
|
|
|
|
if cmd.runcmd == .execute {
|
|
|
|
res := os.execute(cmd.line)
|
|
|
|
cmd.ecode = res.exit_code
|
|
|
|
cmd.output = res.output
|
|
|
|
}
|
2021-01-17 17:04:08 +03:00
|
|
|
spent := sw.elapsed().milliseconds()
|
2022-01-02 10:39:18 +03:00
|
|
|
//
|
|
|
|
mut is_failed := false
|
2022-04-25 11:58:26 +03:00
|
|
|
mut is_failed_expected := false
|
|
|
|
mut is_failed_starts_with := false
|
|
|
|
mut is_failed_ends_with := false
|
|
|
|
mut is_failed_contains := false
|
2022-01-02 10:39:18 +03:00
|
|
|
if cmd.ecode != 0 {
|
|
|
|
is_failed = true
|
|
|
|
}
|
|
|
|
if cmd.expect != expect_nothing {
|
|
|
|
if cmd.output != cmd.expect {
|
|
|
|
is_failed = true
|
2022-04-25 11:58:26 +03:00
|
|
|
is_failed_expected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cmd.starts_with != starts_with_nothing {
|
|
|
|
if !cmd.output.starts_with(cmd.starts_with) {
|
|
|
|
is_failed = true
|
|
|
|
is_failed_starts_with = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cmd.ends_with != ends_with_nothing {
|
|
|
|
if !cmd.output.ends_with(cmd.ends_with) {
|
|
|
|
is_failed = true
|
|
|
|
is_failed_ends_with = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cmd.contains != contains_nothing {
|
|
|
|
if !cmd.output.contains(cmd.contains) {
|
|
|
|
is_failed = true
|
|
|
|
is_failed_contains = true
|
2022-01-02 10:39:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
run_label := if is_failed { term.failed('FAILED') } else { term_highlight('OK') }
|
|
|
|
println('> Running: "$cmd.line" took: $spent ms ... $run_label')
|
|
|
|
//
|
2022-04-25 11:58:26 +03:00
|
|
|
if is_failed && is_failed_expected {
|
|
|
|
eprintln('> expected:\n$cmd.expect')
|
|
|
|
eprintln('> output:\n$cmd.output')
|
|
|
|
}
|
|
|
|
if is_failed && is_failed_starts_with {
|
|
|
|
eprintln('> expected to start with:\n$cmd.starts_with')
|
|
|
|
eprintln('> output:\n${cmd.output#[..cmd.starts_with.len]}')
|
|
|
|
}
|
|
|
|
if is_failed && is_failed_ends_with {
|
|
|
|
eprintln('> expected to end with:\n$cmd.ends_with')
|
|
|
|
eprintln('> output:\n${cmd.output#[-cmd.starts_with.len..]}')
|
|
|
|
}
|
|
|
|
if is_failed && is_failed_contains {
|
|
|
|
eprintln('> expected to contain:\n$cmd.contains')
|
|
|
|
eprintln('> output:\n$cmd.output')
|
2022-01-02 10:39:18 +03:00
|
|
|
}
|
2021-06-15 14:22:18 +03:00
|
|
|
if vtest_nocleanup {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if cmd.rmfile != '' {
|
2021-07-13 22:24:38 +03:00
|
|
|
mut file_existed := rm_existing(cmd.rmfile)
|
2021-06-15 14:22:18 +03:00
|
|
|
if os.user_os() == 'windows' {
|
2021-07-13 22:24:38 +03:00
|
|
|
file_existed = file_existed || rm_existing(cmd.rmfile + '.exe')
|
|
|
|
}
|
|
|
|
if !file_existed {
|
|
|
|
eprintln('Expected file did not exist: $cmd.rmfile')
|
|
|
|
cmd.ecode = 999
|
2021-06-15 14:22:18 +03:00
|
|
|
}
|
|
|
|
}
|
2021-05-20 10:03:53 +03:00
|
|
|
}
|
|
|
|
|
2021-07-13 22:24:38 +03:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:03:53 +03:00
|
|
|
fn term_highlight(s string) string {
|
|
|
|
return term.colorize(term.yellow, term.colorize(term.bold, s))
|
2021-01-17 17:04:08 +03:00
|
|
|
}
|