-
Notifications
You must be signed in to change notification settings - Fork 7
/
gen.go
42 lines (34 loc) · 1.27 KB
/
gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"io"
"text/template"
"github.com/Antonboom/testifylint/internal/checkers"
)
const header = "// Code generated by testifylint/internal/testgen. DO NOT EDIT."
var fm = template.FuncMap{
"NewAssertionExpander": NewAssertionExpander,
"QuoteReport": QuoteReport,
// NOTE(a.telyshev): Sub-template multiple arguments problem (example in BaseTestsGenerator):
// - https://stackoverflow.com/a/18276262
// - https://dev.to/moniquelive/passing-multiple-arguments-to-golang-templates-16h8
"arr": func(elements ...any) []any { return elements },
}
type Executor interface {
Execute(wr io.Writer, data any) error
}
// TestsGenerator provides test and golden file templates and data for them.
// The resulting (executed) files can be used with analysistest.RunWithSuggestedFixes.
//
// GoldenTemplate can be omitted if autocorrection is not possible.
// For example, non-obvious asserts that require human intervention, such as checkers.FloatCompare.
type TestsGenerator interface {
TemplateData() any
ErroredTemplate() Executor
GoldenTemplate() Executor
}
// CheckerTestsGenerator is a TestsGenerator for specific Checker.
// One checker must be covered by one generator.
type CheckerTestsGenerator interface {
TestsGenerator
Checker() checkers.Checker
}