Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close test descriptor #335

Merged
merged 1 commit into from
Jan 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"golang.org/x/tools/go/analysis/analysistest"

"github.com/quasilyte/go-ruleguard/analyzer"
"github.com/quasilyte/go-ruleguard/ruleguard/goutil"
"github.com/quasilyte/go-ruleguard/ruleguard/irconv"
"github.com/quasilyte/go-ruleguard/ruleguard/irprint"
"golang.org/x/tools/go/analysis/analysistest"
)

var tests = []struct {
Expand Down Expand Up @@ -176,7 +177,10 @@ var rulesFile = %s
if err != nil {
t.Fatal(err)
}
defer os.Remove(mainFile.Name())
defer func() {
mainFile.Close()
os.Remove(mainFile.Name())
}()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, we can rewrite it with https://pkg.go.dev/testing#T.TempDir and just drop folder after a test. However this can be less important than just close a file.

_, err = mainFile.WriteString(fmt.Sprintf(analyzerTemplate, irfileBuf.String()))
if err != nil {
t.Fatal(err)
Expand Down