this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/tdtest: make function detection more robust

Instead of detecting the package (which was already brittle),
test the first argument of the closure of the second argument of
Run. This allows other packages to wrap the tdtest.Run function,
as long as they keep the same signature.

This is necessary to handle errors in cuetest.Run.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: If8dea69244fec9111916df667b0a8c09dc85fa4d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167818
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+14 -8
+14 -8
internal/tdtest/update.go
··· 204 204 return nil, nil 205 205 } 206 206 207 - const ( 208 - typeT = "*cuelang.org/go/internal/tdtest.T" 209 - tdtestParen = `("cuelang.org/go/internal/tdtest")` 210 - ) 207 + const typeT = "*cuelang.org/go/internal/tdtest.T" 211 208 212 209 // findCalls finds all call expressions within a given block for functions 213 210 // or methods defined within the tdtest package. ··· 229 226 info := i.testPkg.TypesInfo 230 227 for _, name := range names { 231 228 if sel.Sel.Name == name { 232 - if info.TypeOf(sel.X).String() == typeT { 233 - } else if ident, ok := sel.X.(*ast.Ident); !ok { 234 - return true // Run method. 235 - } else if id, ok := info.Uses[ident].(*types.PkgName); ok && strings.Contains(id.String(), tdtestParen) { 229 + receiver := info.TypeOf(sel.X).String() 230 + if receiver == typeT { 231 + // Method. 232 + } else if len(c.Args) == 3 { 233 + // Run function. 234 + fn := c.Args[2].(*ast.FuncLit) 235 + if len(fn.Type.Params.List) != 2 { 236 + return true 237 + } 238 + argType := info.TypeOf(fn.Type.Params.List[0].Type).String() 239 + if argType != typeT { 240 + return true 241 + } 236 242 } else { 237 243 return true 238 244 }