| 1 | import os |
| 2 | |
| 3 | const the_source = 'vlib/flag/testdata/usage_example.v' |
| 4 | |
| 5 | const the_executable = os.real_path(os.join_path(os.cache_dir(), 'flag_usage_example_app.exe')) |
| 6 | |
| 7 | fn 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 | |
| 16 | fn testsuite_end() { |
| 17 | os.rm(the_executable) or {} |
| 18 | } |
| 19 | |
| 20 | fn normalise_lines(lines []string) string { |
| 21 | return '\n' + lines.join('\n') |
| 22 | } |
| 23 | |
| 24 | fn 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 | |
| 33 | fn test_normal_usage() { |
| 34 | check_program('abc def', '.out') |
| 35 | check_program(' --help', '.help.out') |
| 36 | check_program(' --version', '.version.out') |
| 37 | } |
| 38 | |