v / vlib / flag / usage_example_test.v
37 lines · 30 sloc · 1.02 KB · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1import os
2
3const the_source = 'vlib/flag/testdata/usage_example.v'
4
5const the_executable = os.real_path(os.join_path(os.cache_dir(), 'flag_usage_example_app.exe'))
6
7fn testsuite_begin() {
8 os.chdir(@VMODROOT) or {}
9 os.rm(the_executable) or {}
10 res :=
11 os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(the_executable)} ${os.quoted_path(the_source)}')
12 assert res.exit_code == 0
13 assert os.execute(os.quoted_path(the_executable)).exit_code == 0
14}
15
16fn testsuite_end() {
17 os.rm(the_executable) or {}
18}
19
20fn normalise_lines(lines []string) string {
21 return '\n' + lines.join('\n')
22}
23
24fn check_program(opts string, extension string) {
25 result := the_source.replace('.v', extension)
26 res := os.execute('${os.quoted_path(the_executable)} ${opts}')
27 assert res.exit_code == 0
28 assert normalise_lines(res.output.split_into_lines()) == normalise_lines(os.read_lines(result) or {
29 panic(err)
30 })
31}
32
33fn test_normal_usage() {
34 check_program('abc def', '.out')
35 check_program(' --help', '.help.out')
36 check_program(' --version', '.version.out')
37}
38