1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

preludes,builder,cgen: add support for VTEST_RUNNER=tap and -test-runner tap (#12523)

This commit is contained in:
Delyan Angelov
2021-12-16 15:59:46 +02:00
committed by GitHub
parent caac89d6ca
commit 6ff953d936
28 changed files with 665 additions and 178 deletions

View File

@@ -40,24 +40,31 @@ fn cleanup_tdir() {
os.rmdir_all(tdir) or { eprintln(err) }
}
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
}
fn main() {
defer {
os.chdir(os.wd_at_startup) or {}
}
println('> vroot: $vroot | vexe: $vexe | tdir: $tdir')
ok_fpath := os.join_path(tdir, 'single_test.v')
os.write_file(ok_fpath, 'fn test_ok(){ assert true }') ?
check_ok('"$vexe" $ok_fpath')
check_ok('"$vexe" test $ok_fpath')
fail_fpath := os.join_path(tdir, 'failing_test.v')
os.write_file(fail_fpath, 'fn test_fail(){ assert 1 == 2 }') ?
check_fail('"$vexe" $fail_fpath')
check_fail('"$vexe" test $fail_fpath')
check_fail('"$vexe" test $tdir')
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"')
rel_dir := os.join_path(tdir, rand.ulid())
os.mkdir(rel_dir) ?
os.chdir(rel_dir) ?
check_ok('"$vexe" test ..${os.path_separator + os.base(ok_fpath)}')
check_ok('"$vexe" test "..${os.path_separator + os.base(ok_fpath)}"')
println('> all done')
}
fn check_ok(cmd string) string {

View File

@@ -11,8 +11,23 @@ and then you can perform:
... to run all the module's '_test.v' files.
NB 2: V builtin testing requires you to name your files with a _test.v
suffix, and to name your test functions with test_ prefix. Each 'test_'
function in a '_test.v' file will be called automatically by the test
framework. You can use `assert condition` inside each 'test_' function.
If the asserted condition fails, then v will record that and produce a
more detailed error message about where the failure was.
suffix, and to name your test functions with test_ prefix. Each function,
that starts with 'fn test_', and that is in a '_test.v' file will be called
automatically by the test framework.
NB 3: You can use `assert condition` inside each 'test_' function. If the
asserted condition fails, then v will record that, and produce a more detailed
error message, about where the failure was.
NB 4: Alternative test runners (for IDE integrations):
You can use several alternative test result formats, using `-test-runner name`,
or by setting VTEST_RUNNER (the command line option has higher priority).
The names of the available test runners are:
`simple` Fastest, does not import additional modules, does no processing.
`tap` Format the output as required by the Test Anything Protocol (TAP).
`normal` Supports color output, nicest/most human readable, the default.
You can also implement your own custom test runner, by providing the path to
your .v file, that implements it to this option. For example, see:
vlib/v/preludes/test_runner_tap.v .