OSDN Git Service

libgo: Update to weekly.2011-11-02.
[pf3gnuchains/gcc-fork.git] / libgo / go / path / filepath / path_test.go
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.
4
5 package filepath_test
6
7 import (
8         "os"
9         "path/filepath"
10         "reflect"
11         "runtime"
12         "testing"
13 )
14
15 type PathTest struct {
16         path, result string
17 }
18
19 var cleantests = []PathTest{
20         // Already clean
21         {"", "."},
22         {"abc", "abc"},
23         {"abc/def", "abc/def"},
24         {"a/b/c", "a/b/c"},
25         {".", "."},
26         {"..", ".."},
27         {"../..", "../.."},
28         {"../../abc", "../../abc"},
29         {"/abc", "/abc"},
30         {"/", "/"},
31
32         // Remove trailing slash
33         {"abc/", "abc"},
34         {"abc/def/", "abc/def"},
35         {"a/b/c/", "a/b/c"},
36         {"./", "."},
37         {"../", ".."},
38         {"../../", "../.."},
39         {"/abc/", "/abc"},
40
41         // Remove doubled slash
42         {"abc//def//ghi", "abc/def/ghi"},
43         {"//abc", "/abc"},
44         {"///abc", "/abc"},
45         {"//abc//", "/abc"},
46         {"abc//", "abc"},
47
48         // Remove . elements
49         {"abc/./def", "abc/def"},
50         {"/./abc/def", "/abc/def"},
51         {"abc/.", "abc"},
52
53         // Remove .. elements
54         {"abc/def/ghi/../jkl", "abc/def/jkl"},
55         {"abc/def/../ghi/../jkl", "abc/jkl"},
56         {"abc/def/..", "abc"},
57         {"abc/def/../..", "."},
58         {"/abc/def/../..", "/"},
59         {"abc/def/../../..", ".."},
60         {"/abc/def/../../..", "/"},
61         {"abc/def/../../../ghi/jkl/../../../mno", "../../mno"},
62
63         // Combinations
64         {"abc/./../def", "def"},
65         {"abc//./../def", "def"},
66         {"abc/../../././../def", "../../def"},
67 }
68
69 var wincleantests = []PathTest{
70         {`c:`, `c:.`},
71         {`c:\`, `c:\`},
72         {`c:\abc`, `c:\abc`},
73         {`c:abc\..\..\.\.\..\def`, `c:..\..\def`},
74         {`c:\abc\def\..\..`, `c:\`},
75         {`c:\..\abc`, `c:\abc`},
76         {`c:..\abc`, `c:..\abc`},
77         {`\`, `\`},
78         {`/`, `\`},
79         {`\\i\..\c$`, `\c$`},
80         {`\\i\..\i\c$`, `\i\c$`},
81         {`\\i\..\I\c$`, `\I\c$`},
82         {`\\host\share\foo\..\bar`, `\\host\share\bar`},
83         {`//host/share/foo/../baz`, `\\host\share\baz`},
84         {`\\a\b\..\c`, `\\a\b\c`},
85         {`\\a\b`, `\\a\b`},
86 }
87
88 func TestClean(t *testing.T) {
89         tests := cleantests
90         if runtime.GOOS == "windows" {
91                 for i := range tests {
92                         tests[i].result = filepath.FromSlash(tests[i].result)
93                 }
94                 tests = append(tests, wincleantests...)
95         }
96         for _, test := range tests {
97                 if s := filepath.Clean(test.path); s != test.result {
98                         t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
99                 }
100         }
101 }
102
103 const sep = filepath.Separator
104
105 var slashtests = []PathTest{
106         {"", ""},
107         {"/", string(sep)},
108         {"/a/b", string([]byte{sep, 'a', sep, 'b'})},
109         {"a//b", string([]byte{'a', sep, sep, 'b'})},
110 }
111
112 func TestFromAndToSlash(t *testing.T) {
113         for _, test := range slashtests {
114                 if s := filepath.FromSlash(test.path); s != test.result {
115                         t.Errorf("FromSlash(%q) = %q, want %q", test.path, s, test.result)
116                 }
117                 if s := filepath.ToSlash(test.result); s != test.path {
118                         t.Errorf("ToSlash(%q) = %q, want %q", test.result, s, test.path)
119                 }
120         }
121 }
122
123 type SplitListTest struct {
124         list   string
125         result []string
126 }
127
128 const lsep = filepath.ListSeparator
129
130 var splitlisttests = []SplitListTest{
131         {"", []string{}},
132         {string([]byte{'a', lsep, 'b'}), []string{"a", "b"}},
133         {string([]byte{lsep, 'a', lsep, 'b'}), []string{"", "a", "b"}},
134 }
135
136 func TestSplitList(t *testing.T) {
137         for _, test := range splitlisttests {
138                 if l := filepath.SplitList(test.list); !reflect.DeepEqual(l, test.result) {
139                         t.Errorf("SplitList(%q) = %s, want %s", test.list, l, test.result)
140                 }
141         }
142 }
143
144 type SplitTest struct {
145         path, dir, file string
146 }
147
148 var unixsplittests = []SplitTest{
149         {"a/b", "a/", "b"},
150         {"a/b/", "a/b/", ""},
151         {"a/", "a/", ""},
152         {"a", "", "a"},
153         {"/", "/", ""},
154 }
155
156 var winsplittests = []SplitTest{
157         {`c:`, `c:`, ``},
158         {`c:/`, `c:/`, ``},
159         {`c:/foo`, `c:/`, `foo`},
160         {`c:/foo/bar`, `c:/foo/`, `bar`},
161         {`//host/share`, `//host/share`, ``},
162         {`//host/share/`, `//host/share/`, ``},
163         {`//host/share/foo`, `//host/share/`, `foo`},
164         {`\\host\share`, `\\host\share`, ``},
165         {`\\host\share\`, `\\host\share\`, ``},
166         {`\\host\share\foo`, `\\host\share\`, `foo`},
167 }
168
169 func TestSplit(t *testing.T) {
170         var splittests []SplitTest
171         splittests = unixsplittests
172         if runtime.GOOS == "windows" {
173                 splittests = append(splittests, winsplittests...)
174         }
175         for _, test := range splittests {
176                 if d, f := filepath.Split(test.path); d != test.dir || f != test.file {
177                         t.Errorf("Split(%q) = %q, %q, want %q, %q", test.path, d, f, test.dir, test.file)
178                 }
179         }
180 }
181
182 type JoinTest struct {
183         elem []string
184         path string
185 }
186
187 var jointests = []JoinTest{
188         // zero parameters
189         {[]string{}, ""},
190
191         // one parameter
192         {[]string{""}, ""},
193         {[]string{"a"}, "a"},
194
195         // two parameters
196         {[]string{"a", "b"}, "a/b"},
197         {[]string{"a", ""}, "a"},
198         {[]string{"", "b"}, "b"},
199         {[]string{"/", "a"}, "/a"},
200         {[]string{"/", ""}, "/"},
201         {[]string{"a/", "b"}, "a/b"},
202         {[]string{"a/", ""}, "a"},
203         {[]string{"", ""}, ""},
204 }
205
206 var winjointests = []JoinTest{
207         {[]string{`directory`, `file`}, `directory\file`},
208         {[]string{`C:\Windows\`, `System32`}, `C:\Windows\System32`},
209         {[]string{`C:\Windows\`, ``}, `C:\Windows`},
210         {[]string{`C:\`, `Windows`}, `C:\Windows`},
211         {[]string{`C:`, `Windows`}, `C:\Windows`},
212         {[]string{`\\host\share`, `foo`}, `\\host\share\foo`},
213         {[]string{`//host/share`, `foo/bar`}, `\\host\share\foo\bar`},
214 }
215
216 // join takes a []string and passes it to Join.
217 func join(elem []string, args ...string) string {
218         args = elem
219         return filepath.Join(args...)
220 }
221
222 func TestJoin(t *testing.T) {
223         if runtime.GOOS == "windows" {
224                 jointests = append(jointests, winjointests...)
225         }
226         for _, test := range jointests {
227                 if p := join(test.elem); p != filepath.FromSlash(test.path) {
228                         t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path)
229                 }
230         }
231 }
232
233 type ExtTest struct {
234         path, ext string
235 }
236
237 var exttests = []ExtTest{
238         {"path.go", ".go"},
239         {"path.pb.go", ".go"},
240         {"a.dir/b", ""},
241         {"a.dir/b.go", ".go"},
242         {"a.dir/", ""},
243 }
244
245 func TestExt(t *testing.T) {
246         for _, test := range exttests {
247                 if x := filepath.Ext(test.path); x != test.ext {
248                         t.Errorf("Ext(%q) = %q, want %q", test.path, x, test.ext)
249                 }
250         }
251 }
252
253 type Node struct {
254         name    string
255         entries []*Node // nil if the entry is a file
256         mark    int
257 }
258
259 var tree = &Node{
260         "testdata",
261         []*Node{
262                 &Node{"a", nil, 0},
263                 &Node{"b", []*Node{}, 0},
264                 &Node{"c", nil, 0},
265                 &Node{
266                         "d",
267                         []*Node{
268                                 &Node{"x", nil, 0},
269                                 &Node{"y", []*Node{}, 0},
270                                 &Node{
271                                         "z",
272                                         []*Node{
273                                                 &Node{"u", nil, 0},
274                                                 &Node{"v", nil, 0},
275                                         },
276                                         0,
277                                 },
278                         },
279                         0,
280                 },
281         },
282         0,
283 }
284
285 func walkTree(n *Node, path string, f func(path string, n *Node)) {
286         f(path, n)
287         for _, e := range n.entries {
288                 walkTree(e, filepath.Join(path, e.name), f)
289         }
290 }
291
292 func makeTree(t *testing.T) {
293         walkTree(tree, tree.name, func(path string, n *Node) {
294                 if n.entries == nil {
295                         fd, err := os.Create(path)
296                         if err != nil {
297                                 t.Errorf("makeTree: %v", err)
298                         }
299                         fd.Close()
300                 } else {
301                         os.Mkdir(path, 0770)
302                 }
303         })
304 }
305
306 func markTree(n *Node) { walkTree(n, "", func(path string, n *Node) { n.mark++ }) }
307
308 func checkMarks(t *testing.T, report bool) {
309         walkTree(tree, tree.name, func(path string, n *Node) {
310                 if n.mark != 1 && report {
311                         t.Errorf("node %s mark = %d; expected 1", path, n.mark)
312                 }
313                 n.mark = 0
314         })
315 }
316
317 // Assumes that each node name is unique. Good enough for a test.
318 // If clear is true, any incoming error is cleared before return. The errors
319 // are always accumulated, though.
320 func mark(path string, info *os.FileInfo, err error, errors *[]error, clear bool) error {
321         if err != nil {
322                 *errors = append(*errors, err)
323                 if clear {
324                         return nil
325                 }
326                 return err
327         }
328         walkTree(tree, tree.name, func(path string, n *Node) {
329                 if n.name == info.Name {
330                         n.mark++
331                 }
332         })
333         return nil
334 }
335
336 func TestWalk(t *testing.T) {
337         makeTree(t)
338         errors := make([]error, 0, 10)
339         clear := true
340         markFn := func(path string, info *os.FileInfo, err error) error {
341                 return mark(path, info, err, &errors, clear)
342         }
343         // Expect no errors.
344         err := filepath.Walk(tree.name, markFn)
345         if err != nil {
346                 t.Errorf("no error expected, found: %s", err)
347         }
348         if len(errors) != 0 {
349                 t.Errorf("unexpected errors: %s", errors)
350         }
351         checkMarks(t, true)
352         errors = errors[0:0]
353
354         // Test permission errors.  Only possible if we're not root
355         // and only on some file systems (AFS, FAT).  To avoid errors during
356         // all.bash on those file systems, skip during gotest -short.
357         if os.Getuid() > 0 && !testing.Short() {
358                 // introduce 2 errors: chmod top-level directories to 0
359                 os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0)
360                 os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0)
361
362                 // 3) capture errors, expect two.
363                 // mark respective subtrees manually
364                 markTree(tree.entries[1])
365                 markTree(tree.entries[3])
366                 // correct double-marking of directory itself
367                 tree.entries[1].mark--
368                 tree.entries[3].mark--
369                 err := filepath.Walk(tree.name, markFn)
370                 if err != nil {
371                         t.Errorf("expected no error return from Walk, %s", err)
372                 }
373                 if len(errors) != 2 {
374                         t.Errorf("expected 2 errors, got %d: %s", len(errors), errors)
375                 }
376                 // the inaccessible subtrees were marked manually
377                 checkMarks(t, true)
378                 errors = errors[0:0]
379
380                 // 4) capture errors, stop after first error.
381                 // mark respective subtrees manually
382                 markTree(tree.entries[1])
383                 markTree(tree.entries[3])
384                 // correct double-marking of directory itself
385                 tree.entries[1].mark--
386                 tree.entries[3].mark--
387                 clear = false // error will stop processing
388                 err = filepath.Walk(tree.name, markFn)
389                 if err == nil {
390                         t.Errorf("expected error return from Walk")
391                 }
392                 if len(errors) != 1 {
393                         t.Errorf("expected 1 error, got %d: %s", len(errors), errors)
394                 }
395                 // the inaccessible subtrees were marked manually
396                 checkMarks(t, false)
397                 errors = errors[0:0]
398
399                 // restore permissions
400                 os.Chmod(filepath.Join(tree.name, tree.entries[1].name), 0770)
401                 os.Chmod(filepath.Join(tree.name, tree.entries[3].name), 0770)
402         }
403
404         // cleanup
405         if err := os.RemoveAll(tree.name); err != nil {
406                 t.Errorf("removeTree: %v", err)
407         }
408 }
409
410 var basetests = []PathTest{
411         {"", "."},
412         {".", "."},
413         {"/.", "."},
414         {"/", "/"},
415         {"////", "/"},
416         {"x/", "x"},
417         {"abc", "abc"},
418         {"abc/def", "def"},
419         {"a/b/.x", ".x"},
420         {"a/b/c.", "c."},
421         {"a/b/c.x", "c.x"},
422 }
423
424 func TestBase(t *testing.T) {
425         for _, test := range basetests {
426                 if s := filepath.ToSlash(filepath.Base(test.path)); s != test.result {
427                         t.Errorf("Base(%q) = %q, want %q", test.path, s, test.result)
428                 }
429         }
430 }
431
432 type IsAbsTest struct {
433         path  string
434         isAbs bool
435 }
436
437 var isabstests = []IsAbsTest{
438         {"", false},
439         {"/", true},
440         {"/usr/bin/gcc", true},
441         {"..", false},
442         {"/a/../bb", true},
443         {".", false},
444         {"./", false},
445         {"lala", false},
446 }
447
448 var winisabstests = []IsAbsTest{
449         {`C:\`, true},
450         {`c\`, false},
451         {`c::`, false},
452         {`c:`, false},
453         {`/`, false},
454         {`\`, false},
455         {`\Windows`, false},
456         {`c:a\b`, false},
457         {`\\host\share\foo`, true},
458         {`//host/share/foo/bar`, true},
459 }
460
461 func TestIsAbs(t *testing.T) {
462         var tests []IsAbsTest
463         if runtime.GOOS == "windows" {
464                 tests = append(tests, winisabstests...)
465                 // All non-windows tests should fail, because they have no volume letter.
466                 for _, test := range isabstests {
467                         tests = append(tests, IsAbsTest{test.path, false})
468                 }
469                 // All non-windows test should work as intended if prefixed with volume letter.
470                 for _, test := range isabstests {
471                         tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs})
472                 }
473         } else {
474                 tests = isabstests
475         }
476
477         for _, test := range tests {
478                 if r := filepath.IsAbs(test.path); r != test.isAbs {
479                         t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs)
480                 }
481         }
482 }
483
484 type EvalSymlinksTest struct {
485         path, dest string
486 }
487
488 var EvalSymlinksTestDirs = []EvalSymlinksTest{
489         {"test", ""},
490         {"test/dir", ""},
491         {"test/dir/link3", "../../"},
492         {"test/link1", "../test"},
493         {"test/link2", "dir"},
494 }
495
496 var EvalSymlinksTests = []EvalSymlinksTest{
497         {"test", "test"},
498         {"test/dir", "test/dir"},
499         {"test/dir/../..", "."},
500         {"test/link1", "test"},
501         {"test/link2", "test/dir"},
502         {"test/link1/dir", "test/dir"},
503         {"test/link2/..", "test"},
504         {"test/dir/link3", "."},
505         {"test/link2/link3/test", "test"},
506 }
507
508 var EvalSymlinksAbsWindowsTests = []EvalSymlinksTest{
509         {`c:\`, `c:\`},
510 }
511
512 func testEvalSymlinks(t *testing.T, tests []EvalSymlinksTest) {
513         for _, d := range tests {
514                 if p, err := filepath.EvalSymlinks(d.path); err != nil {
515                         t.Errorf("EvalSymlinks(%q) error: %v", d.path, err)
516                 } else if filepath.Clean(p) != filepath.Clean(d.dest) {
517                         t.Errorf("EvalSymlinks(%q)=%q, want %q", d.path, p, d.dest)
518                 }
519         }
520 }
521
522 func TestEvalSymlinks(t *testing.T) {
523         defer os.RemoveAll("test")
524         for _, d := range EvalSymlinksTestDirs {
525                 var err error
526                 if d.dest == "" {
527                         err = os.Mkdir(d.path, 0755)
528                 } else {
529                         if runtime.GOOS != "windows" {
530                                 err = os.Symlink(d.dest, d.path)
531                         }
532                 }
533                 if err != nil {
534                         t.Fatal(err)
535                 }
536         }
537         var tests []EvalSymlinksTest
538         if runtime.GOOS == "windows" {
539                 for _, d := range EvalSymlinksTests {
540                         if d.path == d.dest {
541                                 // will test only real files and directories
542                                 tests = append(tests, d)
543                         }
544                 }
545         } else {
546                 tests = EvalSymlinksTests
547         }
548         // relative
549         testEvalSymlinks(t, tests)
550         // absolute
551 /* These tests do not work in the gccgo test environment.
552         goroot, err := filepath.EvalSymlinks(os.Getenv("GOROOT"))
553         if err != nil {
554                 t.Fatalf("EvalSymlinks(%q) error: %v", os.Getenv("GOROOT"), err)
555         }
556         testroot := filepath.Join(goroot, "src", "pkg", "path", "filepath")
557         for i, d := range tests {
558                 tests[i].path = filepath.Join(testroot, d.path)
559                 tests[i].dest = filepath.Join(testroot, d.dest)
560         }
561         if runtime.GOOS == "windows" {
562                 for _, d := range EvalSymlinksAbsWindowsTests {
563                         tests = append(tests, d)
564                 }
565         }
566         testEvalSymlinks(t, tests)
567 */
568 }
569
570 /* These tests do not work in the gccgo test environment.
571
572 // Test paths relative to $GOROOT/src
573 var abstests = []string{
574         "../AUTHORS",
575         "pkg/../../AUTHORS",
576         "Make.pkg",
577         "pkg/Makefile",
578         ".",
579         "$GOROOT/src/Make.pkg",
580         "$GOROOT/src/../src/Make.pkg",
581         "$GOROOT/misc/cgo",
582         "$GOROOT",
583 }
584
585 func TestAbs(t *testing.T) {
586         oldwd, err := os.Getwd()
587         if err != nil {
588                 t.Fatal("Getwd failed: " + err.Error())
589         }
590         defer os.Chdir(oldwd)
591         goroot := os.Getenv("GOROOT")
592         cwd := filepath.Join(goroot, "src")
593         os.Chdir(cwd)
594         for _, path := range abstests {
595                 path = strings.Replace(path, "$GOROOT", goroot, -1)
596                 info, err := os.Stat(path)
597                 if err != nil {
598                         t.Errorf("%s: %s", path, err)
599                 }
600
601                 abspath, err := filepath.Abs(path)
602                 if err != nil {
603                         t.Errorf("Abs(%q) error: %v", path, err)
604                 }
605                 absinfo, err := os.Stat(abspath)
606                 if err != nil || absinfo.Ino != info.Ino {
607                         t.Errorf("Abs(%q)=%q, not the same file", path, abspath)
608                 }
609                 if !filepath.IsAbs(abspath) {
610                         t.Errorf("Abs(%q)=%q, not an absolute path", path, abspath)
611                 }
612                 if filepath.IsAbs(path) && abspath != filepath.Clean(path) {
613                         t.Errorf("Abs(%q)=%q, isn't clean", path, abspath)
614                 }
615         }
616 }
617
618 */
619
620 type RelTests struct {
621         root, path, want string
622 }
623
624 var reltests = []RelTests{
625         {"a/b", "a/b", "."},
626         {"a/b/.", "a/b", "."},
627         {"a/b", "a/b/.", "."},
628         {"./a/b", "a/b", "."},
629         {"a/b", "./a/b", "."},
630         {"ab/cd", "ab/cde", "../cde"},
631         {"ab/cd", "ab/c", "../c"},
632         {"a/b", "a/b/c/d", "c/d"},
633         {"a/b", "a/b/../c", "../c"},
634         {"a/b/../c", "a/b", "../b"},
635         {"a/b/c", "a/c/d", "../../c/d"},
636         {"a/b", "c/d", "../../c/d"},
637         {"../../a/b", "../../a/b/c/d", "c/d"},
638         {"/a/b", "/a/b", "."},
639         {"/a/b/.", "/a/b", "."},
640         {"/a/b", "/a/b/.", "."},
641         {"/ab/cd", "/ab/cde", "../cde"},
642         {"/ab/cd", "/ab/c", "../c"},
643         {"/a/b", "/a/b/c/d", "c/d"},
644         {"/a/b", "/a/b/../c", "../c"},
645         {"/a/b/../c", "/a/b", "../b"},
646         {"/a/b/c", "/a/c/d", "../../c/d"},
647         {"/a/b", "/c/d", "../../c/d"},
648         {"/../../a/b", "/../../a/b/c/d", "c/d"},
649         {".", "a/b", "a/b"},
650         {".", "..", ".."},
651
652         // can't do purely lexically
653         {"..", ".", "err"},
654         {"..", "a", "err"},
655         {"../..", "..", "err"},
656         {"a", "/a", "err"},
657         {"/a", "a", "err"},
658 }
659
660 var winreltests = []RelTests{
661         {`C:a\b\c`, `C:a/b/d`, `..\d`},
662         {`C:\`, `D:\`, `err`},
663         {`C:`, `D:`, `err`},
664 }
665
666 func TestRel(t *testing.T) {
667         tests := append([]RelTests{}, reltests...)
668         if runtime.GOOS == "windows" {
669                 for i := range tests {
670                         tests[i].want = filepath.FromSlash(tests[i].want)
671                 }
672                 tests = append(tests, winreltests...)
673         }
674         for _, test := range tests {
675                 got, err := filepath.Rel(test.root, test.path)
676                 if test.want == "err" {
677                         if err == nil {
678                                 t.Errorf("Rel(%q, %q)=%q, want error", test.root, test.path, got)
679                         }
680                         continue
681                 }
682                 if err != nil {
683                         t.Errorf("Rel(%q, %q): want %q, got error: %s", test.root, test.path, test.want, err)
684                 }
685                 if got != test.want {
686                         t.Errorf("Rel(%q, %q)=%q, want %q", test.root, test.path, got, test.want)
687                 }
688         }
689 }
690
691 type VolumeNameTest struct {
692         path string
693         vol  string
694 }
695
696 var volumenametests = []VolumeNameTest{
697         {`c:/foo/bar`, `c:`},
698         {`c:`, `c:`},
699         {``, ``},
700         {`\\\host`, ``},
701         {`\\\host\`, ``},
702         {`\\\host\share`, ``},
703         {`\\\host\\share`, ``},
704         {`\\host`, ``},
705         {`//host`, ``},
706         {`\\host\`, ``},
707         {`//host/`, ``},
708         {`\\host\share`, `\\host\share`},
709         {`//host/share`, `//host/share`},
710         {`\\host\share\`, `\\host\share`},
711         {`//host/share/`, `//host/share`},
712         {`\\host\share\foo`, `\\host\share`},
713         {`//host/share/foo`, `//host/share`},
714         {`\\host\share\\foo\\\bar\\\\baz`, `\\host\share`},
715         {`//host/share//foo///bar////baz`, `//host/share`},
716         {`\\host\share\foo\..\bar`, `\\host\share`},
717         {`//host/share/foo/../bar`, `//host/share`},
718 }
719
720 func TestVolumeName(t *testing.T) {
721         if runtime.GOOS != "windows" {
722                 return
723         }
724         for _, v := range volumenametests {
725                 if vol := filepath.VolumeName(v.path); vol != v.vol {
726                         t.Errorf("VolumeName(%q)=%q, want %q", v.path, vol, v.vol)
727                 }
728         }
729 }