2021-01-04 12:36:58 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
// This program verifies that `v test` propagates errors
|
|
|
|
// and that it exits with code 1, when at least 1 FAIL happen.
|
|
|
|
import os
|
|
|
|
import rand
|
|
|
|
|
|
|
|
const (
|
|
|
|
vexe = get_vexe_path()
|
|
|
|
vroot = os.dir(vexe)
|
|
|
|
tdir = new_tdir()
|
|
|
|
)
|
|
|
|
|
|
|
|
fn get_vexe_path() string {
|
|
|
|
env_vexe := os.getenv('VEXE')
|
|
|
|
if env_vexe != '' {
|
|
|
|
return env_vexe
|
|
|
|
}
|
|
|
|
me := os.executable()
|
|
|
|
eprintln('me: $me')
|
2021-01-10 21:41:29 +01:00
|
|
|
mut vexe_ := os.join_path(os.dir(os.dir(os.dir(me))), 'v')
|
2021-01-04 12:36:58 +01:00
|
|
|
if os.user_os() == 'windows' {
|
2021-01-10 21:41:29 +01:00
|
|
|
vexe_ += '.exe'
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
2021-01-10 21:41:29 +01:00
|
|
|
return vexe_
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn new_tdir() string {
|
2021-01-10 21:41:29 +01:00
|
|
|
tdir_ := os.join_path(os.temp_dir(), rand.ulid())
|
|
|
|
if os.exists(tdir_) {
|
2021-03-01 00:18:14 +01:00
|
|
|
os.rmdir(tdir_) or { panic(err) }
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
2021-03-01 00:18:14 +01:00
|
|
|
os.mkdir(tdir_) or { panic(err) }
|
2021-01-04 12:36:58 +01:00
|
|
|
C.atexit(cleanup_tdir)
|
2021-01-10 21:41:29 +01:00
|
|
|
return tdir_
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn cleanup_tdir() {
|
|
|
|
println('... removing tdir: $tdir')
|
2021-09-06 02:11:58 +02:00
|
|
|
os.rmdir_all(tdir) or { eprintln(err) }
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 14:59:46 +01:00
|
|
|
fn create_test(tname string, tcontent string) ?string {
|
|
|
|
tpath := os.join_path(tdir, tname)
|
|
|
|
os.write_file(tpath, tcontent) ?
|
|
|
|
eprintln('>>>>>>>> tpath: $tpath | tcontent: $tcontent')
|
|
|
|
return tpath
|
|
|
|
}
|
|
|
|
|
2021-01-04 12:36:58 +01:00
|
|
|
fn main() {
|
2021-09-06 02:11:58 +02:00
|
|
|
defer {
|
|
|
|
os.chdir(os.wd_at_startup) or {}
|
|
|
|
}
|
2021-01-04 12:36:58 +01:00
|
|
|
println('> vroot: $vroot | vexe: $vexe | tdir: $tdir')
|
2021-12-16 14:59:46 +01:00
|
|
|
ok_fpath := create_test('a_single_ok_test.v', 'fn test_ok(){ assert true }') ?
|
|
|
|
check_ok('"$vexe" "$ok_fpath"')
|
|
|
|
check_ok('"$vexe" test "$ok_fpath"')
|
|
|
|
check_ok('"$vexe" test "$tdir"')
|
|
|
|
fail_fpath := create_test('a_single_failing_test.v', 'fn test_fail(){ assert 1 == 2 }') ?
|
|
|
|
check_fail('"$vexe" "$fail_fpath"')
|
|
|
|
check_fail('"$vexe" test "$fail_fpath"')
|
|
|
|
check_fail('"$vexe" test "$tdir"')
|
2021-09-06 02:11:58 +02:00
|
|
|
rel_dir := os.join_path(tdir, rand.ulid())
|
|
|
|
os.mkdir(rel_dir) ?
|
|
|
|
os.chdir(rel_dir) ?
|
2021-12-16 14:59:46 +01:00
|
|
|
check_ok('"$vexe" test "..${os.path_separator + os.base(ok_fpath)}"')
|
|
|
|
println('> all done')
|
2021-01-04 12:36:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_ok(cmd string) string {
|
|
|
|
println('> check_ok cmd: $cmd')
|
2021-03-08 19:52:13 +01:00
|
|
|
res := os.execute(cmd)
|
2021-01-04 12:36:58 +01:00
|
|
|
if res.exit_code != 0 {
|
|
|
|
eprintln('> check_ok failed.\n$res.output')
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
return res.output
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_fail(cmd string) string {
|
|
|
|
println('> check_fail cmd: $cmd')
|
2021-03-08 19:52:13 +01:00
|
|
|
res := os.execute(cmd)
|
2021-01-04 12:36:58 +01:00
|
|
|
if res.exit_code == 0 {
|
|
|
|
eprintln('> check_fail succeeded, but it should have failed.\n$res.output')
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
return res.output
|
|
|
|
}
|