Closed viharm91 closed 4 years ago
For whoever finds this - the "fix" is to define the variables outside of It
for _, te := range loopableLoop {
expected := te.expected
actual := te.actual
g.It(expected, func() {
g.Assert(expected).Equal(actual)
})
}
Or isolate the context
for _, te := range loopableLoop {
func(te struct {
expected string
actual string
}) {
g.It(te.expected, func() {
g.Assert(te.expected).Equal(te.actual)
})
}(te)
}
possibly even easier would be to:
for _, te := range .. {
te := te
}
This is a common solution and not a problem with Goblin. @viharm91 if it answers your question, can you close the issue?
possibly even easier would be to:
for _, te := range .. { te := te }
This is a common solution and not a problem with Goblin. @viharm91 if it answers your question, can you close the issue?
Thanks @Dynom. Its much simpler fix.
possibly even easier would be to:
for _, te := range .. { te := te }
This is a common solution and not a problem with Goblin. @viharm91 if it answers your question, can you close the issue?
For whoever finds this - the "fix" is to define the variables outside of
It
for _, te := range loopableLoop { expected := te.expected actual := te.actual g.It(expected, func() { g.Assert(expected).Equal(actual) }) }
Or isolate the context
for _, te := range loopableLoop { func(te struct { expected string actual string }) { g.It(te.expected, func() { g.Assert(te.expected).Equal(te.actual) }) }(te) }
Thanks @sockol.
Trying the below code. It should actually fail on first
It
as it has expected and actual values different.