@@ -6,7 +6,6 @@ package main_test
66
77import (
88 "fmt"
9- "io/ioutil"
109 "os"
1110 "os/exec"
1211 "path/filepath"
@@ -17,8 +16,7 @@ import (
1716)
1817
1918func TestBinary (t * testing.T ) {
20- exePath , cleanup := build (t )
21- defer cleanup ()
19+ exePath := build (t )
2220
2321 tests := []struct {
2422 name string
@@ -139,7 +137,7 @@ func ParseOutput(t *testing.T, dir, output string) ([]Annotation, error) {
139137
140138func ParseDir (dir string ) ([]Annotation , error ) {
141139 var all []Annotation
142- files , err := ioutil .ReadDir (dir )
140+ files , err := os .ReadDir (dir )
143141 if err != nil {
144142 return nil , err
145143 }
@@ -159,7 +157,7 @@ func ParseDir(dir string) ([]Annotation, error) {
159157}
160158
161159func ParseFile (file string ) ([]Annotation , error ) {
162- data , err := ioutil .ReadFile (file )
160+ data , err := os .ReadFile (file )
163161 if err != nil {
164162 return nil , err
165163 }
@@ -183,24 +181,13 @@ func ParseFile(file string) ([]Annotation, error) {
183181 return all , nil
184182}
185183
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" )
199186
200187 output , err := exec .Command ("go" , "build" , "-o" , exePath , "." ).CombinedOutput ()
201188 if err != nil {
202189 t .Fatalf ("failed to build service program: %v\n %v" , err , string (output ))
203190 }
204191
205- return exePath , cleanup
192+ return exePath
206193}
0 commit comments