Skip to content

Commit 4e76bb4

Browse files
committed
cmd/cue/cmd: improve shell arg parsing in tests
Prepares for Issue #1270 Change-Id: I28d22856b5a96d1a960b610b8a6139b479356199 Signed-off-by: Marcel van Lohuizen <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/527870 Unity-Result: CUEcueckoo <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 0e56b82 commit 4e76bb4

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

cmd/cue/cmd/script_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"strings"
2828
"testing"
2929

30+
"github.com/google/shlex"
3031
"github.com/rogpeppe/go-internal/goproxytest"
3132
"github.com/rogpeppe/go-internal/gotooltest"
3233
"github.com/rogpeppe/go-internal/testscript"
@@ -154,13 +155,10 @@ func TestX(t *testing.T) {
154155
continue
155156
}
156157

157-
// TODO: Ugly hack to get args. Do more principled parsing.
158-
var args []string
159-
for _, a := range strings.Split(cmd, " ")[1:] {
160-
args = append(args, strings.Trim(a, "'"))
161-
}
158+
args, err := shlex.Split(cmd)
159+
check(err)
162160

163-
c, err := New(args)
161+
c, err := New(args[1:])
164162
check(err)
165163
b := &bytes.Buffer{}
166164
c.SetOutput(b)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ require (
55
github.com/cockroachdb/apd/v2 v2.0.1
66
github.com/emicklei/proto v1.6.15
77
github.com/google/go-cmp v0.4.0
8+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
89
github.com/google/uuid v1.2.0
910
github.com/kr/pretty v0.1.0
1011
github.com/kylelemons/godebug v1.1.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
4545
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
4646
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
4747
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
48+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
49+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
4850
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
4951
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5052
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=

0 commit comments

Comments
 (0)