mirror of https://github.com/golang/go.git
Simplify error checking
This commit is contained in:
parent
82304b6882
commit
4cd3ab195b
|
|
@ -2068,51 +2068,43 @@ func TestJoinPath(t *testing.T) {
|
|||
base string
|
||||
elem []string
|
||||
out string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
base: "https://go.googlesource.com",
|
||||
elem: []string{"go"},
|
||||
out: "https://go.googlesource.com/go",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
base: "https://go.googlesource.com/a/b/c",
|
||||
elem: []string{"../../../go"},
|
||||
out: "https://go.googlesource.com/go",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
base: "https://go.googlesource.com/",
|
||||
elem: []string{"./go"},
|
||||
out: "https://go.googlesource.com/go",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
base: "https://go.googlesource.com//",
|
||||
elem: []string{"/go"},
|
||||
out: "https://go.googlesource.com/go",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
base: "https://go.googlesource.com//",
|
||||
elem: []string{"/go", "a", "b", "c"},
|
||||
out: "https://go.googlesource.com/go/a/b/c",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
base: "http://[fe80::1%en0]:8080/",
|
||||
elem: []string{"/go"},
|
||||
out: "",
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if out, err := JoinPath(tt.base, tt.elem...); out != tt.out || (err != nil) != tt.err {
|
||||
wantErr := "nil"
|
||||
if tt.err {
|
||||
wantErr = "non-nil error"
|
||||
}
|
||||
wantErr := "nil"
|
||||
if tt.out == "" {
|
||||
wantErr = "non-nil error"
|
||||
}
|
||||
if out, err := JoinPath(tt.base, tt.elem...); out != tt.out || (err == nil) != (tt.out != "") {
|
||||
t.Errorf("JoinPath(%q, %q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr)
|
||||
}
|
||||
var out string
|
||||
|
|
@ -2121,11 +2113,7 @@ func TestJoinPath(t *testing.T) {
|
|||
u = u.JoinPath(tt.elem...)
|
||||
out = u.String()
|
||||
}
|
||||
if out != tt.out || (err != nil) != tt.err {
|
||||
wantErr := "nil"
|
||||
if tt.err {
|
||||
wantErr = "non-nil error"
|
||||
}
|
||||
if out != tt.out || (err == nil) != (tt.out != "") {
|
||||
t.Errorf("Parse(%q).JoinPath(%q) = %q, %v, want %q, %v", tt.base, tt.elem, out, err, tt.out, wantErr)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue