1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-27 01:33:39 +02:00

test: remove redundant os.Exit in TestMain (#5257)

This PR simplifies tests by removing redundant `os.Exit` calls in
`TestMain` functions.

As of Go 1.15, we do not need to call `os.Exit(m.Run())` explicitly, as
value returned by `m.Run()` is stored into unexported field of `m` and
go test executable is smart enough to automatically call
`os.Exit(retValue)` when `TestMain` returns. See golang/go#34129.
This commit is contained in:
Oleksandr Redko 2024-11-09 20:10:14 +02:00 committed by GitHub
parent e5862356a5
commit 5a1353ddfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 12 deletions

View File

@ -11,5 +11,5 @@ func TestMain(m *testing.M) {
return
}
os.Exit(m.Run())
m.Run()
}

View File

@ -1,7 +1,6 @@
package before
import (
"os"
"path/filepath"
"testing"
@ -15,9 +14,8 @@ import (
func TestMain(m *testing.M) {
log.SetLevel(log.DebugLevel)
code := m.Run()
m.Run()
log.SetLevel(log.InfoLevel)
os.Exit(code)
}
func TestDescription(t *testing.T) {

View File

@ -30,7 +30,8 @@ var listen string
func TestMain(m *testing.M) {
if !testlib.InPath("docker") {
os.Exit(m.Run())
m.Run()
return
}
prepareEnv()
@ -67,10 +68,9 @@ func TestMain(m *testing.M) {
}))
listen = "localhost:" + resource.GetPort("9000/tcp")
code := m.Run()
m.Run()
requireNoErr(pool.Purge(resource))
os.Exit(code)
}
func TestMinioUpload(t *testing.T) {

View File

@ -24,13 +24,11 @@ func TestMain(m *testing.M) {
}
}
code := m.Run()
m.Run()
for k, v := range restores {
_ = os.Setenv(k, v)
}
os.Exit(code)
}
func TestDescription(t *testing.T) {

View File

@ -46,9 +46,8 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
code := m.Run()
m.Run()
_ = os.RemoveAll(keyring)
os.Exit(code)
}
func TestDescription(t *testing.T) {