|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "io" |
5 | | - "time" |
6 | | - "reflect" |
7 | | - codspeed "github.com/CodSpeedHQ/codspeed-go/compat/testing" |
8 | | - codspeed_testing "github.com/CodSpeedHQ/codspeed-go/testing/testing" |
| 4 | + "fmt" |
| 5 | + "io" |
| 6 | + "reflect" |
| 7 | + "regexp" |
| 8 | + "time" |
9 | 9 |
|
10 | | - // Import parent package containing the benchmarks |
11 | | -{{#each benchmarks}} |
12 | | - {{import_alias}} "{{module_path}}" |
13 | | -{{/each}} |
| 10 | + codspeed_testing "github.com/CodSpeedHQ/codspeed-go/testing/testing" |
| 11 | + |
| 12 | + // Import parent package containing the benchmarks |
| 13 | + {{#each benchmarks}} |
| 14 | + {{import_alias}} "{{module_path}}" |
| 15 | + {{/each}} |
14 | 16 | ) |
15 | 17 |
|
16 | | -type BenchmarkEntry struct { |
17 | | - Name string |
18 | | - Func func(b *codspeed.B) |
19 | | -} |
| 18 | +// TestDeps is an implementation of the testing.testDeps interface, |
| 19 | +// suitable for passing to [testing.MainStart]. |
| 20 | +// |
| 21 | +// It is partially copied from `testing/internal/testdeps/deps.go`, and |
| 22 | +// only implements the minimum required functionality. |
| 23 | +type TestDeps struct {} |
20 | 24 |
|
21 | | -type corpusEntry = struct { |
22 | | - Parent string |
23 | | - Path string |
24 | | - Data []byte |
25 | | - Values []any |
26 | | - Generation int |
27 | | - IsSeed bool |
28 | | -} |
| 25 | +func (d TestDeps) ImportPath() string { return "" } |
29 | 26 |
|
30 | | -type simpleDeps struct{} |
| 27 | +var matchPat string |
| 28 | +var matchRe *regexp.Regexp |
31 | 29 |
|
32 | | -func (d simpleDeps) ImportPath() string { return "" } |
33 | | -func (d simpleDeps) MatchString(pat, str string) (bool, error) { return true, nil } |
34 | | -func (d simpleDeps) SetPanicOnExit0(bool) {} |
35 | | -func (d simpleDeps) StartCPUProfile(io.Writer) error { return nil } |
36 | | -func (d simpleDeps) StopCPUProfile() {} |
37 | | -func (d simpleDeps) StartTestLog(io.Writer) {} |
38 | | -func (d simpleDeps) StopTestLog() error { return nil } |
39 | | -func (d simpleDeps) WriteProfileTo(string, io.Writer, int) error { return nil } |
| 30 | +func (TestDeps) MatchString(pat, str string) (result bool, err error) { |
| 31 | + if matchRe == nil || matchPat != pat { |
| 32 | + matchPat = pat |
| 33 | + matchRe, err = regexp.Compile(matchPat) |
| 34 | + if err != nil { |
| 35 | + return |
| 36 | + } |
| 37 | + } |
| 38 | + return matchRe.MatchString(str), nil |
| 39 | +} |
| 40 | + |
| 41 | +func (d TestDeps) SetPanicOnExit0(bool) {} |
| 42 | +func (d TestDeps) StartCPUProfile(io.Writer) error { return nil } |
| 43 | +func (d TestDeps) StopCPUProfile() {} |
| 44 | +func (d TestDeps) StartTestLog(io.Writer) {} |
| 45 | +func (d TestDeps) StopTestLog() error { return nil } |
| 46 | +func (d TestDeps) WriteProfileTo(string, io.Writer, int) error { return nil } |
40 | 47 |
|
41 | | -func (d simpleDeps) CoordinateFuzzing( |
42 | | - fuzzTime time.Duration, |
43 | | - fuzzN int64, |
44 | | - minimizeTime time.Duration, |
45 | | - minimizeN int64, |
46 | | - parallel int, |
47 | | - corpus []corpusEntry, |
48 | | - types []reflect.Type, |
49 | | - corpusDir, |
50 | | - cacheDir string, |
51 | | -) error { |
52 | | - return nil |
| 48 | +type corpusEntry = struct { |
| 49 | + Parent string |
| 50 | + Path string |
| 51 | + Data []byte |
| 52 | + Values []any |
| 53 | + Generation int |
| 54 | + IsSeed bool |
53 | 55 | } |
54 | | -func (d simpleDeps) RunFuzzWorker(fn func(corpusEntry) error) error { |
55 | | - return nil |
| 56 | + |
| 57 | +func (d TestDeps) CoordinateFuzzing(fuzzTime time.Duration, fuzzN int64, minimizeTime time.Duration, minimizeN int64, parallel int, corpus []corpusEntry, types []reflect.Type, corpusDir, cacheDir string) error { |
| 58 | + return nil |
56 | 59 | } |
57 | | -func (d simpleDeps) ReadCorpus(dir string, types []reflect.Type) ([]corpusEntry, error) { |
58 | | - return nil, nil |
| 60 | +func (d TestDeps) RunFuzzWorker(fn func(corpusEntry) error) error { return nil } |
| 61 | +func (d TestDeps) ReadCorpus(dir string, types []reflect.Type) ([]corpusEntry, error) { |
| 62 | + return nil, nil |
59 | 63 | } |
60 | | -func (d simpleDeps) CheckCorpus(vals []any, types []reflect.Type) error { |
61 | | - return nil |
| 64 | +func (d TestDeps) CheckCorpus(vals []any, types []reflect.Type) error { |
| 65 | + return nil |
62 | 66 | } |
63 | | -func (d simpleDeps) ResetCoverage() {} |
64 | | -func (d simpleDeps) SnapshotCoverage() {} |
65 | | -func (d simpleDeps) InitRuntimeCoverage() (mode string, tearDown func(coverprofile string, gocoverdir string) (string, error), snapcov func() float64) { |
66 | | - return "", nil, nil |
| 67 | +func (d TestDeps) ResetCoverage() {} |
| 68 | +func (d TestDeps) SnapshotCoverage() {} |
| 69 | +func (d TestDeps) InitRuntimeCoverage() (mode string, tearDown func(coverprofile string, gocoverdir string) (string, error), snapcov func() float64) { |
| 70 | + return "", nil, nil |
67 | 71 | } |
68 | 72 |
|
69 | 73 | func main() { |
70 | | - var tests = []codspeed_testing.InternalTest{} |
71 | | - var fuzzTargets = []codspeed_testing.InternalFuzzTarget{} |
72 | | - var examples = []codspeed_testing.InternalExample{} |
73 | | - var benchmarks = []codspeed_testing.InternalBenchmark{ |
74 | | -{{#each benchmarks}} |
75 | | - {"{{name}}", {{qualified_name}}}, |
76 | | -{{/each}} |
77 | | - } |
| 74 | + var tests = []codspeed_testing.InternalTest{} |
| 75 | + var fuzzTargets = []codspeed_testing.InternalFuzzTarget{} |
| 76 | + var examples = []codspeed_testing.InternalExample{} |
| 77 | + var benchmarks = []codspeed_testing.InternalBenchmark{ |
| 78 | + {{#each benchmarks}} |
| 79 | + {"{{name}}", {{qualified_name}}}, |
| 80 | + {{/each}} |
| 81 | + } |
78 | 82 |
|
79 | | - m := codspeed_testing.MainStart(simpleDeps{}, tests, benchmarks, fuzzTargets, examples) |
80 | | - m.Run() |
| 83 | + m := codspeed_testing.MainStart(TestDeps{}, tests, benchmarks, fuzzTargets, examples) |
| 84 | + m.Run() |
81 | 85 | } |
0 commit comments