2019-11-01 02:15:03 +03:00
|
|
|
module main
|
2019-10-09 06:01:43 +03:00
|
|
|
|
2020-04-17 22:41:54 +03:00
|
|
|
import os
|
|
|
|
import os.cmdline
|
|
|
|
import testing
|
2019-10-09 06:01:43 +03:00
|
|
|
|
2020-04-17 22:41:54 +03:00
|
|
|
fn main() {
|
2020-12-20 19:27:42 +03:00
|
|
|
args := os.args.clone()
|
|
|
|
if os.args.last() == 'test' {
|
2021-01-13 22:52:05 +03:00
|
|
|
show_usage()
|
2019-10-09 06:01:43 +03:00
|
|
|
return
|
|
|
|
}
|
2019-12-24 05:43:31 +03:00
|
|
|
args_to_executable := args[1..]
|
2020-02-16 14:42:28 +03:00
|
|
|
args_before := cmdline.options_before(args_to_executable, ['test'])
|
|
|
|
args_after := cmdline.options_after(args_to_executable, ['test'])
|
2019-12-24 05:43:31 +03:00
|
|
|
if args_after.join(' ') == 'v' {
|
2019-12-01 12:50:13 +03:00
|
|
|
eprintln('`v test v` has been deprecated.')
|
|
|
|
eprintln('Use `v test-compiler` instead.')
|
|
|
|
exit(1)
|
2019-10-09 06:01:43 +03:00
|
|
|
}
|
2019-12-24 05:43:31 +03:00
|
|
|
mut ts := testing.new_test_session(args_before.join(' '))
|
|
|
|
for targ in args_after {
|
2019-12-04 23:03:12 +03:00
|
|
|
if os.exists(targ) && targ.ends_with('_test.v') {
|
2019-10-09 06:01:43 +03:00
|
|
|
ts.files << targ
|
|
|
|
continue
|
|
|
|
}
|
2019-12-04 23:03:12 +03:00
|
|
|
if os.is_dir(targ) {
|
2019-10-20 09:56:33 +03:00
|
|
|
// Fetch all tests from the directory
|
2020-10-15 16:17:52 +03:00
|
|
|
ts.files << os.walk_ext(targ.trim_right(os.path_separator), '_test.v')
|
2019-10-09 06:01:43 +03:00
|
|
|
continue
|
|
|
|
}
|
2021-01-13 22:52:05 +03:00
|
|
|
eprintln('\nUnrecognized test file `$targ` .\n `v test` can only be used with folders and/or _test.v files.\n')
|
|
|
|
show_usage()
|
|
|
|
exit(1)
|
2019-10-09 06:01:43 +03:00
|
|
|
}
|
2020-02-08 19:01:10 +03:00
|
|
|
testing.header('Testing...')
|
2019-10-09 06:01:43 +03:00
|
|
|
ts.test()
|
2021-01-13 12:07:12 +03:00
|
|
|
println(ts.benchmark.total_message('Ran all V _test.v files'))
|
2019-10-09 06:01:43 +03:00
|
|
|
if ts.failed {
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|
2021-01-13 22:52:05 +03:00
|
|
|
|
|
|
|
fn show_usage() {
|
|
|
|
println('Usage:')
|
|
|
|
println(' A)')
|
|
|
|
println(' v test folder/ : run all v tests in the given folder.')
|
|
|
|
println(' v -stats test folder/ : the same, but print more stats.')
|
|
|
|
println(' B)')
|
|
|
|
println(' v test file_test.v : run test functions in a given test file.')
|
|
|
|
println(' v -stats test file_test.v : as above, but with more stats.')
|
|
|
|
println(' NB: you can also give many and mixed folder/ file_test.v arguments after `v test` .')
|
|
|
|
println('')
|
|
|
|
}
|