Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(348)

Side by Side Diff: src/pkg/os/path_test.go

Issue 2343043: code review 2343043: os: make tests work on windows (Closed)
Patch Set: code review 2343043: os: make tests work on windows Created 14 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package os_test 5 package os_test
6 6
7 import ( 7 import (
8 . "os" 8 . "os"
9 "testing" 9 "testing"
10 "syscall"
10 ) 11 )
11 12
12 func TestMkdirAll(t *testing.T) { 13 func TestMkdirAll(t *testing.T) {
13 // Create new dir, in _obj so it will get 14 // Create new dir, in _obj so it will get
14 // cleaned up by make if not by us. 15 // cleaned up by make if not by us.
15 path := "_obj/_TestMkdirAll_/dir/./dir2" 16 path := "_obj/_TestMkdirAll_/dir/./dir2"
16 err := MkdirAll(path, 0777) 17 err := MkdirAll(path, 0777)
17 if err != nil { 18 if err != nil {
18 t.Fatalf("MkdirAll %q: %s", path, err) 19 t.Fatalf("MkdirAll %q: %s", path, err)
19 } 20 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 t.Fatalf("create %q: %s", fpath, err) 98 t.Fatalf("create %q: %s", fpath, err)
98 } 99 }
99 fd.Close() 100 fd.Close()
100 if err = RemoveAll(path); err != nil { 101 if err = RemoveAll(path); err != nil {
101 t.Fatalf("RemoveAll %q (second): %s", path, err) 102 t.Fatalf("RemoveAll %q (second): %s", path, err)
102 } 103 }
103 if _, err := Lstat(path); err == nil { 104 if _, err := Lstat(path); err == nil {
104 t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path) 105 t.Fatalf("Lstat %q succeeded after RemoveAll (second)", path)
105 } 106 }
106 107
107 » if Getuid() != 0 { // Test fails as root 108 » // Determine, if we should run the following test.
r 2010/10/04 05:48:00 s/,//
brainman 2010/10/04 06:16:07 Done.
109 » testit := true
110 » if syscall.OS == "windows" {
r 2010/10/04 05:48:00 you could fold these test together but if you want
brainman 2010/10/04 06:16:07 I will keep them separate, because I want both com
111 » » // Chmod is not supported under windows.
112 » » testit = false
113 » } else {
114 » » // Test fails as root.
115 » » testit = Getuid() != 0
116 » }
117 » if testit {
108 // Make directory with file and subdirectory and trigger error. 118 // Make directory with file and subdirectory and trigger error.
109 if err = MkdirAll(dpath, 0777); err != nil { 119 if err = MkdirAll(dpath, 0777); err != nil {
110 t.Fatalf("MkdirAll %q: %s", dpath, err) 120 t.Fatalf("MkdirAll %q: %s", dpath, err)
111 } 121 }
112 122
113 for _, s := range []string{fpath, dpath + "/file1", path + "/zzz "} { 123 for _, s := range []string{fpath, dpath + "/file1", path + "/zzz "} {
114 fd, err = Open(s, O_WRONLY|O_CREAT, 0666) 124 fd, err = Open(s, O_WRONLY|O_CREAT, 0666)
115 if err != nil { 125 if err != nil {
116 t.Fatalf("create %q: %s", s, err) 126 t.Fatalf("create %q: %s", s, err)
117 } 127 }
(...skipping 25 matching lines...) Expand all
143 } 153 }
144 } 154 }
145 } 155 }
146 if err = RemoveAll(path); err != nil { 156 if err = RemoveAll(path); err != nil {
147 t.Fatalf("RemoveAll %q after partial RemoveAll: %s", path, err) 157 t.Fatalf("RemoveAll %q after partial RemoveAll: %s", path, err)
148 } 158 }
149 if _, err := Lstat(path); err == nil { 159 if _, err := Lstat(path); err == nil {
150 t.Fatalf("Lstat %q succeeded after RemoveAll (final)", path) 160 t.Fatalf("Lstat %q succeeded after RemoveAll (final)", path)
151 } 161 }
152 } 162 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b