2021-07-11 09:52:16 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
const the_source = 'vlib/flag/testdata/usage_example.v'
|
|
|
|
|
|
|
|
const the_executable = os.real_path(os.join_path(os.cache_dir(), 'flag_usage_example_app.exe'))
|
|
|
|
|
|
|
|
fn testsuite_begin() {
|
2021-08-28 08:39:18 +02:00
|
|
|
os.chdir(@VMODROOT) or {}
|
2021-07-11 09:52:16 +02:00
|
|
|
os.rm(the_executable) or {}
|
2022-01-22 20:13:16 +01:00
|
|
|
res := os.execute('${os.quoted_path(@VEXE)} -o ${os.quoted_path(the_executable)} ${os.quoted_path(the_source)}')
|
2021-07-11 09:52:16 +02:00
|
|
|
assert res.exit_code == 0
|
2022-01-22 20:13:16 +01:00
|
|
|
assert os.execute(os.quoted_path(the_executable)).exit_code == 0
|
2021-07-11 09:52:16 +02:00
|
|
|
C.atexit(fn () {
|
|
|
|
os.rm(the_executable) or {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn normalise_lines(lines []string) string {
|
|
|
|
return '\n' + lines.join('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_program(opts string, extension string) {
|
|
|
|
result := the_source.replace('.v', extension)
|
2022-01-22 20:13:16 +01:00
|
|
|
res := os.execute('${os.quoted_path(the_executable)} $opts')
|
2021-07-11 09:52:16 +02:00
|
|
|
assert res.exit_code == 0
|
|
|
|
assert normalise_lines(res.output.split_into_lines()) == normalise_lines(os.read_lines(result) or {
|
|
|
|
panic(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_normal_usage() {
|
|
|
|
check_program('abc def', '.out')
|
|
|
|
check_program(' --help', '.help.out')
|
|
|
|
check_program(' --version', '.version.out')
|
|
|
|
}
|