1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package testdeps provides access to dependencies needed by test execution.
7 // This package is imported by the generated main package, which passes
8 // TestDeps into testing.Main. This allows tests to use packages at run time
9 // without making those packages direct dependencies of package testing.
10 // Direct dependencies of package testing are harder to write tests for.
19 // TestDeps is an implementation of the testing.testDeps interface,
20 // suitable for passing to testing.MainStart.
21 type TestDeps struct{}
24 var matchRe *regexp.Regexp
26 func (TestDeps) MatchString(pat, str string) (result bool, err error) {
27 if matchRe == nil || matchPat != pat {
29 matchRe, err = regexp.Compile(matchPat)
34 return matchRe.MatchString(str), nil
37 func (TestDeps) StartCPUProfile(w io.Writer) error {
38 return pprof.StartCPUProfile(w)
41 func (TestDeps) StopCPUProfile() {
42 pprof.StopCPUProfile()
45 func (TestDeps) WriteHeapProfile(w io.Writer) error {
46 return pprof.WriteHeapProfile(w)
49 func (TestDeps) WriteProfileTo(name string, w io.Writer, debug int) error {
50 return pprof.Lookup(name).WriteTo(w, debug)