aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorapocelipes <seve3r@outlook.com>2024-07-24 10:47:14 +0000
committerGopher Robot <gobot@golang.org>2024-07-25 00:23:06 +0000
commit05861ff90cfc855620d0dcbd1d6cc488ebf04880 (patch)
tree72b56bbb48da1f66041fd9df85423740bb3f5120 /src/os
parent0b0dfcd5404ce86d6c818d78bdb6348ded459e96 (diff)
downloadgo-05861ff90cfc855620d0dcbd1d6cc488ebf04880.tar.xz
os,path/filepath,testing: use slices to clean up tests
Replace reflect.DeepEqual with slices.Equal which is much faster. Change-Id: I299db6f998738174983731f08c1021346b87dfaa GitHub-Last-Rev: 44ca9015d6af4e0fbe8d23c93b3f2da08a2d7728 GitHub-Pull-Request: golang/go#67613 Reviewed-on: https://go-review.googlesource.com/c/go/+/587938 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/env_test.go4
-rw-r--r--src/os/exec/env_test.go4
-rw-r--r--src/os/exec/exec_posix_test.go6
-rw-r--r--src/os/os_test.go5
-rw-r--r--src/os/os_windows_test.go3
5 files changed, 10 insertions, 12 deletions
diff --git a/src/os/env_test.go b/src/os/env_test.go
index 5809f4b866..e3de64196a 100644
--- a/src/os/env_test.go
+++ b/src/os/env_test.go
@@ -6,7 +6,7 @@ package os_test
import (
. "os"
- "reflect"
+ "slices"
"strings"
"testing"
)
@@ -91,7 +91,7 @@ func TestConsistentEnviron(t *testing.T) {
e0 := Environ()
for i := 0; i < 10; i++ {
e1 := Environ()
- if !reflect.DeepEqual(e0, e1) {
+ if !slices.Equal(e0, e1) {
t.Fatalf("environment changed")
}
}
diff --git a/src/os/exec/env_test.go b/src/os/exec/env_test.go
index ea06af3885..9fd022b2ee 100644
--- a/src/os/exec/env_test.go
+++ b/src/os/exec/env_test.go
@@ -5,7 +5,7 @@
package exec
import (
- "reflect"
+ "slices"
"testing"
)
@@ -60,7 +60,7 @@ func TestDedupEnv(t *testing.T) {
}
for _, tt := range tests {
got, err := dedupEnvCase(tt.noCase, tt.nulOK, tt.in)
- if !reflect.DeepEqual(got, tt.want) || (err != nil) != tt.wantErr {
+ if !slices.Equal(got, tt.want) || (err != nil) != tt.wantErr {
t.Errorf("Dedup(%v, %q) = %q, %v; want %q, error:%v", tt.noCase, tt.in, got, err, tt.want, tt.wantErr)
}
}
diff --git a/src/os/exec/exec_posix_test.go b/src/os/exec/exec_posix_test.go
index 5d828b3475..45604203dd 100644
--- a/src/os/exec/exec_posix_test.go
+++ b/src/os/exec/exec_posix_test.go
@@ -13,8 +13,8 @@ import (
"os"
"os/user"
"path/filepath"
- "reflect"
"runtime"
+ "slices"
"strconv"
"strings"
"syscall"
@@ -184,7 +184,7 @@ func TestImplicitPWD(t *testing.T) {
wantPWDs = nil
}
}
- if !reflect.DeepEqual(pwds, wantPWDs) {
+ if !slices.Equal(pwds, wantPWDs) {
t.Errorf("PWD entries in cmd.Environ():\n\t%s\nwant:\n\t%s", strings.Join(pwds, "\n\t"), strings.Join(wantPWDs, "\n\t"))
}
@@ -257,7 +257,7 @@ func TestExplicitPWD(t *testing.T) {
}
wantPWDs := []string{tc.pwd}
- if !reflect.DeepEqual(pwds, wantPWDs) {
+ if !slices.Equal(pwds, wantPWDs) {
t.Errorf("PWD entries in cmd.Environ():\n\t%s\nwant:\n\t%s", strings.Join(pwds, "\n\t"), strings.Join(wantPWDs, "\n\t"))
}
diff --git a/src/os/os_test.go b/src/os/os_test.go
index 5a36abd7c6..46c4f138c3 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -16,7 +16,6 @@ import (
. "os"
"os/exec"
"path/filepath"
- "reflect"
"runtime"
"runtime/debug"
"slices"
@@ -805,13 +804,13 @@ func TestReaddirStatFailures(t *testing.T) {
}
if got, want := names(mustReadDir("initial readdir")),
- []string{"good1", "good2", "x"}; !reflect.DeepEqual(got, want) {
+ []string{"good1", "good2", "x"}; !slices.Equal(got, want) {
t.Errorf("initial readdir got %q; want %q", got, want)
}
xerr = ErrNotExist
if got, want := names(mustReadDir("with x disappearing")),
- []string{"good1", "good2"}; !reflect.DeepEqual(got, want) {
+ []string{"good1", "good2"}; !slices.Equal(got, want) {
t.Errorf("with x disappearing, got %q; want %q", got, want)
}
diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go
index caff011122..4a8d0d07ef 100644
--- a/src/os/os_windows_test.go
+++ b/src/os/os_windows_test.go
@@ -17,7 +17,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "reflect"
"runtime"
"slices"
"strings"
@@ -778,7 +777,7 @@ func TestReadStdin(t *testing.T) {
for len(want) < 5 {
want = append(want, "")
}
- if !reflect.DeepEqual(all, want) {
+ if !slices.Equal(all, want) {
t.Errorf("reading %q:\nhave %x\nwant %x", s, all, want)
}
})