Skip to content

Commit a243177

Browse files
tklausergopherbot
authored andcommitted
net, os, file/filepath, syscall: use slices.Equal in tests
Use slices.Equal to compare slices instead of strings.Join and then comparing strings. Change-Id: Ib916002b7357bd7f4e66b853dd7af8d98eba5549 Reviewed-on: https://go-review.googlesource.com/c/go/+/690475 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent a7f05b3 commit a243177

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

src/net/net_windows_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func TestInterfacesWithNetsh(t *testing.T) {
302302
}
303303
slices.Sort(want)
304304

305-
if strings.Join(want, "/") != strings.Join(have, "/") {
305+
if !slices.Equal(want, have) {
306306
t.Fatalf("unexpected interface list %q, want %q", have, want)
307307
}
308308
}
@@ -487,7 +487,7 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) {
487487
want = append(want, wantIPv6...)
488488
slices.Sort(want)
489489

490-
if strings.Join(want, "/") != strings.Join(have, "/") {
490+
if !slices.Equal(want, have) {
491491
t.Errorf("%s: unexpected addresses list %q, want %q", ifi.Name, have, want)
492492
}
493493
}

src/os/os_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ func TestOpenVolumeName(t *testing.T) {
663663
}
664664
slices.Sort(have)
665665

666-
if strings.Join(want, "/") != strings.Join(have, "/") {
666+
if !slices.Equal(want, have) {
667667
t.Fatalf("unexpected file list %q, want %q", have, want)
668668
}
669669
}

src/path/filepath/match_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (test *globTest) globAbs(root, rootPattern string) error {
231231
}
232232
slices.Sort(have)
233233
want := test.buildWant(root + `\`)
234-
if strings.Join(want, "_") == strings.Join(have, "_") {
234+
if slices.Equal(want, have) {
235235
return nil
236236
}
237237
return fmt.Errorf("Glob(%q) returns %q, but %q expected", p, have, want)
@@ -245,12 +245,12 @@ func (test *globTest) globRel(root string) error {
245245
}
246246
slices.Sort(have)
247247
want := test.buildWant(root)
248-
if strings.Join(want, "_") == strings.Join(have, "_") {
248+
if slices.Equal(want, have) {
249249
return nil
250250
}
251251
// try also matching version without root prefix
252252
wantWithNoRoot := test.buildWant("")
253-
if strings.Join(wantWithNoRoot, "_") == strings.Join(have, "_") {
253+
if slices.Equal(wantWithNoRoot, have) {
254254
return nil
255255
}
256256
return fmt.Errorf("Glob(%q) returns %q, but %q expected", p, have, want)

src/syscall/dirent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestDirentRepeat(t *testing.T) {
140140
// Check results
141141
slices.Sort(files)
142142
slices.Sort(files2)
143-
if strings.Join(files, "|") != strings.Join(files2, "|") {
143+
if !slices.Equal(files, files2) {
144144
t.Errorf("bad file list: want\n%q\ngot\n%q", files, files2)
145145
}
146146
}

src/syscall/getdirentries_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"path/filepath"
1313
"slices"
14-
"strings"
1514
"syscall"
1615
"testing"
1716
"unsafe"
@@ -78,7 +77,7 @@ func testGetdirentries(t *testing.T, count int) {
7877
names = append(names, ".", "..") // Getdirentries returns these also
7978
slices.Sort(names)
8079
slices.Sort(names2)
81-
if strings.Join(names, ":") != strings.Join(names2, ":") {
80+
if !slices.Equal(names, names2) {
8281
t.Errorf("names don't match\n names: %q\nnames2: %q", names, names2)
8382
}
8483
}

0 commit comments

Comments
 (0)