Debian Codegraph @

interp/interp_file_test.go

raw symbols SCIP
1 package interp_testscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.21 bytes/"
5 "go/buildscip-go gomod github.com/golang/go/src go1.21 `go/build`/"
6 "go/parserscip-go gomod github.com/golang/go/src go1.21 `go/parser`/"
7 "go/tokenscip-go gomod github.com/golang/go/src go1.21 `go/token`/"
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 "runtimescip-go gomod github.com/golang/go/src go1.21 runtime/"
11 "stringsscip-go gomod github.com/golang/go/src go1.21 strings/"
12 "testingscip-go gomod github.com/golang/go/src go1.21 testing/"
13
14 "github.com/traefik/yaegi/interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/"
15 "github.com/traefik/yaegi/stdlibscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/"
16 "github.com/traefik/yaegi/stdlib/unsafescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib/unsafe`/"
17 )
18
19 // The following tests sometimes (not always) crash with go1.21 but not with go1.20 or go1.22.
20 // The reason of failure is not obvious, maybe due to the runtime itself, and will be investigated separately.
21 // Also, the closure tests depend on an incompatible language change in go1.22, where `for` variables are now
22 // defined in body (thus reallocated at each loop). This is now the behavior in yaegi, so 1.21 produces
23 // different results.
24 var testsToSkipGo121scip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/testsToSkipGo121. = map[string]bool{"cli6.go": true, "cli7.go": true, "issue-1276.go": true, "issue-1330.go": true, "struct11.go": true, "closure9.go": true, "closure10.go": true, "closure11.go": true, "closure12.go": true, "closure15.go": true, "closure16.go": true, "closure17.go": true, "closure18.go": true, "closure20.go": true, "for17.go": true, "for18.go": true, "for19.go": true}
25
26 var go121scip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/go121. = stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(runtimescip-go gomod github.com/golang/go/src go1.21 runtime/.Versionscip-go gomod github.com/golang/go/src go1.21 runtime/Version().(), "go1.21")
27
28 func TestFilescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/TestFile().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) {
29 filePath := "../_test/str.go"
30 runCheckscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/runCheck().(t, filePath)
31
32 t.Setenvscip-go gomod github.com/golang/go/src go1.21 testing/T#Setenv().("YAEGI_SPECIAL_STDIO", "1")
33
34 baseDir := 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().("..", "_test")
35 files, err := osscip-go gomod github.com/golang/go/src go1.21 os/.ReadDirscip-go gomod github.com/golang/go/src go1.21 os/ReadDir().(baseDir)
36 if err != nil {
37 t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err)
38 }
39
40 for _, file := range files {
41 if filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Extscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Ext().(file.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()) != ".go" {
42 continue
43 }
44 // Skip some tests which are problematic in go1.21 only.
45 if go121scip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/go121. && testsToSkipGo121scip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/testsToSkipGo121.[file.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()] {
46 continue
47 }
48 file := file
49 t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(file.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().(), func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) {
50 runCheckscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/runCheck().(t, 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().(baseDir, file.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()))
51 })
52 }
53 }
54
55 func runCheckscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/runCheck().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#, p string) {
56 t.Helperscip-go gomod github.com/golang/go/src go1.21 testing/common#Helper().()
57
58 wanted, goPath, errWanted := wantedFromCommentscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/wantedFromComment().(p)
59 if wanted == "" {
60 t.Skipscip-go gomod github.com/golang/go/src go1.21 testing/common#Skip().(p, "has no comment 'Output:' or 'Error:'")
61 }
62 wanted = stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.21 strings/TrimSpace().(wanted)
63
64 if goPath == "" {
65 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.
66 }
67 var stdout, stderr bytesscip-go gomod github.com/golang/go/src go1.21 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.21 bytes/Buffer#
68 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#{GoPathscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#GoPath.: goPath, Stdoutscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#Stdout.: &stdout, Stderrscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#Stderr.: &stderr})
69 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 {
70 t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err)
71 }
72 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 {
73 t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err)
74 }
75 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 {
76 t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err)
77 }
78
79 _, err := i.EvalPathscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#EvalPath().(p)
80 if errWanted {
81 if err == nil {
82 t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("got nil error, want: %q", wanted)
83 }
84 if res := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.21 strings/TrimSpace().(err.Error()); !stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Containsscip-go gomod github.com/golang/go/src go1.21 strings/Contains().(res, wanted) {
85 t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("got %q, want: %q", res, wanted)
86 }
87 return
88 }
89
90 if err != nil {
91 t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err)
92 }
93
94 res := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.21 strings/TrimSpace().(stdout.Stringscip-go gomod github.com/golang/go/src go1.21 bytes/Buffer#String().())
95 // Remove path in output, to have results independent of location.
96 res = stringsscip-go gomod github.com/golang/go/src go1.21 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.21 strings/ReplaceAll().(res, filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(p)+":", "")
97 if res != wanted {
98 t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("\ngot: %q,\nwant: %q", res, wanted)
99 }
100 }
101
102 func wantedFromCommentscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp_test`/wantedFromComment().(p string) (res string, goPath string, err bool) {
103 fset := tokenscip-go gomod github.com/golang/go/src go1.21 `go/token`/.NewFileSetscip-go gomod github.com/golang/go/src go1.21 `go/token`/NewFileSet().()
104 f, _ := parserscip-go gomod github.com/golang/go/src go1.21 `go/parser`/.ParseFilescip-go gomod github.com/golang/go/src go1.21 `go/parser`/ParseFile().(fset, p, nil, parserscip-go gomod github.com/golang/go/src go1.21 `go/parser`/.ParseCommentsscip-go gomod github.com/golang/go/src go1.21 `go/parser`/ParseComments.)
105 if len(f.Commentsscip-go gomod github.com/golang/go/src go1.21 `go/ast`/File#Comments.) == 0 {
106 return
107 }
108 text := f.Commentsscip-go gomod github.com/golang/go/src go1.21 `go/ast`/File#Comments.[len(f.Commentsscip-go gomod github.com/golang/go/src go1.21 `go/ast`/File#Comments.)-1].Textscip-go gomod github.com/golang/go/src go1.21 `go/ast`/CommentGroup#Text().()
109 if stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(text, "GOPATH:") {
110 parts := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.SplitNscip-go gomod github.com/golang/go/src go1.21 strings/SplitN().(text, "\n", 2)
111 text = parts[1]
112 wd, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Getwdscip-go gomod github.com/golang/go/src go1.21 os/Getwd().()
113 if err != nil {
114 panic(err)
115 }
116 goPath = 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().(wd, "..", "_test", stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(parts[0], "GOPATH:"))
117 }
118 if stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(text, "Output:\n") {
119 return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(text, "Output:\n"), goPath, false
120 }
121 if stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(text, "Error:\n") {
122 return stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(text, "Error:\n"), goPath, true
123 }
124 return
125 }