From df167d3ff04cdc90012c8ca39647662ad69e6715 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 26 Jul 2016 10:03:47 -0400 Subject: [PATCH] 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 --- builder/dockerfile/parser/parser.go | 6 +++--- builder/dockerfile/parser/parser_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/dockerfile/parser/parser.go b/builder/dockerfile/parser/parser.go index eefbf0cf39..f34a8f859f 100644 --- a/builder/dockerfile/parser/parser.go +++ b/builder/dockerfile/parser/parser.go @@ -36,19 +36,19 @@ type Node struct { EndLine int // the line in the original dockerfile where the node ends } +const defaultTokenEscape = "\\" + var ( dispatch map[string]func(string) (*Node, map[string]bool, error) tokenWhitespace = regexp.MustCompile(`[\t\v\f\r ]+`) tokenLineContinuation *regexp.Regexp - tokenEscape rune + tokenEscape = rune(defaultTokenEscape[0]) tokenEscapeCommand = regexp.MustCompile(`^#[ \t]*escape[ \t]*=[ \t]*(?P.).*$`) tokenComment = regexp.MustCompile(`^#.*$`) lookingForDirectives bool directiveEscapeSeen bool ) -const defaultTokenEscape = "\\" - // setTokenEscape sets the default token for escaping characters in a Dockerfile. func setTokenEscape(s string) error { if s != "`" && s != "\\" { diff --git a/builder/dockerfile/parser/parser_test.go b/builder/dockerfile/parser/parser_test.go index 1f5aaf5a6a..3c65a4a0a7 100644 --- a/builder/dockerfile/parser/parser_test.go +++ b/builder/dockerfile/parser/parser_test.go @@ -121,11 +121,11 @@ func TestParseWords(t *testing.T) { for _, test := range tests { words := parseWords(test["input"][0]) if len(words) != len(test["expect"]) { - t.Fatalf("length check failed. input: %v, expect: %v, output: %v", test["input"][0], test["expect"], words) + t.Fatalf("length check failed. input: %v, expect: %q, output: %q", test["input"][0], test["expect"], words) } for i, word := range words { if word != test["expect"][i] { - t.Fatalf("word check failed for word: %q. input: %v, expect: %v, output: %v", word, test["input"][0], test["expect"], words) + t.Fatalf("word check failed for word: %q. input: %q, expect: %q, output: %q", word, test["input"][0], test["expect"], words) } } }