|
| 1 | +import os |
| 2 | + |
| 3 | +const qvexe = os.quoted_path(@VEXE) |
| 4 | + |
| 5 | +fn depend_on_command(cmd string) ? { |
| 6 | + path := os.find_abs_path_of_executable(cmd) or { |
| 7 | + println('skip: ${cmd} not found') |
| 8 | + return none |
| 9 | + } |
| 10 | + res := os.execute('${os.quoted_path(path)} --version') |
| 11 | + if res.exit_code != 0 { |
| 12 | + println('skip: ${cmd} does not support --version') |
| 13 | + return none |
| 14 | + } |
| 15 | + if !res.output.contains('GNU coreutils') { |
| 16 | + println('skip: ${cmd} is not from coreutils') |
| 17 | + return none |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +fn test_normal_exit_without_timeout_echo() { |
| 22 | + depend_on_command('echo') or { return } |
| 23 | + ee := os.execute('${qvexe} timeout 0.2 echo') |
| 24 | + assert ee.exit_code == 0, ee.output |
| 25 | + res := os.execute('${qvexe} timeout 0.2 echo z123') |
| 26 | + assert res.exit_code == 0, res.output |
| 27 | + assert res.output.contains('z123') |
| 28 | +} |
| 29 | + |
| 30 | +fn test_normal_exit_without_timeout_sleep() { |
| 31 | + depend_on_command('sleep') or { return } |
| 32 | + res := os.execute('${qvexe} timeout 0.4 sleep 0.1') |
| 33 | + assert res.exit_code == 0, res.output |
| 34 | + assert res.output == '' |
| 35 | +} |
| 36 | + |
| 37 | +fn test_exit_with_timeout() { |
| 38 | + depend_on_command('sleep') or { return } |
| 39 | + res := os.execute('${qvexe} timeout 0.2 sleep 2') |
| 40 | + assert res.exit_code == 124, res.output |
| 41 | +} |
0 commit comments