v2 / vlib / v / debug / tracing_test.v
61 lines · 52 sloc · 1.57 KB · 2332ecff4811b8c97dfda8e825170e9397962519
Raw
1import os
2import term
3import time
4
5const vexe = @VEXE
6const trace_tests_path = os.join_path(@VEXEROOT, 'vlib', 'v', 'debug', 'tests', 'trace')
7const bar = term.yellow('-'.repeat(105))
8const be_verbose = os.getenv('GITHUB_JOB') != '' || os.getenv('VERBOSE') != ''
9
10const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or {
11 eprintln('skipping test, since expect is missing')
12 exit(0)
13})
14
15fn testsuite_begin() {
16 os.chdir(@VEXEROOT) or {}
17}
18
19fn gprintln(msg string) {
20 println(term.green(msg))
21 flush_stdout()
22}
23
24fn gprint(msg string) {
25 print(term.green(msg))
26 flush_stdout()
27}
28
29fn test_trace() {
30 all_expect_files := os.walk_ext(trace_tests_path, '.v')
31 assert all_expect_files.len > 0, 'no .v files found in ${trace_tests_path}'
32 mut oks := 0
33 for eidx, efile in all_expect_files.sorted() {
34 // if !efile.contains('sumtype') { gprintln('skipping ${efile}') continue }
35 vfile := efile
36
37 if be_verbose {
38 println(bar)
39 }
40 gprint('>>>> Running [${eidx + 1}/${all_expect_files.len}] ${term.magenta(efile):-68} ... ')
41 if be_verbose {
42 println('')
43 }
44
45 compile_sw := time.new_stopwatch()
46 comp_res := os.system('${os.quoted_path(vexe)} -d trace test ${os.quoted_path(vfile)}')
47 cdur_ms := compile_sw.elapsed().milliseconds()
48 if be_verbose {
49 gprintln('>>>>>>>>>>> compilation took ${cdur_ms} ms, comp_res: ${comp_res}')
50 }
51 if comp_res != 0 {
52 assert false, term.red('failed test cmd: ${vfile}')
53 }
54 assert true
55 oks++
56 }
57 os.chdir(@VEXEROOT) or {}
58
59 println(bar)
60 gprintln('Passed debugger tests: ${term.bold(oks.str())} of ${all_expect_files.len} total.')
61}
62