aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec_test.go
diff options
context:
space:
mode:
authorGuoliang Wang <iamwgliang@gmail.com>2018-08-28 01:03:37 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-08-28 01:46:11 +0000
commitbe94dac4e945a2921b116761e41f1c22f0af2add (patch)
treec2bc102a5b6eda20d5079a3076a3cfa10164a63f /src/os/exec/exec_test.go
parent2b69ad0b3c9770b6b67c4057c565d6f4c4444d26 (diff)
downloadgo-be94dac4e945a2921b116761e41f1c22f0af2add.tar.gz
go-be94dac4e945a2921b116761e41f1c22f0af2add.zip
os: add ExitCode method to ProcessState
Fixes #26539 Change-Id: I6d403c1bbb552e1f1bdcc09a7ccd60b50617e0fc GitHub-Last-Rev: 0b5262df5d99504523fd7a4665cb70a3cc6b0a09 GitHub-Pull-Request: golang/go#26544 Reviewed-on: https://go-review.googlesource.com/125443 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r--src/os/exec/exec_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index 7bb230806f..f0bba11c5a 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -168,6 +168,49 @@ func TestExitStatus(t *testing.T) {
}
}
+func TestExitCode(t *testing.T) {
+ // Test that exit code are returned correctly
+ cmd := helperCommand(t, "exit", "42")
+ cmd.Run()
+ want := 42
+ got := cmd.ProcessState.ExitCode()
+ if want != got {
+ t.Errorf("ExitCode got %d, want %d", got, want)
+ }
+
+ cmd = helperCommand(t, "/no-exist-executable")
+ cmd.Run()
+ want = 2
+ got = cmd.ProcessState.ExitCode()
+ if want != got {
+ t.Errorf("ExitCode got %d, want %d", got, want)
+ }
+
+ cmd = helperCommand(t, "exit", "255")
+ cmd.Run()
+ want = 255
+ got = cmd.ProcessState.ExitCode()
+ if want != got {
+ t.Errorf("ExitCode got %d, want %d", got, want)
+ }
+
+ cmd = helperCommand(t, "cat")
+ cmd.Run()
+ want = 0
+ got = cmd.ProcessState.ExitCode()
+ if want != got {
+ t.Errorf("ExitCode got %d, want %d", got, want)
+ }
+
+ // Test when command does not call Run().
+ cmd = helperCommand(t, "cat")
+ want = -1
+ got = cmd.ProcessState.ExitCode()
+ if want != got {
+ t.Errorf("ExitCode got %d, want %d", got, want)
+ }
+}
+
func TestPipes(t *testing.T) {
check := func(what string, err error) {
if err != nil {