v / vlib / cli / cli_test.v
35 lines · 32 sloc · 833 bytes · e1b3e5b656a56e08dc0f32f13f4e4f992932d5ec
Raw
1// vtest build: tinyc
2module main
3
4import v.util.diff
5import term
6import os
7
8const vexe = @VEXE
9const vroot = os.dir(vexe)
10
11fn 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