@@ -6,7 +6,6 @@ package main_test
6
6
7
7
import (
8
8
"fmt"
9
- "io/ioutil"
10
9
"os"
11
10
"os/exec"
12
11
"path/filepath"
@@ -17,8 +16,7 @@ import (
17
16
)
18
17
19
18
func TestBinary (t * testing.T ) {
20
- exePath , cleanup := build (t )
21
- defer cleanup ()
19
+ exePath := build (t )
22
20
23
21
tests := []struct {
24
22
name string
@@ -139,7 +137,7 @@ func ParseOutput(t *testing.T, dir, output string) ([]Annotation, error) {
139
137
140
138
func ParseDir (dir string ) ([]Annotation , error ) {
141
139
var all []Annotation
142
- files , err := ioutil .ReadDir (dir )
140
+ files , err := os .ReadDir (dir )
143
141
if err != nil {
144
142
return nil , err
145
143
}
@@ -159,7 +157,7 @@ func ParseDir(dir string) ([]Annotation, error) {
159
157
}
160
158
161
159
func ParseFile (file string ) ([]Annotation , error ) {
162
- data , err := ioutil .ReadFile (file )
160
+ data , err := os .ReadFile (file )
163
161
if err != nil {
164
162
return nil , err
165
163
}
@@ -183,24 +181,13 @@ func ParseFile(file string) ([]Annotation, error) {
183
181
return all , nil
184
182
}
185
183
186
- func build (t * testing.T ) (exePath string , cleanup func ()) {
187
- dir , err := ioutil .TempDir ("" , "unconvert_test" )
188
- if err != nil {
189
- t .Fatalf ("failed to create tempdir: %v\n " , err )
190
- }
191
- exePath = filepath .Join (dir , "test_unconvert.exe" )
192
-
193
- cleanup = func () {
194
- err := os .RemoveAll (dir )
195
- if err != nil {
196
- t .Fatal (err )
197
- }
198
- }
184
+ func build (t * testing.T ) (exePath string ) {
185
+ exePath = filepath .Join (t .TempDir (), "test_unconvert.exe" )
199
186
200
187
output , err := exec .Command ("go" , "build" , "-o" , exePath , "." ).CombinedOutput ()
201
188
if err != nil {
202
189
t .Fatalf ("failed to build service program: %v\n %v" , err , string (output ))
203
190
}
204
191
205
- return exePath , cleanup
192
+ return exePath
206
193
}
0 commit comments