5
5
package interp_test
6
6
7
7
import (
8
- "bytes"
9
- "log"
10
- "os"
11
- "os/exec"
12
8
"path/filepath"
13
9
"reflect"
10
+ "strings"
14
11
"testing"
15
12
16
13
"golang.org/x/tools/internal/testenv"
@@ -19,34 +16,15 @@ import (
19
16
func TestIssue69298 (t * testing.T ) {
20
17
testenv .NeedsGo1Point (t , 23 )
21
18
22
- // TODO: Is cwd actually needed here?
23
19
goroot := makeGoroot (t )
24
- cwd , err := os .Getwd ()
25
- if err != nil {
26
- log .Fatal (err )
27
- }
28
- run (t , filepath .Join (cwd , "testdata" , "fixedbugs/issue69298.go" ), goroot )
20
+ run (t , filepath .Join ("testdata" , "fixedbugs" , "issue69298.go" ), goroot )
29
21
}
30
22
31
- // TestRangeFunc tests range-over-func in a subprocess.
32
23
func TestRangeFunc (t * testing.T ) {
33
24
testenv .NeedsGo1Point (t , 23 )
34
25
35
- // TODO(taking): Remove subprocess from the test and capture output another way.
36
- if os .Getenv ("INTERPTEST_CHILD" ) == "1" {
37
- testRangeFunc (t )
38
- return
39
- }
40
-
41
- testenv .NeedsExec (t )
42
- testenv .NeedsTool (t , "go" )
43
-
44
- cmd := exec .Command (os .Args [0 ], "-test.run=TestRangeFunc" )
45
- cmd .Env = append (os .Environ (), "INTERPTEST_CHILD=1" )
46
- out , err := cmd .CombinedOutput ()
47
- if len (out ) > 0 {
48
- t .Logf ("out=<<%s>>" , out )
49
- }
26
+ goroot := makeGoroot (t )
27
+ out := run (t , filepath .Join ("testdata" , "rangefunc.go" ), goroot )
50
28
51
29
// Check the output of the tests.
52
30
const (
@@ -62,14 +40,14 @@ func TestRangeFunc(t *testing.T) {
62
40
)
63
41
expected := map [string ][]string {
64
42
// rangefunc.go
65
- "TestCheck" : [] string {"i = 45" , CERR_DONE },
66
- "TestCooperativeBadOfSliceIndex" : [] string {RERR_EXHAUSTED , "i = 36" },
67
- "TestCooperativeBadOfSliceIndexCheck" : [] string {CERR_EXHAUSTED , "i = 36" },
68
- "TestTrickyIterAll" : [] string {"i = 36" , RERR_EXHAUSTED },
69
- "TestTrickyIterOne" : [] string {"i = 1" , RERR_EXHAUSTED },
70
- "TestTrickyIterZero" : [] string {"i = 0" , RERR_EXHAUSTED },
71
- "TestTrickyIterZeroCheck" : [] string {"i = 0" , CERR_EXHAUSTED },
72
- "TestTrickyIterEcho" : [] string {
43
+ "TestCheck" : {"i = 45" , CERR_DONE },
44
+ "TestCooperativeBadOfSliceIndex" : {RERR_EXHAUSTED , "i = 36" },
45
+ "TestCooperativeBadOfSliceIndexCheck" : {CERR_EXHAUSTED , "i = 36" },
46
+ "TestTrickyIterAll" : {"i = 36" , RERR_EXHAUSTED },
47
+ "TestTrickyIterOne" : {"i = 1" , RERR_EXHAUSTED },
48
+ "TestTrickyIterZero" : {"i = 0" , RERR_EXHAUSTED },
49
+ "TestTrickyIterZeroCheck" : {"i = 0" , CERR_EXHAUSTED },
50
+ "TestTrickyIterEcho" : {
73
51
"first loop i=0" ,
74
52
"first loop i=1" ,
75
53
"first loop i=3" ,
@@ -79,7 +57,7 @@ func TestRangeFunc(t *testing.T) {
79
57
RERR_EXHAUSTED ,
80
58
"end i=0" ,
81
59
},
82
- "TestTrickyIterEcho2" : [] string {
60
+ "TestTrickyIterEcho2" : {
83
61
"k=0,x=1,i=0" ,
84
62
"k=0,x=2,i=1" ,
85
63
"k=0,x=3,i=3" ,
@@ -89,37 +67,37 @@ func TestRangeFunc(t *testing.T) {
89
67
RERR_EXHAUSTED ,
90
68
"end i=1" ,
91
69
},
92
- "TestBreak1" : [] string {"[1 2 -1 1 2 -2 1 2 -3]" },
93
- "TestBreak2" : [] string {"[1 2 -1 1 2 -2 1 2 -3]" },
94
- "TestContinue" : [] string {"[-1 1 2 -2 1 2 -3 1 2 -4]" },
95
- "TestBreak3" : [] string {"[100 10 2 4 200 10 2 4 20 2 4 300 10 2 4 20 2 4 30]" },
96
- "TestBreak1BadA" : [] string {"[1 2 -1 1 2 -2 1 2 -3]" , RERR_DONE },
97
- "TestBreak1BadB" : [] string {"[1 2]" , RERR_DONE },
98
- "TestMultiCont0" : [] string {"[1000 10 2 4 2000]" },
99
- "TestMultiCont1" : [] string {"[1000 10 2 4]" , RERR_DONE },
100
- "TestMultiCont2" : [] string {"[1000 10 2 4]" , RERR_DONE },
101
- "TestMultiCont3" : [] string {"[1000 10 2 4]" , RERR_DONE },
102
- "TestMultiBreak0" : [] string {"[1000 10 2 4]" , RERR_DONE },
103
- "TestMultiBreak1" : [] string {"[1000 10 2 4]" , RERR_DONE },
104
- "TestMultiBreak2" : [] string {"[1000 10 2 4]" , RERR_DONE },
105
- "TestMultiBreak3" : [] string {"[1000 10 2 4]" , RERR_DONE },
106
- "TestPanickyIterator1" : [] string {panickyIterMsg },
107
- "TestPanickyIterator1Check" : [] string {panickyIterMsg },
108
- "TestPanickyIterator2" : [] string {RERR_MISSING },
109
- "TestPanickyIterator2Check" : [] string {CERR_MISSING },
110
- "TestPanickyIterator3" : [] string {"[100 10 1 2 200 10 1 2]" },
111
- "TestPanickyIterator3Check" : [] string {"[100 10 1 2 200 10 1 2]" },
112
- "TestPanickyIterator4" : [] string {RERR_MISSING },
113
- "TestPanickyIterator4Check" : [] string {CERR_MISSING },
114
- "TestVeryBad1" : [] string {"[1 10]" },
115
- "TestVeryBad2" : [] string {"[1 10]" },
116
- "TestVeryBadCheck" : [] string {"[1 10]" },
117
- "TestOk" : [] string {"[1 10]" },
118
- "TestBreak1BadDefer" : [] string {RERR_DONE , "[1 2 -1 1 2 -2 1 2 -3 -30 -20 -10]" },
119
- "TestReturns" : [] string {"[-1 1 2 -10]" , "[-1 1 2 -10]" , RERR_DONE , "[-1 1 2 -10]" , RERR_DONE },
120
- "TestGotoA" : [] string {"testGotoA1[-1 1 2 -2 1 2 -3 1 2 -4 -30 -20 -10]" , "testGotoA2[-1 1 2 -2 1 2 -3 1 2 -4 -30 -20 -10]" , RERR_DONE , "testGotoA3[-1 1 2 -10]" , RERR_DONE },
121
- "TestGotoB" : [] string {"testGotoB1[-1 1 2 999 -10]" , "testGotoB2[-1 1 2 -10]" , RERR_DONE , "testGotoB3[-1 1 2 -10]" , RERR_DONE },
122
- "TestPanicReturns" : [] string {
70
+ "TestBreak1" : {"[1 2 -1 1 2 -2 1 2 -3]" },
71
+ "TestBreak2" : {"[1 2 -1 1 2 -2 1 2 -3]" },
72
+ "TestContinue" : {"[-1 1 2 -2 1 2 -3 1 2 -4]" },
73
+ "TestBreak3" : {"[100 10 2 4 200 10 2 4 20 2 4 300 10 2 4 20 2 4 30]" },
74
+ "TestBreak1BadA" : {"[1 2 -1 1 2 -2 1 2 -3]" , RERR_DONE },
75
+ "TestBreak1BadB" : {"[1 2]" , RERR_DONE },
76
+ "TestMultiCont0" : {"[1000 10 2 4 2000]" },
77
+ "TestMultiCont1" : {"[1000 10 2 4]" , RERR_DONE },
78
+ "TestMultiCont2" : {"[1000 10 2 4]" , RERR_DONE },
79
+ "TestMultiCont3" : {"[1000 10 2 4]" , RERR_DONE },
80
+ "TestMultiBreak0" : {"[1000 10 2 4]" , RERR_DONE },
81
+ "TestMultiBreak1" : {"[1000 10 2 4]" , RERR_DONE },
82
+ "TestMultiBreak2" : {"[1000 10 2 4]" , RERR_DONE },
83
+ "TestMultiBreak3" : {"[1000 10 2 4]" , RERR_DONE },
84
+ "TestPanickyIterator1" : {panickyIterMsg },
85
+ "TestPanickyIterator1Check" : {panickyIterMsg },
86
+ "TestPanickyIterator2" : {RERR_MISSING },
87
+ "TestPanickyIterator2Check" : {CERR_MISSING },
88
+ "TestPanickyIterator3" : {"[100 10 1 2 200 10 1 2]" },
89
+ "TestPanickyIterator3Check" : {"[100 10 1 2 200 10 1 2]" },
90
+ "TestPanickyIterator4" : {RERR_MISSING },
91
+ "TestPanickyIterator4Check" : {CERR_MISSING },
92
+ "TestVeryBad1" : {"[1 10]" },
93
+ "TestVeryBad2" : {"[1 10]" },
94
+ "TestVeryBadCheck" : {"[1 10]" },
95
+ "TestOk" : {"[1 10]" },
96
+ "TestBreak1BadDefer" : {RERR_DONE , "[1 2 -1 1 2 -2 1 2 -3 -30 -20 -10]" },
97
+ "TestReturns" : {"[-1 1 2 -10]" , "[-1 1 2 -10]" , RERR_DONE , "[-1 1 2 -10]" , RERR_DONE },
98
+ "TestGotoA" : {"testGotoA1[-1 1 2 -2 1 2 -3 1 2 -4 -30 -20 -10]" , "testGotoA2[-1 1 2 -2 1 2 -3 1 2 -4 -30 -20 -10]" , RERR_DONE , "testGotoA3[-1 1 2 -10]" , RERR_DONE },
99
+ "TestGotoB" : {"testGotoB1[-1 1 2 999 -10]" , "testGotoB2[-1 1 2 -10]" , RERR_DONE , "testGotoB3[-1 1 2 -10]" , RERR_DONE },
100
+ "TestPanicReturns" : {
123
101
"Got expected 'f return'" ,
124
102
"Got expected 'g return'" ,
125
103
"Got expected 'h return'" ,
@@ -130,9 +108,9 @@ func TestRangeFunc(t *testing.T) {
130
108
},
131
109
}
132
110
got := make (map [string ][]string )
133
- for _ , ln := range bytes .Split (out , [] byte ( "\n " ) ) {
134
- if ind := bytes .Index (ln , [] byte ( " \t " ) ); ind >= 0 {
135
- n , m := string ( ln [:ind ]), string ( ln [ind + 3 :])
111
+ for _ , ln := range strings .Split (out , "\n " ) {
112
+ if ind := strings .Index (ln , " \t " ); ind >= 0 {
113
+ n , m := ln [:ind ], ln [ind + 3 :]
136
114
got [n ] = append (got [n ], m )
137
115
}
138
116
}
@@ -146,24 +124,4 @@ func TestRangeFunc(t *testing.T) {
146
124
t .Errorf ("No expected output for test %s. got %v" , n , gs )
147
125
}
148
126
}
149
-
150
- var exitcode int
151
- if err , ok := err .(* exec.ExitError ); ok {
152
- exitcode = err .ExitCode ()
153
- }
154
- const want = 0
155
- if exitcode != want {
156
- t .Errorf ("exited %d, want %d" , exitcode , want )
157
- }
158
- }
159
-
160
- func testRangeFunc (t * testing.T ) {
161
- goroot := makeGoroot (t )
162
- cwd , err := os .Getwd ()
163
- if err != nil {
164
- log .Fatal (err )
165
- }
166
-
167
- input := "rangefunc.go"
168
- run (t , filepath .Join (cwd , "testdata" , input ), goroot )
169
127
}
0 commit comments