diff options
| author | apocelipes <seve3r@outlook.com> | 2024-07-24 10:39:58 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-07-25 00:22:14 +0000 |
| commit | 2247afc0aee41434a4e874af07d026f828bd3210 (patch) | |
| tree | 939cfa7ec182e2c0fb80c1125841ee54c50e48a9 /src/internal | |
| parent | 1d717951f518a9e818e8b98d4daed17756c394ca (diff) | |
| download | go-2247afc0aee41434a4e874af07d026f828bd3210.tar.xz | |
go,internal,io,mime: use slices and maps to clean tests
Replace reflect.DeepEqual with slices.Equal/maps.Equal, which is
much faster.
Change-Id: Id9cb550884da817da96befdeccfecb3325fb4414
GitHub-Last-Rev: 7d64d78feb86e3ea1af6c24ea6782cb85731bb52
GitHub-Pull-Request: golang/go#67612
Reviewed-on: https://go-review.googlesource.com/c/go/+/587819
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/internal')
| -rw-r--r-- | src/internal/dag/alg_test.go | 4 | ||||
| -rw-r--r-- | src/internal/dag/parse_test.go | 4 | ||||
| -rw-r--r-- | src/internal/godebug/godebug_test.go | 3 | ||||
| -rw-r--r-- | src/internal/profile/proto_test.go | 8 | ||||
| -rw-r--r-- | src/internal/xcoff/file_test.go | 3 |
5 files changed, 11 insertions, 11 deletions
diff --git a/src/internal/dag/alg_test.go b/src/internal/dag/alg_test.go index e5ea8b6ab6..0659eb18e3 100644 --- a/src/internal/dag/alg_test.go +++ b/src/internal/dag/alg_test.go @@ -5,7 +5,7 @@ package dag import ( - "reflect" + "slices" "strings" "testing" ) @@ -26,7 +26,7 @@ func TestTopo(t *testing.T) { // // "a" is a leaf. wantNodes := strings.Fields("d c b a") - if !reflect.DeepEqual(wantNodes, got) { + if !slices.Equal(wantNodes, got) { t.Fatalf("want topo sort %v, got %v", wantNodes, got) } } diff --git a/src/internal/dag/parse_test.go b/src/internal/dag/parse_test.go index b2520c3659..dda304ad3e 100644 --- a/src/internal/dag/parse_test.go +++ b/src/internal/dag/parse_test.go @@ -5,7 +5,7 @@ package dag import ( - "reflect" + "slices" "strings" "testing" ) @@ -52,7 +52,7 @@ func TestParse(t *testing.T) { g := mustParse(t, diamond) wantNodes := strings.Fields("a b c d") - if !reflect.DeepEqual(wantNodes, g.Nodes) { + if !slices.Equal(wantNodes, g.Nodes) { t.Fatalf("want nodes %v, got %v", wantNodes, g.Nodes) } diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go index 5d426fd52e..6929630356 100644 --- a/src/internal/godebug/godebug_test.go +++ b/src/internal/godebug/godebug_test.go @@ -11,7 +11,6 @@ import ( "internal/testenv" "os" "os/exec" - "reflect" "runtime/metrics" "slices" "strings" @@ -125,7 +124,7 @@ func TestCmdBisect(t *testing.T) { } slices.Sort(have) - if !reflect.DeepEqual(have, want) { + if !slices.Equal(have, want) { t.Errorf("bad bisect output:\nhave %v\nwant %v\ncomplete output:\n%s", have, want, string(out)) } } diff --git a/src/internal/profile/proto_test.go b/src/internal/profile/proto_test.go index 46c6d83063..4c09f7c47e 100644 --- a/src/internal/profile/proto_test.go +++ b/src/internal/profile/proto_test.go @@ -5,7 +5,7 @@ package profile import ( - "reflect" + "slices" "testing" ) @@ -34,7 +34,7 @@ func TestPackedEncoding(t *testing.T) { }, } { source := &packedInts{tc.uint64s, tc.int64s} - if got, want := marshal(source), tc.encoded; !reflect.DeepEqual(got, want) { + if got, want := marshal(source), tc.encoded; !slices.Equal(got, want) { t.Errorf("failed encode %d, got %v, want %v", i, got, want) } @@ -43,10 +43,10 @@ func TestPackedEncoding(t *testing.T) { t.Errorf("failed decode %d: %v", i, err) continue } - if got, want := dest.uint64s, tc.uint64s; !reflect.DeepEqual(got, want) { + if got, want := dest.uint64s, tc.uint64s; !slices.Equal(got, want) { t.Errorf("failed decode uint64s %d, got %v, want %v", i, got, want) } - if got, want := dest.int64s, tc.int64s; !reflect.DeepEqual(got, want) { + if got, want := dest.int64s, tc.int64s; !slices.Equal(got, want) { t.Errorf("failed decode int64s %d, got %v, want %v", i, got, want) } } diff --git a/src/internal/xcoff/file_test.go b/src/internal/xcoff/file_test.go index a6722e9453..d1f10d6bf1 100644 --- a/src/internal/xcoff/file_test.go +++ b/src/internal/xcoff/file_test.go @@ -6,6 +6,7 @@ package xcoff import ( "reflect" + "slices" "testing" ) @@ -87,7 +88,7 @@ func TestOpen(t *testing.T) { if err != nil { t.Error(err) } - if !reflect.DeepEqual(tl, fl) { + if !slices.Equal(tl, fl) { t.Errorf("open %s: loader import = %v, want %v", tt.file, tl, fl) } } |
