2019-11-01 00:15:03 +01:00
|
|
|
module main
|
2019-10-09 05:01:43 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
os
|
2019-12-06 00:11:39 +01:00
|
|
|
testing
|
2019-10-09 05:01:43 +02:00
|
|
|
)
|
|
|
|
|
2019-11-01 00:15:03 +01:00
|
|
|
pub fn main() {
|
2019-10-09 05:01:43 +02:00
|
|
|
args := os.args
|
|
|
|
if args.last() == 'test' {
|
|
|
|
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.')
|
2019-12-01 10:50:13 +01:00
|
|
|
println(' B)')
|
2019-10-09 05:01:43 +02:00
|
|
|
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 test.')
|
|
|
|
println('')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-27 08:03:15 +01:00
|
|
|
args_string := args[1..].join(' ')
|
2019-10-09 05:01:43 +02:00
|
|
|
args_before := args_string.all_before('test ')
|
|
|
|
args_after := args_string.all_after('test ')
|
|
|
|
|
|
|
|
if args_after == 'v' {
|
2019-12-01 10:50:13 +01:00
|
|
|
eprintln('`v test v` has been deprecated.')
|
|
|
|
eprintln('Use `v test-compiler` instead.')
|
|
|
|
exit(1)
|
2019-10-09 05:01:43 +02:00
|
|
|
}
|
2019-12-06 00:11:39 +01:00
|
|
|
|
|
|
|
mut ts := testing.new_test_session(args_before)
|
2019-10-09 05:01:43 +02:00
|
|
|
for targ in args_after.split(' ') {
|
2019-12-04 21:03:12 +01:00
|
|
|
if os.exists(targ) && targ.ends_with('_test.v') {
|
2019-10-09 05:01:43 +02:00
|
|
|
ts.files << targ
|
|
|
|
continue
|
|
|
|
}
|
2019-12-04 21:03:12 +01:00
|
|
|
if os.is_dir(targ) {
|
2019-10-20 08:56:33 +02:00
|
|
|
// Fetch all tests from the directory
|
2019-10-12 21:31:05 +02:00
|
|
|
ts.files << os.walk_ext( targ.trim_right(os.path_separator), '_test.v')
|
2019-10-09 05:01:43 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
println('Unrecognized test file $targ .')
|
|
|
|
}
|
|
|
|
|
|
|
|
println('Testing...')
|
|
|
|
ts.test()
|
2019-12-20 21:17:48 +01:00
|
|
|
|
|
|
|
// Print separator with dynamic width
|
|
|
|
mut cols := 76
|
|
|
|
if tput := os.exec("tput cols; echo") {
|
|
|
|
if tput.exit_code == 0 {
|
|
|
|
cols = tput.output.int()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
println("-".repeat(cols))
|
|
|
|
|
2019-10-09 05:01:43 +02:00
|
|
|
println( ts.benchmark.total_message('running V _test.v files') )
|
|
|
|
if ts.failed {
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|