]> Cypherpunks repositories - gostls13.git/commitdiff
net, os, file/filepath, syscall: use slices.Equal in tests
authorTobias Klauser <tklauser@distanz.ch>
Fri, 25 Jul 2025 11:02:01 +0000 (13:02 +0200)
committerGopher Robot <gobot@golang.org>
Mon, 11 Aug 2025 15:13:16 +0000 (08:13 -0700)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/net/net_windows_test.go
src/os/os_windows_test.go
src/path/filepath/match_test.go
src/syscall/dirent_test.go
src/syscall/getdirentries_test.go

index 671de7678008ed9b3e87eac1d950ce4d624ee94e..0a5c77f032527ef3d411fa629119840f61d53412 100644 (file)
@@ -302,7 +302,7 @@ func TestInterfacesWithNetsh(t *testing.T) {
        }
        slices.Sort(want)
 
-       if strings.Join(want, "/") != strings.Join(have, "/") {
+       if !slices.Equal(want, have) {
                t.Fatalf("unexpected interface list %q, want %q", have, want)
        }
 }
@@ -487,7 +487,7 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) {
                want = append(want, wantIPv6...)
                slices.Sort(want)
 
-               if strings.Join(want, "/") != strings.Join(have, "/") {
+               if !slices.Equal(want, have) {
                        t.Errorf("%s: unexpected addresses list %q, want %q", ifi.Name, have, want)
                }
        }
index 515d1c135901e0114119d3563fe2a08035340d26..5a479051ee1e3037defd14505ab257790b8ed99c 100644 (file)
@@ -663,7 +663,7 @@ func TestOpenVolumeName(t *testing.T) {
        }
        slices.Sort(have)
 
-       if strings.Join(want, "/") != strings.Join(have, "/") {
+       if !slices.Equal(want, have) {
                t.Fatalf("unexpected file list %q, want %q", have, want)
        }
 }
index f415b0408820af75a8b85643a0426771edc201fc..2ae79980c753ee4891676274a541d8dd2a7ce5fe 100644 (file)
@@ -231,7 +231,7 @@ func (test *globTest) globAbs(root, rootPattern string) error {
        }
        slices.Sort(have)
        want := test.buildWant(root + `\`)
-       if strings.Join(want, "_") == strings.Join(have, "_") {
+       if slices.Equal(want, have) {
                return nil
        }
        return fmt.Errorf("Glob(%q) returns %q, but %q expected", p, have, want)
@@ -245,12 +245,12 @@ func (test *globTest) globRel(root string) error {
        }
        slices.Sort(have)
        want := test.buildWant(root)
-       if strings.Join(want, "_") == strings.Join(have, "_") {
+       if slices.Equal(want, have) {
                return nil
        }
        // try also matching version without root prefix
        wantWithNoRoot := test.buildWant("")
-       if strings.Join(wantWithNoRoot, "_") == strings.Join(have, "_") {
+       if slices.Equal(wantWithNoRoot, have) {
                return nil
        }
        return fmt.Errorf("Glob(%q) returns %q, but %q expected", p, have, want)
index cfa5478feb1bc8b7364620ed07bc79b124470138..173ccc3ed28ef3d7f129901371f7aad7087075d0 100644 (file)
@@ -140,7 +140,7 @@ func TestDirentRepeat(t *testing.T) {
        // Check results
        slices.Sort(files)
        slices.Sort(files2)
-       if strings.Join(files, "|") != strings.Join(files2, "|") {
+       if !slices.Equal(files, files2) {
                t.Errorf("bad file list: want\n%q\ngot\n%q", files, files2)
        }
 }
index 5d401d8dd6fa2c15dee97fa8bdfafc4ff8621bb5..b5361ddaef702473905abb57d93368af41265138 100644 (file)
@@ -11,7 +11,6 @@ import (
        "os"
        "path/filepath"
        "slices"
-       "strings"
        "syscall"
        "testing"
        "unsafe"
@@ -78,7 +77,7 @@ func testGetdirentries(t *testing.T, count int) {
        names = append(names, ".", "..") // Getdirentries returns these also
        slices.Sort(names)
        slices.Sort(names2)
-       if strings.Join(names, ":") != strings.Join(names2, ":") {
+       if !slices.Equal(names, names2) {
                t.Errorf("names don't match\n names: %q\nnames2: %q", names, names2)
        }
 }