1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add an .exit_code field to os.Command (#13321)

* Added os.Command.exit_code

* vfmt vlib/os/os_test.v

* extract os.Command to os.v, add a dummy panicing implementation on windows, just for parity, fix os_test.v on macos, skip test_command on windows.

Co-authored-by: Merlin Diavova <md@merlindiaova.org>
Co-authored-by: Delyan Angelov <delian66@gmail.com>
This commit is contained in:
Merlin Diavova
2022-01-29 22:44:52 +00:00
committed by GitHub
parent eb7f152f3d
commit f3683b7cdc
4 changed files with 61 additions and 13 deletions

View File

@@ -861,3 +861,36 @@ fn test_execute() ? {
assert hexresult.starts_with('7374617274004d4944444c450066696e697368')
assert hexresult.ends_with('0a7878')
}
fn test_command() {
if os.user_os() == 'windows' {
eprintln('>>> os.Command is not implemented fully on Windows yet')
return
}
mut cmd := os.Command{
path: 'ls'
}
cmd.start() or { panic(err) }
for !cmd.eof {
cmd.read_line()
}
cmd.close() or { panic(err) }
// dump( cmd )
assert cmd.exit_code == 0
// This will return a non 0 code
mut cmd_to_fail := os.Command{
path: 'ls -M'
}
cmd_to_fail.start() or { panic(err) }
for !cmd_to_fail.eof {
cmd_to_fail.read_line()
}
cmd_to_fail.close() or { panic(err) }
// dump( cmd_to_fail )
assert cmd_to_fail.exit_code != 0 // 2 on linux, 1 on macos
}