Browse code

Fix issue with test ordering for TestParseWords

`TestParseWords` needs to use the `tokenEscape` for one of the test
cases, but `tokenEscape` was not being set unless tests ran in a
specific order.
This sets a default value for `tokenEscape`... `\`... so that tests that
rely on this global are not affected by test ordering.

This is the simplest fix for these cases. Ideally the token should not
be set as a global but rather passed down, which is a much larger
change.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit df167d3ff04cdc90012c8ca39647662ad69e6715)
Signed-off-by: Tibor Vass <tibor@docker.com>

Brian Goff authored on 2016/07/26 23:03:47
Showing 2 changed files
... ...
@@ -36,19 +36,19 @@ type Node struct {
36 36
 	EndLine    int             // the line in the original dockerfile where the node ends
37 37
 }
38 38
 
39
+const defaultTokenEscape = "\\"
40
+
39 41
 var (
40 42
 	dispatch              map[string]func(string) (*Node, map[string]bool, error)
41 43
 	tokenWhitespace       = regexp.MustCompile(`[\t\v\f\r ]+`)
42 44
 	tokenLineContinuation *regexp.Regexp
43
-	tokenEscape           rune
45
+	tokenEscape           = rune(defaultTokenEscape[0])
44 46
 	tokenEscapeCommand    = regexp.MustCompile(`^#[ \t]*escape[ \t]*=[ \t]*(?P<escapechar>.).*$`)
45 47
 	tokenComment          = regexp.MustCompile(`^#.*$`)
46 48
 	lookingForDirectives  bool
47 49
 	directiveEscapeSeen   bool
48 50
 )
49 51
 
50
-const defaultTokenEscape = "\\"
51
-
52 52
 // setTokenEscape sets the default token for escaping characters in a Dockerfile.
53 53
 func setTokenEscape(s string) error {
54 54
 	if s != "`" && s != "\\" {
... ...
@@ -121,11 +121,11 @@ func TestParseWords(t *testing.T) {
121 121
 	for _, test := range tests {
122 122
 		words := parseWords(test["input"][0])
123 123
 		if len(words) != len(test["expect"]) {
124
-			t.Fatalf("length check failed. input: %v, expect: %v, output: %v", test["input"][0], test["expect"], words)
124
+			t.Fatalf("length check failed. input: %v, expect: %q, output: %q", test["input"][0], test["expect"], words)
125 125
 		}
126 126
 		for i, word := range words {
127 127
 			if word != test["expect"][i] {
128
-				t.Fatalf("word check failed for word: %q. input: %v, expect: %v, output: %v", word, test["input"][0], test["expect"], words)
128
+				t.Fatalf("word check failed for word: %q. input: %q, expect: %q, output: %q", word, test["input"][0], test["expect"], words)
129 129
 			}
130 130
 		}
131 131
 	}