diff options
author | Heschi Kreinick <heschi@google.com> | 2022-12-07 10:36:28 -0500 |
---|---|---|
committer | Heschi Kreinick <heschi@google.com> | 2022-12-07 10:36:28 -0500 |
commit | fc1ed37e824b2f87e287e1bc4597253f1b30b3b3 (patch) | |
tree | b9bd79860c787dfadd6f58927ac9bc492801ab5d /src/os/os_test.go | |
parent | f241e009541082fb1bc5cc5a207ded510cac3d19 (diff) | |
parent | 0d8a92bdfd3d6d1b24f47e05f9be46645aec94f0 (diff) | |
download | go-fc1ed37e824b2f87e287e1bc4597253f1b30b3b3.tar.gz go-fc1ed37e824b2f87e287e1bc4597253f1b30b3b3.zip |
[dev.boringcrypto.go1.18] all: merge go1.18.9 into dev.boringcrypto.go1.18
Change-Id: I5eda3a3fb2fc381e237d18d2846cf1b1810d8015
Diffstat (limited to 'src/os/os_test.go')
-rw-r--r-- | src/os/os_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go index 63427deb6e..4124be13cc 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -2696,6 +2696,44 @@ func TestDirFS(t *testing.T) { if err == nil { t.Fatalf(`Open testdata\dirfs succeeded`) } + + // Test that Open does not open Windows device files. + _, err = d.Open(`NUL`) + if err == nil { + t.Errorf(`Open NUL succeeded`) + } +} + +func TestDirFSRootDir(t *testing.T) { + cwd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + cwd = cwd[len(filepath.VolumeName(cwd)):] // trim volume prefix (C:) on Windows + cwd = filepath.ToSlash(cwd) // convert \ to / + cwd = strings.TrimPrefix(cwd, "/") // trim leading / + + // Test that Open can open a path starting at /. + d := DirFS("/") + f, err := d.Open(cwd + "/testdata/dirfs/a") + if err != nil { + t.Fatal(err) + } + f.Close() +} + +func TestDirFSEmptyDir(t *testing.T) { + d := DirFS("") + cwd, _ := os.Getwd() + for _, path := range []string{ + "testdata/dirfs/a", // not DirFS(".") + filepath.ToSlash(cwd) + "/testdata/dirfs/a", // not DirFS("/") + } { + _, err := d.Open(path) + if err == nil { + t.Fatalf(`DirFS("").Open(%q) succeeded`, path) + } + } } func TestDirFSPathsValid(t *testing.T) { |