| 1 | import os |
| 2 | import term |
| 3 | import time |
| 4 | |
| 5 | const vexe = @VEXE |
| 6 | const expect_tests_path = os.join_path(@VEXEROOT, 'vlib', 'v', 'debug', 'tests') |
| 7 | const test_module_path = os.join_path(os.vtmp_dir(), 'test_vdbg_input') |
| 8 | const bar = term.yellow('-'.repeat(107)) |
| 9 | const be_verbose = os.getenv('GITHUB_JOB') != '' || os.getenv('VERBOSE') != '' |
| 10 | |
| 11 | const expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or { |
| 12 | eprintln('skipping test, since expect is missing') |
| 13 | exit(0) |
| 14 | }) |
| 15 | |
| 16 | fn testsuite_begin() { |
| 17 | os.chdir(@VEXEROOT) or {} |
| 18 | os.rmdir_all(test_module_path) or {} |
| 19 | os.mkdir_all(test_module_path) or {} |
| 20 | } |
| 21 | |
| 22 | fn gprintln(msg string) { |
| 23 | println(term.green(msg)) |
| 24 | flush_stdout() |
| 25 | } |
| 26 | |
| 27 | fn gprint(msg string) { |
| 28 | print(term.green(msg)) |
| 29 | flush_stdout() |
| 30 | } |
| 31 | |
| 32 | fn test_debugger() { |
| 33 | all_expect_files := os.walk_ext(expect_tests_path, '.expect') |
| 34 | assert all_expect_files.len > 0, 'no .expect files found in ${expect_tests_path}' |
| 35 | mut oks := 0 |
| 36 | for eidx, efile in all_expect_files.sorted() { |
| 37 | // if !efile.contains('sumtype') { gprintln('skipping ${efile}') continue } |
| 38 | vfile := efile.replace('.expect', '.vv') |
| 39 | output_file := os.join_path(test_module_path, |
| 40 | os.file_name(efile).replace('.expect', '.exe')) |
| 41 | |
| 42 | if be_verbose { |
| 43 | println(bar) |
| 44 | } |
| 45 | gprint('>>>> Running [${eidx + 1:2}/${all_expect_files.len:-2}] ${term.magenta(efile):-68} ... ') |
| 46 | if be_verbose { |
| 47 | println('') |
| 48 | } |
| 49 | |
| 50 | compile_sw := time.new_stopwatch() |
| 51 | comp_res := |
| 52 | os.system('${os.quoted_path(vexe)} -o ${os.quoted_path(output_file)} ${os.quoted_path(vfile)}') |
| 53 | cdur_ms := compile_sw.elapsed().milliseconds() |
| 54 | if be_verbose { |
| 55 | gprintln('>>>>>>>>>>> compilation took ${cdur_ms} ms, comp_res: ${comp_res}') |
| 56 | } |
| 57 | |
| 58 | verbose_options := if be_verbose { '-d' } else { '' } |
| 59 | expect_cmd := '${expect_exe} ${verbose_options} -c "cd ${expect_tests_path}" ${os.quoted_path(efile)} ${os.quoted_path(output_file)} ${os.quoted_path(vfile)}' |
| 60 | if be_verbose { |
| 61 | gprintln(term.cyan(expect_cmd)) |
| 62 | } |
| 63 | sw := time.new_stopwatch() |
| 64 | mut res := 0 |
| 65 | if be_verbose { |
| 66 | res = os.system(expect_cmd) |
| 67 | } else { |
| 68 | result := os.execute(expect_cmd) |
| 69 | res = result.exit_code |
| 70 | if res != 0 { |
| 71 | eprintln(result.output) |
| 72 | } |
| 73 | } |
| 74 | edur_ms := sw.elapsed().milliseconds() |
| 75 | if be_verbose { |
| 76 | gprintln('>>>>>>>>>>> expect took: ${edur_ms} ms, res: ${res}') |
| 77 | } |
| 78 | if res != 0 { |
| 79 | assert false, term.red('failed expect cmd: ${expect_cmd}') |
| 80 | } |
| 81 | assert true |
| 82 | oks++ |
| 83 | if !be_verbose { |
| 84 | gprintln(' c: ${cdur_ms} ms, e: ${edur_ms} ms') |
| 85 | } |
| 86 | } |
| 87 | os.chdir(@VEXEROOT) or {} |
| 88 | os.rmdir_all(test_module_path) or {} |
| 89 | |
| 90 | println(bar) |
| 91 | gprintln('Passed debugger tests: ${term.bold(oks.str())} of ${all_expect_files.len} total.') |
| 92 | } |
| 93 | |