From 5cc418e6255f6fa530e5a43e3b4d96759e604571 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Wed, 8 Nov 2023 19:38:00 +0800 Subject: [PATCH] os: avoid TestFileChdir fail when GOROOT is a symbolic link If GOROOT is a symbolic link, the paths obtained from the first and second Getwd of TestFileChdir are different, and this CL fixes the test failure in this situation. --- src/os/os_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/os/os_test.go b/src/os/os_test.go index ae12b9ce1be..7e0e0b90be0 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -1620,8 +1620,17 @@ func TestFileChdir(t *testing.T) { if err != nil { t.Fatalf("Getwd: %s", err) } - if !equal(wdNew, wd) { - t.Fatalf("fd.Chdir failed, got %s, want %s", wdNew, wd) + + wdInfo, err := fd.Stat() + if err != nil { + t.Fatal(err) + } + newInfo, err := Stat(wdNew) + if err != nil { + t.Fatal(err) + } + if !SameFile(wdInfo, newInfo) { + t.Fatalf("fd.Chdir failed: got %s, want %s", wdNew, wd) } }