@@ -129,7 +129,11 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
129129 if err := cmd .Run (); err != nil {
130130 return nil , err
131131 }
132- return run (filepath .Join (tmpDir , progBinary ))
132+ p , err := run (filepath .Join (tmpDir , progBinary ))
133+ if err == nil {
134+ log .Printf ("Successfully reflected in directory: %v\n " , dir )
135+ }
136+ return p , err
133137}
134138
135139// reflectMode generates mocks via reflection on an interface.
@@ -152,6 +156,11 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
152156
153157 wd , _ := os .Getwd ()
154158
159+ // Try to run the reflection program in the current working directory.
160+ if p , err := runInDir (program , wd ); err == nil {
161+ return p , nil
162+ }
163+
155164 // Try to run the program in the same directory as the input package.
156165 if p , err := build .Import (importPath , wd , build .FindOnly ); err == nil {
157166 dir := p .Dir
@@ -160,11 +169,7 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
160169 }
161170 }
162171
163- // Since that didn't work, try to run it in the current working directory.
164- if p , err := runInDir (program , wd ); err == nil {
165- return p , nil
166- }
167- // Since that didn't work, try to run it in a standard temp directory.
172+ // Try to run it in a standard temp directory.
168173 return runInDir (program , "" )
169174}
170175
0 commit comments