~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/path/filepath/path_windows_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package filepath_test
 
2
 
 
3
import (
 
4
        "io/ioutil"
 
5
        "os"
 
6
        "os/exec"
 
7
        "path/filepath"
 
8
        "reflect"
 
9
        "testing"
 
10
)
 
11
 
 
12
func TestWinSplitListTestsAreValid(t *testing.T) {
 
13
        comspec := os.Getenv("ComSpec")
 
14
        if comspec == "" {
 
15
                t.Fatal("%ComSpec% must be set")
 
16
        }
 
17
 
 
18
        for ti, tt := range winsplitlisttests {
 
19
                testWinSplitListTestIsValid(t, ti, tt, comspec)
 
20
        }
 
21
}
 
22
 
 
23
func testWinSplitListTestIsValid(t *testing.T, ti int, tt SplitListTest,
 
24
        comspec string) {
 
25
 
 
26
        const (
 
27
                cmdfile             = `printdir.cmd`
 
28
                perm    os.FileMode = 0700
 
29
        )
 
30
 
 
31
        tmp, err := ioutil.TempDir("", "testWinSplitListTestIsValid")
 
32
        if err != nil {
 
33
                t.Fatalf("TempDir failed: %v", err)
 
34
        }
 
35
        defer os.RemoveAll(tmp)
 
36
 
 
37
        for i, d := range tt.result {
 
38
                if d == "" {
 
39
                        continue
 
40
                }
 
41
                if cd := filepath.Clean(d); filepath.VolumeName(cd) != "" ||
 
42
                        cd[0] == '\\' || cd == ".." || (len(cd) >= 3 && cd[0:3] == `..\`) {
 
43
                        t.Errorf("%d,%d: %#q refers outside working directory", ti, i, d)
 
44
                        return
 
45
                }
 
46
                dd := filepath.Join(tmp, d)
 
47
                if _, err := os.Stat(dd); err == nil {
 
48
                        t.Errorf("%d,%d: %#q already exists", ti, i, d)
 
49
                        return
 
50
                }
 
51
                if err = os.MkdirAll(dd, perm); err != nil {
 
52
                        t.Errorf("%d,%d: MkdirAll(%#q) failed: %v", ti, i, dd, err)
 
53
                        return
 
54
                }
 
55
                fn, data := filepath.Join(dd, cmdfile), []byte("@echo "+d+"\r\n")
 
56
                if err = ioutil.WriteFile(fn, data, perm); err != nil {
 
57
                        t.Errorf("%d,%d: WriteFile(%#q) failed: %v", ti, i, fn, err)
 
58
                        return
 
59
                }
 
60
        }
 
61
 
 
62
        for i, d := range tt.result {
 
63
                if d == "" {
 
64
                        continue
 
65
                }
 
66
                exp := []byte(d + "\r\n")
 
67
                cmd := &exec.Cmd{
 
68
                        Path: comspec,
 
69
                        Args: []string{`/c`, cmdfile},
 
70
                        Env:  []string{`Path=` + tt.list},
 
71
                        Dir:  tmp,
 
72
                }
 
73
                out, err := cmd.CombinedOutput()
 
74
                switch {
 
75
                case err != nil:
 
76
                        t.Errorf("%d,%d: execution error %v\n%q", ti, i, err, out)
 
77
                        return
 
78
                case !reflect.DeepEqual(out, exp):
 
79
                        t.Errorf("%d,%d: expected %#q, got %#q", ti, i, exp, out)
 
80
                        return
 
81
                default:
 
82
                        // unshadow cmdfile in next directory
 
83
                        err = os.Remove(filepath.Join(tmp, d, cmdfile))
 
84
                        if err != nil {
 
85
                                t.Fatalf("Remove test command failed: %v", err)
 
86
                        }
 
87
                }
 
88
        }
 
89
}