Skip to content

Commit 927a333

Browse files
committed
Work around go vet issue with Go v1.11
- go vet in Go v1.11 identifies `Say()` as a print wrapper - go vet will then fail for `Say("%")` because this is not a valid Sprintf template - Because of golang/go#26486, changing the way that the functon is written will work around the vet issue - I have added a comment documenting that this is not ideal in golang/go#26555 (comment)
1 parent ae19f1b commit 927a333

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

gbytes/say_matcher.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ In such cases, Say simply operates on the *gbytes.Buffer returned by Buffer()
3636
If the buffer is closed, the Say matcher will tell Eventually to abort.
3737
*/
3838
func Say(expected string, args ...interface{}) *sayMatcher {
39-
formattedRegexp := expected
4039
if len(args) > 0 {
41-
formattedRegexp = fmt.Sprintf(expected, args...)
40+
expected = fmt.Sprintf(expected, args...)
4241
}
4342
return &sayMatcher{
44-
re: regexp.MustCompile(formattedRegexp),
43+
re: regexp.MustCompile(expected),
4544
}
4645
}
4746

gbytes/say_matcher_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ var _ = Describe("SayMatcher", func() {
4343
Expect(buffer).Should(Say("a%sc", "b"))
4444
})
4545

46+
It("should match literal %", func() {
47+
buffer.Write([]byte("%"))
48+
Expect(buffer).Should(Say("abc%"))
49+
})
50+
4651
It("should use a regular expression", func() {
4752
Expect(buffer).Should(Say("a.c"))
4853
})

0 commit comments

Comments
 (0)