Debian Codegraph @

cmd/yaegi/test.go

raw symbols SCIP
1 package mainscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/cmd/yaegi`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.21 errors/"
5 "flagscip-go gomod github.com/golang/go/src go1.21 flag/"
6 "fmtscip-go gomod github.com/golang/go/src go1.21 fmt/"
7 "go/buildscip-go gomod github.com/golang/go/src go1.21 `go/build`/"
8 "osscip-go gomod github.com/golang/go/src go1.21 os/"
9 "path/filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/"
10 "regexpscip-go gomod github.com/golang/go/src go1.21 regexp/"
11 "strconvscip-go gomod github.com/golang/go/src go1.21 strconv/"
12 "stringsscip-go gomod github.com/golang/go/src go1.21 strings/"
13 "testingscip-go gomod github.com/golang/go/src go1.21 testing/"
14
15 "github.com/traefik/yaegi/interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/"
16 "github.com/traefik/yaegi/stdlibscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/"
17 "github.com/traefik/yaegi/stdlib/syscallscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/syscall`/"
18 "github.com/traefik/yaegi/stdlib/unrestrictedscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unrestricted`/"
19 "github.com/traefik/yaegi/stdlib/unsafescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unsafe`/"
20 )
21
22 func testscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/cmd/yaegi`/test().(arg []string) (err error) {
23 var (
24 bench string
25 benchmem bool
26 benchtime string
27 count string
28 cpu string
29 failfast bool
30 run string
31 short bool
32 tags string
33 timeout string
34 verbose bool
35 )
36
37 // The following flags are initialized from environment.
38 useSyscall, _ := strconvscip-go gomod github.com/golang/go/src go1.21 strconv/.ParseBoolscip-go gomod github.com/golang/go/src go1.21 strconv/ParseBool().(osscip-go gomod github.com/golang/go/src go1.21 os/.Getenvscip-go gomod github.com/golang/go/src go1.21 os/Getenv().("YAEGI_SYSCALL"))
39 useUnrestricted, _ := strconvscip-go gomod github.com/golang/go/src go1.21 strconv/.ParseBoolscip-go gomod github.com/golang/go/src go1.21 strconv/ParseBool().(osscip-go gomod github.com/golang/go/src go1.21 os/.Getenvscip-go gomod github.com/golang/go/src go1.21 os/Getenv().("YAEGI_UNRESTRICTED"))
40 useUnsafe, _ := strconvscip-go gomod github.com/golang/go/src go1.21 strconv/.ParseBoolscip-go gomod github.com/golang/go/src go1.21 strconv/ParseBool().(osscip-go gomod github.com/golang/go/src go1.21 os/.Getenvscip-go gomod github.com/golang/go/src go1.21 os/Getenv().("YAEGI_UNSAFE"))
41
42 tflag := flagscip-go gomod github.com/golang/go/src go1.21 flag/.NewFlagSetscip-go gomod github.com/golang/go/src go1.21 flag/NewFlagSet().("test", flagscip-go gomod github.com/golang/go/src go1.21 flag/.ContinueOnErrorscip-go gomod github.com/golang/go/src go1.21 flag/ContinueOnError.)
43 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&bench, "bench", "", "Run only those benchmarks matching a regular expression.")
44 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&benchmem, "benchmem", false, "Print memory allocation statistics for benchmarks.")
45 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&benchtime, "benchtime", "", "Run enough iterations of each benchmark to take t.")
46 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&count, "count", "", "Run each test and benchmark n times (default 1).")
47 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&cpu, "cpu", "", "Specify a list of GOMAXPROCS values for which the tests or benchmarks should be executed.")
48 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&failfast, "failfast", false, "Do not start new tests after the first test failure.")
49 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&run, "run", "", "Run only those tests matching a regular expression.")
50 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&short, "short", false, "Tell long-running tests to shorten their run time.")
51 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&tags, "tags", "", "Set a list of build tags.")
52 tflag.StringVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#StringVar().(&timeout, "timeout", "", "If a test binary runs longer than duration d, panic.")
53 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&useUnrestricted, "unrestricted", useUnrestricted, "Include unrestricted symbols.")
54 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&useUnsafe, "unsafe", useUnsafe, "Include usafe symbols.")
55 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&useSyscall, "syscall", useSyscall, "Include syscall symbols.")
56 tflag.BoolVarscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#BoolVar().(&verbose, "v", false, "Verbose output: log all tests as they are run.")
57 tflag.Usagescip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#Usage. = func() {
58 fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21 fmt/Println().("Usage: yaegi test [options] [path]")
59 fmtscip-go gomod github.com/golang/go/src go1.21 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21 fmt/Println().("Options:")
60 tflag.PrintDefaultsscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#PrintDefaults().()
61 }
62 if err = tflag.Parsescip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#Parse().(arg); err != nil {
63 return err
64 }
65 args := tflag.Argsscip-go gomod github.com/golang/go/src go1.21 flag/FlagSet#Args().()
66 path := "."
67 if len(args) > 0 {
68 path = args[0]
69 }
70
71 // Overwrite os.Args with correct flags to setup testing.Init.
72 tf := []string{""}
73 if bench != "" {
74 tf = append(tf, "-test.bench", bench)
75 }
76 if benchmem {
77 tf = append(tf, "-test.benchmem")
78 }
79 if benchtime != "" {
80 tf = append(tf, "-test.benchtime", benchtime)
81 }
82 if count != "" {
83 tf = append(tf, "-test.count", count)
84 }
85 if cpu != "" {
86 tf = append(tf, "-test.cpu", cpu)
87 }
88 if failfast {
89 tf = append(tf, "-test.failfast")
90 }
91 if run != "" {
92 tf = append(tf, "-test.run", run)
93 }
94 if short {
95 tf = append(tf, "-test.short")
96 }
97 if timeout != "" {
98 tf = append(tf, "-test.timeout", timeout)
99 }
100 if verbose {
101 tf = append(tf, "-test.v")
102 }
103 testingscip-go gomod github.com/golang/go/src go1.21 testing/.Initscip-go gomod github.com/golang/go/src go1.21 testing/Init().()
104 osscip-go gomod github.com/golang/go/src go1.21 os/.Argsscip-go gomod github.com/golang/go/src go1.21 os/Args. = tf
105 flagscip-go gomod github.com/golang/go/src go1.21 flag/.Parsescip-go gomod github.com/golang/go/src go1.21 flag/Parse().()
106 path += string(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Separator.)
107 var dir string
108
109 switch stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(path, string(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Separator.))[0] {
110 case ".", "..", string(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Separator.):
111 dir = path
112 default:
113 dir = filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(buildscip-go gomod github.com/golang/go/src go1.21 `go/build`/.Defaultscip-go gomod github.com/golang/go/src go1.21 `go/build`/Default..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH., "src", path)
114 }
115 if err = osscip-go gomod github.com/golang/go/src go1.21 os/.Chdirscip-go gomod github.com/golang/go/src go1.21 os/Chdir().(dir); err != nil {
116 return err
117 }
118
119 i := interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/.Newscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/New().(interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/.Optionsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#{
120 GoPathscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#GoPath.: buildscip-go gomod github.com/golang/go/src go1.21 `go/build`/.Defaultscip-go gomod github.com/golang/go/src go1.21 `go/build`/Default..GOPATHscip-go gomod github.com/golang/go/src go1.21 `go/build`/Context#GOPATH.,
121 BuildTagsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#BuildTags.: stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(tags, ","),
122 Envscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#Env.: osscip-go gomod github.com/golang/go/src go1.21 os/.Environscip-go gomod github.com/golang/go/src go1.21 os/Environ().(),
123 Unrestrictedscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#Unrestricted.: useUnrestricted,
124 })
125 if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(stdlibscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/Symbols.); err != nil {
126 return err
127 }
128 if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Symbols.); err != nil {
129 return err
130 }
131 if useSyscall {
132 if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(syscallscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/syscall`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/syscall`/Symbols.); err != nil {
133 return err
134 }
135 // Using a environment var allows a nested interpreter to import the syscall package.
136 if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Setenvscip-go gomod github.com/golang/go/src go1.21 os/Setenv().("YAEGI_SYSCALL", "1"); err != nil {
137 return err
138 }
139 }
140 if useUnrestricted {
141 if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(unrestrictedscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unrestricted`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unrestricted`/Symbols.); err != nil {
142 return err
143 }
144 if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Setenvscip-go gomod github.com/golang/go/src go1.21 os/Setenv().("YAEGI_UNRESTRICTED", "1"); err != nil {
145 return err
146 }
147 }
148 if useUnsafe {
149 if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(unsafescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unsafe`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unsafe`/Symbols.); err != nil {
150 return err
151 }
152 if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Setenvscip-go gomod github.com/golang/go/src go1.21 os/Setenv().("YAEGI_UNSAFE", "1"); err != nil {
153 return err
154 }
155 }
156 if err = i.EvalTestscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#EvalTest().(path); err != nil {
157 return err
158 }
159
160 benchmarks := []testingscip-go gomod github.com/golang/go/src go1.21 testing/.InternalBenchmarkscip-go gomod github.com/golang/go/src go1.21 testing/InternalBenchmark#{}
161 tests := []testingscip-go gomod github.com/golang/go/src go1.21 testing/.InternalTestscip-go gomod github.com/golang/go/src go1.21 testing/InternalTest#{}
162 syms, ok := i.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Symbols().(path)[path]
163 if !ok {
164 return errorsscip-go gomod github.com/golang/go/src go1.21 errors/.Newscip-go gomod github.com/golang/go/src go1.21 errors/New().("no tests found")
165 }
166 for name, sym := range syms {
167 switch fun := sym.Interfacescip-go gomod github.com/golang/go/src go1.21 reflect/Value#Interface().().(type) {
168 case func(*testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#):
169 benchmarks = append(benchmarks, testingscip-go gomod github.com/golang/go/src go1.21 testing/.InternalBenchmarkscip-go gomod github.com/golang/go/src go1.21 testing/InternalBenchmark#{name, fun})
170 case func(*testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#):
171 tests = append(tests, testingscip-go gomod github.com/golang/go/src go1.21 testing/.InternalTestscip-go gomod github.com/golang/go/src go1.21 testing/InternalTest#{name, fun})
172 }
173 }
174
175 testingscip-go gomod github.com/golang/go/src go1.21 testing/.Mainscip-go gomod github.com/golang/go/src go1.21 testing/Main().(regexpscip-go gomod github.com/golang/go/src go1.21 regexp/.MatchStringscip-go gomod github.com/golang/go/src go1.21 regexp/MatchString()., tests, benchmarks, nil)
176 return nil
177 }