mirror of
https://github.com/golang/go
synced 2024-11-25 06:47:56 -07:00
all: move defers to after error check to avoid nil indirection
Only affects some tests and none seem likely to be problematic, but let's fix them. Fixes #3971. R=golang-dev, iant CC=golang-dev https://golang.org/cl/6463060
This commit is contained in:
parent
95a00cae2e
commit
deb53889c2
@ -161,10 +161,10 @@ func TestTransportConnectionCloseOnResponse(t *testing.T) {
|
|||||||
t.Fatalf("error in connectionClose=%v, req #%d, Do: %v", connectionClose, n, err)
|
t.Fatalf("error in connectionClose=%v, req #%d, Do: %v", connectionClose, n, err)
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
defer res.Body.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error in connectionClose=%v, req #%d, ReadAll: %v", connectionClose, n, err)
|
t.Fatalf("error in connectionClose=%v, req #%d, ReadAll: %v", connectionClose, n, err)
|
||||||
}
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
return string(body)
|
return string(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,10 +69,10 @@ var sysdir = func() (sd *sysDir) {
|
|||||||
|
|
||||||
func size(name string, t *testing.T) int64 {
|
func size(name string, t *testing.T) int64 {
|
||||||
file, err := Open(name)
|
file, err := Open(name)
|
||||||
defer file.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("open failed:", err)
|
t.Fatal("open failed:", err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
var buf [100]byte
|
var buf [100]byte
|
||||||
len := 0
|
len := 0
|
||||||
for {
|
for {
|
||||||
@ -134,10 +134,10 @@ func TestStat(t *testing.T) {
|
|||||||
func TestFstat(t *testing.T) {
|
func TestFstat(t *testing.T) {
|
||||||
path := sfdir + "/" + sfname
|
path := sfdir + "/" + sfname
|
||||||
file, err1 := Open(path)
|
file, err1 := Open(path)
|
||||||
defer file.Close()
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
t.Fatal("open failed:", err1)
|
t.Fatal("open failed:", err1)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
dir, err2 := file.Stat()
|
dir, err2 := file.Stat()
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
t.Fatal("fstat failed:", err2)
|
t.Fatal("fstat failed:", err2)
|
||||||
@ -189,10 +189,10 @@ func TestRead0(t *testing.T) {
|
|||||||
|
|
||||||
func testReaddirnames(dir string, contents []string, t *testing.T) {
|
func testReaddirnames(dir string, contents []string, t *testing.T) {
|
||||||
file, err := Open(dir)
|
file, err := Open(dir)
|
||||||
defer file.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("open %q failed: %v", dir, err)
|
t.Fatalf("open %q failed: %v", dir, err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
s, err2 := file.Readdirnames(-1)
|
s, err2 := file.Readdirnames(-1)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
t.Fatalf("readdirnames %q failed: %v", dir, err2)
|
t.Fatalf("readdirnames %q failed: %v", dir, err2)
|
||||||
@ -218,10 +218,10 @@ func testReaddirnames(dir string, contents []string, t *testing.T) {
|
|||||||
|
|
||||||
func testReaddir(dir string, contents []string, t *testing.T) {
|
func testReaddir(dir string, contents []string, t *testing.T) {
|
||||||
file, err := Open(dir)
|
file, err := Open(dir)
|
||||||
defer file.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("open %q failed: %v", dir, err)
|
t.Fatalf("open %q failed: %v", dir, err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
s, err2 := file.Readdir(-1)
|
s, err2 := file.Readdir(-1)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
t.Fatalf("readdir %q failed: %v", dir, err2)
|
t.Fatalf("readdir %q failed: %v", dir, err2)
|
||||||
@ -285,10 +285,10 @@ func TestReaddirnamesOneAtATime(t *testing.T) {
|
|||||||
dir = "/bin"
|
dir = "/bin"
|
||||||
}
|
}
|
||||||
file, err := Open(dir)
|
file, err := Open(dir)
|
||||||
defer file.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("open %q failed: %v", dir, err)
|
t.Fatalf("open %q failed: %v", dir, err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
all, err1 := file.Readdirnames(-1)
|
all, err1 := file.Readdirnames(-1)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
t.Fatalf("readdirnames %q failed: %v", dir, err1)
|
t.Fatalf("readdirnames %q failed: %v", dir, err1)
|
||||||
|
Loading…
Reference in New Issue
Block a user