summaryrefslogtreecommitdiff
path: root/pkgtools/pkglint/files/mkshwalker_test.go
blob: fe36292b815c6fc728a52802eac2072b93dd3492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"gopkg.in/check.v1"
)

func (s *Suite) Test_MkShWalker_Walk(c *check.C) {
	list, err := parseShellProgram(dummyLine, ""+
		"if condition; then action; else case selector in pattern) case-item-action ;; esac; fi; "+
		"set -e; cd ${WRKSRC}/locale; "+
		"for lang in *.po; do "+
		"  [ \"$${lang}\" = \"wxstd.po\" ] && continue; "+
		"  ${TOOLS_PATH.msgfmt} -c -o \"$${lang%.po}.mo\" \"$${lang}\"; "+
		"done")
	if c.Check(err, check.IsNil) && c.Check(list, check.NotNil) {
		var commands []string
		(*MkShWalker).Walk(nil, list, func(node interface{}) {
			if cmd, ok := node.(*MkShSimpleCommand); ok {
				commands = append(commands, NewStrCommand(cmd).String())
			}
		})
		c.Check(commands, deepEquals, []string{
			"[] condition []",
			"[] action []",
			"[] case-item-action []",
			"[] set [-e]",
			"[] cd [${WRKSRC}/locale]",
			"[] [ [\"$${lang}\" = \"wxstd.po\" ]]",
			"[] continue []",
			"[] ${TOOLS_PATH.msgfmt} [-c -o \"$${lang%.po}.mo\" \"$${lang}\"]"})
	}
}