@@ -20,6 +20,7 @@ import (
20
20
"log"
21
21
"os"
22
22
"path"
23
+ "regexp"
23
24
"strings"
24
25
"text/template"
25
26
@@ -28,6 +29,7 @@ import (
28
29
29
30
var (
30
31
pkg = flag .String ("assert-path" , "github.com/stretchr/testify/assert" , "Path to the assert package" )
32
+ includeF = flag .Bool ("include-format-funcs" , false , "include format functions such as Errorf and Equalf" )
31
33
outputPkg = flag .String ("output-package" , "" , "package for the resulting code" )
32
34
tmplFile = flag .String ("template" , "" , "What file to load the function template from" )
33
35
out = flag .String ("out" , "" , "What file to write the source code to" )
@@ -157,6 +159,11 @@ func analyzeCode(scope *types.Scope, docs *doc.Package) (imports.Importer, []tes
157
159
continue
158
160
}
159
161
162
+ // Skip functions ending with f
163
+ if strings .HasSuffix (fdocs .Name , "f" ) && ! * includeF {
164
+ continue
165
+ }
166
+
160
167
funcs = append (funcs , testFunc {* outputPkg , fdocs , fn })
161
168
importer .AddImportsFrom (sig .Params ())
162
169
}
@@ -264,10 +271,26 @@ func (f *testFunc) ForwardedParams() string {
264
271
return p
265
272
}
266
273
274
+ func (f * testFunc ) ParamsFormat () string {
275
+ return strings .Replace (f .Params (), "msgAndArgs" , "msg string, args" , 1 )
276
+ }
277
+
278
+ func (f * testFunc ) ForwardedParamsFormat () string {
279
+ return strings .Replace (f .ForwardedParams (), "msgAndArgs" , "append([]interface{}{msg}, args...)" , 1 )
280
+ }
281
+
267
282
func (f * testFunc ) Comment () string {
268
283
return "// " + strings .Replace (strings .TrimSpace (f .DocInfo .Doc ), "\n " , "\n // " , - 1 )
269
284
}
270
285
286
+ func (f * testFunc ) CommentFormat () string {
287
+ search := fmt .Sprintf ("%s" , f .DocInfo .Name )
288
+ replace := fmt .Sprintf ("%sf" , f .DocInfo .Name )
289
+ comment := strings .Replace (f .Comment (), search , replace , - 1 )
290
+ exp := regexp .MustCompile (replace + `\(((\(\)|[^)])+)\)` )
291
+ return exp .ReplaceAllString (comment , replace + `($1, "error message %s", "formatted")` )
292
+ }
293
+
271
294
func (f * testFunc ) CommentWithoutT (receiver string ) string {
272
295
search := fmt .Sprintf ("assert.%s(t, " , f .DocInfo .Name )
273
296
replace := fmt .Sprintf ("%s.%s(" , receiver , f .DocInfo .Name )
0 commit comments