MCPcopy Index your code
hub / github.com/coder/coder / TestParse

Function TestParse

coderd/util/shellparse/shellparse_test.go:12–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestParse(t *testing.T) {
13 t.Parallel()
14
15 cases := []struct {
16 name string
17 in string
18 want [][]string
19 }{
20 {
21 name: "chained-git-workflow",
22 in: `cd /path && git pull && git add . && git commit -m "x"`,
23 want: [][]string{{"cd", "/path"}, {"git", "pull"}, {"git", "add"}, {"git", "commit"}},
24 },
25 {
26 name: "single-command-with-flags",
27 in: `ls -la /tmp`,
28 want: [][]string{{"ls", "/tmp"}},
29 },
30 {
31 name: "no-arg",
32 in: `pwd`,
33 want: [][]string{{"pwd"}},
34 },
35 {
36 name: "find-xargs-grep-pipeline",
37 in: `find /repo -type f | xargs grep "foo" 2>/dev/null | grep -i "bar" | head -30`,
38 want: [][]string{{"find", "/repo"}, {"xargs", "grep"}, {"grep", "bar"}, {"head"}},
39 },
40 {
41 name: "stash-build-pop-exit",
42 // "ES=$?" is a pure assignment; not a command.
43 in: `cd /repo && git stash && go build ./... 2>&1; ES=$?; git stash pop 2>&1 | tail -1; exit $ES`,
44 want: [][]string{
45 {"cd", "/repo"},
46 {"git", "stash"},
47 {"go", "build"},
48 {"git", "stash"},
49 {"tail"},
50 {"exit"},
51 },
52 },
53 {
54 name: "command-substitution-and-if",
55 in: `cd /repo && TOKEN=$(cat /tmp/tok || echo "") && if [ -n "$TOKEN" ]; then echo "$TOKEN" | gh auth login --with-token; else echo "missing"; fi`,
56 want: [][]string{
57 {"cd", "/repo"},
58 {"cat", "/tmp/tok"},
59 {"echo"},
60 {"[", "]"},
61 {"echo"},
62 {"gh", "auth"},
63 {"echo", "missing"},
64 },
65 },
66 {
67 name: "for-loop-with-sed",
68 in: `cd /repo && for line in 1 2 3; do
69 sed -i "${line}s|a|b|" file

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected