| 1 | // vtest build: tinyc |
| 2 | module main |
| 3 | |
| 4 | import v.util.diff |
| 5 | import term |
| 6 | import os |
| 7 | |
| 8 | const vexe = @VEXE |
| 9 | const vroot = os.dir(vexe) |
| 10 | |
| 11 | fn test_cli_programs() { |
| 12 | testdata := os.join_path(vroot, 'vlib/cli/testdata') |
| 13 | mut has_err := false |
| 14 | for test in os.walk_ext(testdata, '.vv') { |
| 15 | print(test + ' ') |
| 16 | out_path := test.all_before_last('.vv') + '.out' |
| 17 | if !os.exists(out_path) { |
| 18 | println(term.red('FAIL')) |
| 19 | eprintln('failed to find output file for `${test}`') |
| 20 | has_err = true |
| 21 | continue |
| 22 | } |
| 23 | expected_out := os.read_file(out_path)!.replace('\r\n', '\n') |
| 24 | test_out := os.execute('${vexe} run ${test}').output.replace('\r\n', '\n') |
| 25 | diff_ := diff.compare_text(expected_out, test_out)! |
| 26 | if diff_ != '' { |
| 27 | println(term.red('FAIL')) |
| 28 | eprintln(diff_) |
| 29 | has_err = true |
| 30 | } else { |
| 31 | println(term.green('OK')) |
| 32 | } |
| 33 | } |
| 34 | assert !has_err |
| 35 | } |
| 36 | |