analyzeCode takes the types scope and the docs and returns the import information and information about all the assertion functions.
(scope *types.Scope, docs *doc.Package)
| 129 | // analyzeCode takes the types scope and the docs and returns the import |
| 130 | // information and information about all the assertion functions. |
| 131 | func analyzeCode(scope *types.Scope, docs *doc.Package) (imports.Importer, []testFunc, error) { |
| 132 | testingT := scope.Lookup("TestingT").Type().Underlying().(*types.Interface) |
| 133 | |
| 134 | importer := imports.New(*outputPkg) |
| 135 | var funcs []testFunc |
| 136 | // Go through all the top level functions |
| 137 | for _, fdocs := range docs.Funcs { |
| 138 | // Find the function |
| 139 | obj := scope.Lookup(fdocs.Name) |
| 140 | |
| 141 | fn, ok := obj.(*types.Func) |
| 142 | if !ok { |
| 143 | continue |
| 144 | } |
| 145 | // Check function signature has at least two arguments |
| 146 | sig := fn.Type().(*types.Signature) |
| 147 | if sig.Params().Len() < 2 { |
| 148 | continue |
| 149 | } |
| 150 | // Check first argument is of type testingT |
| 151 | first, ok := sig.Params().At(0).Type().(*types.Named) |
| 152 | if !ok { |
| 153 | continue |
| 154 | } |
| 155 | firstType, ok := first.Underlying().(*types.Interface) |
| 156 | if !ok { |
| 157 | continue |
| 158 | } |
| 159 | if !types.Implements(firstType, testingT) { |
| 160 | continue |
| 161 | } |
| 162 | |
| 163 | // Skip functions ending with f |
| 164 | if strings.HasSuffix(fdocs.Name, "f") && !*includeF { |
| 165 | continue |
| 166 | } |
| 167 | |
| 168 | funcs = append(funcs, testFunc{*outputPkg, fdocs, fn}) |
| 169 | importer.AddImportsFrom(sig.Params()) |
| 170 | } |
| 171 | return importer, funcs, nil |
| 172 | } |
| 173 | |
| 174 | // parsePackageSource returns the types scope and the package documentation from the package |
| 175 | func parsePackageSource(pkg string) (*types.Scope, *doc.Package, error) { |
no test coverage detected
searching dependent graphs…