]> Cypherpunks repositories - gostls13.git/commitdiff
os: define TestIssue60181 only on Unix platforms
authorBryan C. Mills <bcmills@google.com>
Thu, 10 Aug 2023 14:39:58 +0000 (10:39 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 10 Aug 2023 15:36:04 +0000 (15:36 +0000)
In CL 517755 the test was added in the unconstrained os_test.go
because it appeared to be portable, but it turned out not to be
valid on plan9.

(The build error was masked on the misc-compile TryBots by #61923.)

Although the test can also compile and run on Windows, the bug it
checks for is specific to Linux and only really needs to run there, so
I am moving it to os_unix_test.go instead of adding yet another test
file for “Unix and Windows but not Plan 9”.

Updates #60181.

Change-Id: I41fd11b288217e95652b5daa72460c0d26bde606
Reviewed-on: https://go-review.googlesource.com/c/go/+/518255
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/os/os_test.go
src/os/os_unix_test.go

index 28256ee213ec4804b53e2e8d3e6bca46a3031db3..94c3ad04f352ac7a6bda338dd41f3f4181df8750 100644 (file)
@@ -3270,59 +3270,3 @@ func TestPipeCloseRace(t *testing.T) {
                t.Errorf("got nils %d errs %d, want 2 2", nils, errs)
        }
 }
-
-// Test that copying to files opened with O_APPEND works and
-// the copy_file_range syscall isn't used on Linux.
-//
-// Regression test for go.dev/issue/60181
-func TestIssue60181(t *testing.T) {
-       defer chtmpdir(t)()
-
-       want := "hello gopher"
-
-       a, err := CreateTemp("", "a")
-       if err != nil {
-               t.Fatal(err)
-       }
-       a.WriteString(want[:5])
-       a.Close()
-
-       b, err := CreateTemp("", "b")
-       if err != nil {
-               t.Fatal(err)
-       }
-       b.WriteString(want[5:])
-       b.Close()
-
-       afd, err := syscall.Open(a.Name(), syscall.O_RDWR|syscall.O_APPEND, 0)
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       bfd, err := syscall.Open(b.Name(), syscall.O_RDONLY, 0)
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       aa := NewFile(uintptr(afd), a.Name())
-       defer aa.Close()
-       bb := NewFile(uintptr(bfd), b.Name())
-       defer bb.Close()
-
-       // This would fail on Linux in case the copy_file_range syscall was used because it doesn't
-       // support destination files opened with O_APPEND, see
-       // https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS
-       _, err = io.Copy(aa, bb)
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       buf, err := ReadFile(aa.Name())
-       if err != nil {
-               t.Fatal(err)
-       }
-
-       if got := string(buf); got != want {
-               t.Errorf("files not concatenated: got %q, want %q", got, want)
-       }
-}
index 98e7afd0f6ba0a8b55c73a092d4cf6cf6ce0cfb3..9041b25471020c555540a41845dd58cbaa432be7 100644 (file)
@@ -346,3 +346,59 @@ func TestSplitPath(t *testing.T) {
                }
        }
 }
+
+// Test that copying to files opened with O_APPEND works and
+// the copy_file_range syscall isn't used on Linux.
+//
+// Regression test for go.dev/issue/60181
+func TestIssue60181(t *testing.T) {
+       defer chtmpdir(t)()
+
+       want := "hello gopher"
+
+       a, err := CreateTemp("", "a")
+       if err != nil {
+               t.Fatal(err)
+       }
+       a.WriteString(want[:5])
+       a.Close()
+
+       b, err := CreateTemp("", "b")
+       if err != nil {
+               t.Fatal(err)
+       }
+       b.WriteString(want[5:])
+       b.Close()
+
+       afd, err := syscall.Open(a.Name(), syscall.O_RDWR|syscall.O_APPEND, 0)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       bfd, err := syscall.Open(b.Name(), syscall.O_RDONLY, 0)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       aa := NewFile(uintptr(afd), a.Name())
+       defer aa.Close()
+       bb := NewFile(uintptr(bfd), b.Name())
+       defer bb.Close()
+
+       // This would fail on Linux in case the copy_file_range syscall was used because it doesn't
+       // support destination files opened with O_APPEND, see
+       // https://man7.org/linux/man-pages/man2/copy_file_range.2.html#ERRORS
+       _, err = io.Copy(aa, bb)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       buf, err := ReadFile(aa.Name())
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       if got := string(buf); got != want {
+               t.Errorf("files not concatenated: got %q, want %q", got, want)
+       }
+}