Skip to content

Commit

Permalink
fix f.Close lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjit-bhat committed Jun 10, 2024
1 parent 66d4992 commit 9e561a6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions rpc/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,24 @@ var data = []entry{
}

// tmpWrite writes data to a tmp file and returns the tmp file name.
func tmpWrite(data []byte) (string, error) {
func tmpWrite(t *testing.T, data []byte) string {
f, err := os.CreateTemp("", "")
defer f.Close()
defer func() {
err := f.Close()
if err != nil {
t.Error(err)
}
}()
if err != nil {
return "", err
t.Error(err)
return ""
}
_, err = f.Write(data)
if err != nil {
return "", err
t.Error(err)
return ""
}
return f.Name(), nil
return f.Name()
}

func check(t *testing.T, source, golden string) {
Expand All @@ -53,11 +60,7 @@ func check(t *testing.T, source, golden string) {
}

res := compile(source)
actual, err := tmpWrite(res)
if err != nil {
t.Error(err)
return
}
actual := tmpWrite(t, res)

cmd := exec.Command("diff", "--unified", actual, golden)
diff, err := cmd.CombinedOutput()
Expand Down

0 comments on commit 9e561a6

Please sign in to comment.