| 1 | import os |
| 2 | |
| 3 | const source = 'vlib/flag/testdata/simplest_flag_program.v' |
| 4 | |
| 5 | const simple_flag_app_executable = os.real_path(os.join_path(os.cache_dir(), 'simple_flag_app.exe')) |
| 6 | |
| 7 | fn testsuite_begin() { |
| 8 | os.chdir(@VMODROOT) or {} |
| 9 | os.rm(simple_flag_app_executable) or {} |
| 10 | res := |
| 11 | os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(simple_flag_app_executable)} ${os.quoted_path(source)}') |
| 12 | assert res.exit_code == 0 |
| 13 | assert os.execute(simple_flag_app_executable).exit_code == 0 |
| 14 | } |
| 15 | |
| 16 | fn testsuite_end() { |
| 17 | os.rm(simple_flag_app_executable) or {} |
| 18 | assert true |
| 19 | } |
| 20 | |
| 21 | fn check_program(opts string, extension string) { |
| 22 | result := source.replace('.v', extension) |
| 23 | res := os.execute('${os.quoted_path(simple_flag_app_executable)} ${opts}') |
| 24 | lines := os.read_lines(result) or { panic(err) } |
| 25 | assert res.exit_code == 0 |
| 26 | assert res.output.split_into_lines() == lines |
| 27 | } |
| 28 | |
| 29 | fn test_default_builtin_flag_options() { |
| 30 | check_program('', '.out') |
| 31 | check_program(' -- --help', '.dashdash.help.out') |
| 32 | check_program(' -- --version', '.dashdash.version.out') |
| 33 | check_program(' -h', '.help.out') |
| 34 | check_program(' --help', '.help.out') |
| 35 | check_program(' --version', '.version.out') |
| 36 | } |
| 37 | |