Skip to content

Commit c06c3ce

Browse files
committed
Simplify error checking
1 parent 1910d66 commit c06c3ce

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/net/url/url_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,51 +2068,43 @@ func TestJoinPath(t *testing.T) {
20682068
base string
20692069
elem []string
20702070
out string
2071-
err bool
20722071
}{
20732072
{
20742073
base: "https://go.googlesource.com",
20752074
elem: []string{"go"},
20762075
out: "https://go.googlesource.com/go",
2077-
err: false,
20782076
},
20792077
{
20802078
base: "https://go.googlesource.com/a/b/c",
20812079
elem: []string{"../../../go"},
20822080
out: "https://go.googlesource.com/go",
2083-
err: false,
20842081
},
20852082
{
20862083
base: "https://go.googlesource.com/",
20872084
elem: []string{"./go"},
20882085
out: "https://go.googlesource.com/go",
2089-
err: false,
20902086
},
20912087
{
20922088
base: "https://go.googlesource.com//",
20932089
elem: []string{"/go"},
20942090
out: "https://go.googlesource.com/go",
2095-
err: false,
20962091
},
20972092
{
20982093
base: "https://go.googlesource.com//",
20992094
elem: []string{"/go", "a", "b", "c"},
21002095
out: "https://go.googlesource.com/go/a/b/c",
2101-
err: false,
21022096
},
21032097
{
21042098
base: "http://[fe80::1%en0]:8080/",
21052099
elem: []string{"/go"},
2106-
out: "",
2107-
err: true,
21082100
},
21092101
}
21102102
for _, tt := range tests {
2111-
if out, err := JoinPath(tt.base, tt.elem...); out != tt.out || (err != nil) != tt.err {
2112-
wantErr := "nil"
2113-
if tt.err {
2114-
wantErr = "non-nil error"
2115-
}
2103+
wantErr := "nil"
2104+
if tt.out == "" {
2105+
wantErr = "non-nil error"
2106+
}
2107+
if out, err := JoinPath(tt.base, tt.elem...); out != tt.out || (err == nil) != (tt.out != "") {
21162108
t.Errorf("JoinPath(%q, %q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr)
21172109
}
21182110
var out string
@@ -2121,11 +2113,7 @@ func TestJoinPath(t *testing.T) {
21212113
u = u.JoinPath(tt.elem...)
21222114
out = u.String()
21232115
}
2124-
if out != tt.out || (err != nil) != tt.err {
2125-
wantErr := "nil"
2126-
if tt.err {
2127-
wantErr = "non-nil error"
2128-
}
2116+
if out != tt.out || (err == nil) != (tt.out != "") {
21292117
t.Errorf("Parse(%q).JoinPath(%q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr)
21302118
}
21312119
}

0 commit comments

Comments
 (0)