libstdc++: Qualify calls in <bits/stl_uninitialized.h> to prevent ADL
[official-gcc.git] / libgo / go / os / path_test.go
blob59f72834859e2f10d5a4e31c5351d72760d78a36
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package os_test
7 import (
8 "internal/testenv"
9 . "os"
10 "path/filepath"
11 "runtime"
12 "syscall"
13 "testing"
16 var isReadonlyError = func(error) bool { return false }
18 func TestMkdirAll(t *testing.T) {
19 tmpDir := TempDir()
20 path := tmpDir + "/_TestMkdirAll_/dir/./dir2"
21 err := MkdirAll(path, 0777)
22 if err != nil {
23 t.Fatalf("MkdirAll %q: %s", path, err)
25 defer RemoveAll(tmpDir + "/_TestMkdirAll_")
27 // Already exists, should succeed.
28 err = MkdirAll(path, 0777)
29 if err != nil {
30 t.Fatalf("MkdirAll %q (second time): %s", path, err)
33 // Make file.
34 fpath := path + "/file"
35 f, err := Create(fpath)
36 if err != nil {
37 t.Fatalf("create %q: %s", fpath, err)
39 defer f.Close()
41 // Can't make directory named after file.
42 err = MkdirAll(fpath, 0777)
43 if err == nil {
44 t.Fatalf("MkdirAll %q: no error", fpath)
46 perr, ok := err.(*PathError)
47 if !ok {
48 t.Fatalf("MkdirAll %q returned %T, not *PathError", fpath, err)
50 if filepath.Clean(perr.Path) != filepath.Clean(fpath) {
51 t.Fatalf("MkdirAll %q returned wrong error path: %q not %q", fpath, filepath.Clean(perr.Path), filepath.Clean(fpath))
54 // Can't make subdirectory of file.
55 ffpath := fpath + "/subdir"
56 err = MkdirAll(ffpath, 0777)
57 if err == nil {
58 t.Fatalf("MkdirAll %q: no error", ffpath)
60 perr, ok = err.(*PathError)
61 if !ok {
62 t.Fatalf("MkdirAll %q returned %T, not *PathError", ffpath, err)
64 if filepath.Clean(perr.Path) != filepath.Clean(fpath) {
65 t.Fatalf("MkdirAll %q returned wrong error path: %q not %q", ffpath, filepath.Clean(perr.Path), filepath.Clean(fpath))
68 if runtime.GOOS == "windows" {
69 path := tmpDir + `\_TestMkdirAll_\dir\.\dir2\`
70 err := MkdirAll(path, 0777)
71 if err != nil {
72 t.Fatalf("MkdirAll %q: %s", path, err)
77 func TestMkdirAllWithSymlink(t *testing.T) {
78 testenv.MustHaveSymlink(t)
80 tmpDir := t.TempDir()
81 dir := tmpDir + "/dir"
82 if err := Mkdir(dir, 0755); err != nil {
83 t.Fatalf("Mkdir %s: %s", dir, err)
86 link := tmpDir + "/link"
87 if err := Symlink("dir", link); err != nil {
88 t.Fatalf("Symlink %s: %s", link, err)
91 path := link + "/foo"
92 if err := MkdirAll(path, 0755); err != nil {
93 t.Errorf("MkdirAll %q: %s", path, err)
97 func TestMkdirAllAtSlash(t *testing.T) {
98 switch runtime.GOOS {
99 case "android", "ios", "plan9", "windows":
100 t.Skipf("skipping on %s", runtime.GOOS)
102 RemoveAll("/_go_os_test")
103 const dir = "/_go_os_test/dir"
104 err := MkdirAll(dir, 0777)
105 if err != nil {
106 pathErr, ok := err.(*PathError)
107 // common for users not to be able to write to /
108 if ok && (pathErr.Err == syscall.EACCES || isReadonlyError(pathErr.Err)) {
109 t.Skipf("could not create %v: %v", dir, err)
111 t.Fatalf(`MkdirAll "/_go_os_test/dir": %v, %s`, err, pathErr.Err)
113 RemoveAll("/_go_os_test")