Skip to content

Commit 36bbf72

Browse files
authored
support [] in IgnoringTopFunction function signatures (#851)
* support [] in IgnoringTopFunction function signatures
1 parent 4ee7ed0 commit 36bbf72

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

gleak/ignoring_top_function.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
// matches a goroutine where the name of the top function is "foo.bar" and the
2626
// goroutine's state starts with "running".
2727
func IgnoringTopFunction(topfname string) types.GomegaMatcher {
28-
if brIndex := strings.Index(topfname, "["); brIndex >= 0 {
29-
expectedState := strings.Trim(topfname[brIndex:], "[]")
30-
expectedTopFunction := strings.Trim(topfname[:brIndex], " ")
28+
if brIndex := strings.Index(topfname, " ["); brIndex >= 0 {
29+
expectedState := strings.Trim(topfname[brIndex+1:], "[]")
30+
expectedTopFunction := strings.Trim(topfname[:brIndex+1], " ")
3131
return &ignoringTopFunctionMatcher{
3232
expectedTopFunction: expectedTopFunction,
3333
expectedState: expectedState,

gleak/ignoring_top_function_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ var _ = Describe("IgnoringTopFunction matcher", func() {
2020
Expect(m.Match(Goroutine{
2121
TopFunction: "main.main",
2222
})).To(BeFalse())
23+
24+
m = IgnoringTopFunction("foo.bar(*implementation[...]).baz")
25+
Expect(m.Match(Goroutine{
26+
TopFunction: "foo.bar(*implementation[...]).baz",
27+
})).To(BeTrue())
28+
Expect(m.Match(Goroutine{
29+
TopFunction: "main.main",
30+
})).To(BeFalse())
2331
})
2432

2533
It("matches a toplevel function by prefix", func() {
@@ -33,6 +41,17 @@ var _ = Describe("IgnoringTopFunction matcher", func() {
3341
Expect(m.Match(Goroutine{
3442
TopFunction: "spanish.inquisition",
3543
})).To(BeFalse())
44+
45+
m = IgnoringTopFunction("foo.bar(*implementation[...])...")
46+
Expect(m.Match(Goroutine{
47+
TopFunction: "foo.bar(*implementation[...]).baz",
48+
})).To(BeTrue())
49+
Expect(m.Match(Goroutine{
50+
TopFunction: "foo",
51+
})).To(BeFalse())
52+
Expect(m.Match(Goroutine{
53+
TopFunction: "spanish.inquisition",
54+
})).To(BeFalse())
3655
})
3756

3857
It("matches a toplevel function by name and state prefix", func() {
@@ -45,6 +64,16 @@ var _ = Describe("IgnoringTopFunction matcher", func() {
4564
TopFunction: "foo.bar",
4665
State: "uneasy, anxious",
4766
})).To(BeFalse())
67+
68+
m = IgnoringTopFunction("foo.bar(*implementation[...]) [worried]")
69+
Expect(m.Match(Goroutine{
70+
TopFunction: "foo.bar(*implementation[...])",
71+
State: "worried, stalled",
72+
})).To(BeTrue())
73+
Expect(m.Match(Goroutine{
74+
TopFunction: "foo.bar(*implementation[...])",
75+
State: "uneasy, anxious",
76+
})).To(BeFalse())
4877
})
4978

5079
It("returns failure messages", func() {

0 commit comments

Comments
 (0)