v2 / vlib / os / command_test.v
32 lines · 29 sloc · 618 bytes · 10dff915005abd046294b6db847313fbd22a3ede
Raw
1import os
2
3fn test_command() {
4 if os.user_os() == 'windows' {
5 eprintln('>>> skipping command test on windows')
6 return
7 }
8
9 mut cmd := os.start_new_command('ls')!
10 for !cmd.eof {
11 line := cmd.read_line()
12 if line == '' {
13 continue
14 }
15 dump(line)
16 }
17 cmd.close()!
18 assert cmd.exit_code == 0
19
20 eprintln('-------------------------')
21 // This will return a non 0 code
22 mut cmd_to_fail := os.start_new_command('ls -M')!
23 for !cmd_to_fail.eof {
24 line := cmd_to_fail.read_line()
25 if line == '' {
26 continue
27 }
28 dump(line)
29 }
30 cmd_to_fail.close()!
31 assert cmd_to_fail.exit_code != 0 // 2 on linux, 1 on macos
32}
33