diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2019-03-20 14:09:51 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2019-03-21 13:19:55 +0000 |
commit | 6249ea2f39958764b88ab1b03cd55cf99dae6bbd (patch) | |
tree | c11589246f59d72ea942f95ae4944f5613f415aa /src/os/exec/exec_test.go | |
parent | eb00167e27ba3525d26bbe9286c82090da782587 (diff) | |
download | go-6249ea2f39958764b88ab1b03cd55cf99dae6bbd.tar.gz go-6249ea2f39958764b88ab1b03cd55cf99dae6bbd.zip |
os/exec: add Cmd.String
The initial implementation is intentionally simple.
Let's see how far it gets us.
Fixes #30638
Change-Id: I240afae2b401744ab2ff2a69952c4eb0fd3feb56
Reviewed-on: https://go-review.googlesource.com/c/go/+/168518
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
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.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 3e6b7bb95e..26be62dd92 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -1150,3 +1150,37 @@ func TestDedupEnvEcho(t *testing.T) { t.Errorf("output = %q; want %q", got, want) } } + +func TestString(t *testing.T) { + echoPath, err := exec.LookPath("echo") + if err != nil { + t.Skip(err) + } + tests := [...]struct { + path string + args []string + want string + }{ + {"echo", nil, echoPath}, + {"echo", []string{"a"}, echoPath + " a"}, + {"echo", []string{"a", "b"}, echoPath + " a b"}, + } + for _, test := range tests { + cmd := exec.Command(test.path, test.args...) + if got := cmd.String(); got != test.want { + t.Errorf("String(%q, %q) = %q, want %q", test.path, test.args, got, test.want) + } + } +} + +func TestStringPathNotResolved(t *testing.T) { + _, err := exec.LookPath("makemeasandwich") + if err == nil { + t.Skip("wow, thanks") + } + cmd := exec.Command("makemeasandwich", "-lettuce") + want := "makemeasandwich -lettuce" + if got := cmd.String(); got != want { + t.Errorf("String(%q, %q) = %q, want %q", "makemeasandwich", "-lettuce", got, want) + } +} |