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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
package main
import (
check "gopkg.in/check.v1"
)
func (s *Suite) TestDetermineUsedVariables_simple(c *check.C) {
G.mkContext = newMkContext()
line := NewLine("fname", "1", "${VAR}", nil)
lines := []*Line{line}
determineUsedVariables(lines)
c.Check(len(G.mkContext.varuse), equals, 1)
c.Check(G.mkContext.varuse["VAR"], equals, line)
}
func (s *Suite) TestDetermineUsedVariables_nested(c *check.C) {
G.mkContext = newMkContext()
line := NewLine("fname", "2", "${outer.${inner}}", nil)
lines := []*Line{line}
determineUsedVariables(lines)
c.Check(len(G.mkContext.varuse), equals, 3)
c.Check(G.mkContext.varuse["inner"], equals, line)
c.Check(G.mkContext.varuse["outer."], equals, line)
c.Check(G.mkContext.varuse["outer.*"], equals, line)
}
func (s *Suite) TestReShellword(c *check.C) {
re := `^(?:` + reShellword + `)$`
matches := check.NotNil
doesntMatch := check.IsNil
c.Check(match("", re), doesntMatch)
c.Check(match("$var", re), matches)
c.Check(match("$var$var", re), matches)
c.Check(match("$var;;", re), doesntMatch) // More than one shellword
c.Check(match("'single-quoted'", re), matches)
c.Check(match("\"", re), doesntMatch) // Incomplete string
c.Check(match("'...'\"...\"", re), matches) // Mixed strings
c.Check(match("\"...\"", re), matches)
c.Check(match("`cat file`", re), matches)
}
func (s *Suite) TestResolveVariableRefs_CircularReference(c *check.C) {
line := NewLine("fname", "1", "dummy", nil)
line.extra["value"] = "${GCC_VERSION}"
G.pkgContext = newPkgContext(".")
G.pkgContext.vardef["GCC_VERSION"] = line // circular reference
resolved := resolveVariableRefs("gcc-${GCC_VERSION}")
c.Check(resolved, equals, "gcc-${GCC_VERSION}")
}
func (s *Suite) TestResolveVariableRefs_Multilevel(c *check.C) {
line1 := NewLine("fname", "dummy", "dummy", nil)
line1.extra["value"] = "${SECOND}"
line2 := NewLine("fname", "dummy", "dummy", nil)
line2.extra["value"] = "${THIRD}"
line3 := NewLine("fname", "dummy", "dummy", nil)
line3.extra["value"] = "got it"
G.pkgContext = newPkgContext(".")
G.pkgContext.vardef["FIRST"] = line1
G.pkgContext.vardef["SECOND"] = line2
G.pkgContext.vardef["THIRD"] = line3
resolved := resolveVariableRefs("you ${FIRST}")
c.Check(resolved, equals, "you got it")
}
func (s *Suite) TestResolveVariableRefs_SpecialChars(c *check.C) {
line := NewLine("fname", "dummy", "dummy", nil)
line.extra["value"] = "x11"
G.pkgContext = newPkgContext("category/pkg")
G.pkgContext.vardef["GST_PLUGINS0.10_TYPE"] = line
resolved := resolveVariableRefs("gst-plugins0.10-${GST_PLUGINS0.10_TYPE}/distinfo")
c.Check(resolved, equals, "gst-plugins0.10-x11/distinfo")
}
func (s *Suite) TestChecklineRcsid(c *check.C) {
lines := s.NewLines("fname",
"$"+"NetBSD: dummy $",
"$"+"NetBSD$",
"$"+"Id: dummy $",
"$"+"Id$",
"$"+"FreeBSD$")
for _, line := range lines {
checklineRcsid(line, ``, "")
}
c.Check(s.Output(), equals, ""+
"ERROR: fname:3: Expected \"$"+"NetBSD$\".\n"+
"ERROR: fname:4: Expected \"$"+"NetBSD$\".\n"+
"ERROR: fname:5: Expected \"$"+"NetBSD$\".\n")
G.isWip = true
for _, line := range lines {
checklineRcsid(line, ``, "")
}
c.Check(s.Output(), equals, ""+
"ERROR: fname:5: Expected \"$"+"NetBSD$\".\n")
}
func (s *Suite) TestChecklineMkAbsolutePathname(c *check.C) {
line := NewLine("Makefile", "1", "dummy", nil)
checklineMkAbsolutePathname(line, "bindir=/bin")
checklineMkAbsolutePathname(line, "bindir=/../lib")
c.Check(s.Output(), equals, "WARN: Makefile:1: Found absolute pathname: /bin\n")
}
func (s *Suite) TestMatchVarassign(c *check.C) {
m, varname, op, value, comment := matchVarassign("C++=c11")
c.Check(m, equals, true)
c.Check(varname, equals, "C+")
c.Check(op, equals, "+=")
c.Check(value, equals, "c11")
c.Check(comment, equals, "")
}
|