Skip to content

Commit 13e8deb

Browse files
committed
test walking variable assignments
1 parent 0c556ae commit 13e8deb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

common/script_parser_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package common
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func Test_parsing_scrip_assignments(t *testing.T) {
10+
input := `
11+
if [[ true ]]; then
12+
export PATH="/path1:$PATH"
13+
else
14+
export PATH="${PATH}:/path2"
15+
fi
16+
PATH=$PATH:/path3
17+
path=$path:/path4
18+
TEST=$PATH:/path5
19+
`
20+
var seenValues string
21+
ForEachVariableAssignment("PATH", input, func(s string) {
22+
seenValues += s
23+
})
24+
assert.Contains(t, seenValues, "/path1")
25+
assert.Contains(t, seenValues, "/path2")
26+
assert.Contains(t, seenValues, "/path3")
27+
assert.NotContains(t, seenValues, "/path4")
28+
assert.NotContains(t, seenValues, "/path5")
29+
}

0 commit comments

Comments
 (0)