@@ -9,37 +9,61 @@ import (
9
9
"os"
10
10
"path/filepath"
11
11
"runtime"
12
+ "strings"
12
13
"testing"
13
14
14
15
"github.com/golang/dep/internal/test"
15
16
)
16
17
18
+ // This function tests HadFilepathPrefix. It should test it on both case
19
+ // sensitive and insensitive situations. However, the only reliable way to test
20
+ // case-insensitive behaviour is if using case-insensitive filesystem. This
21
+ // cannot be guaranteed in an automated test. Therefore, the behaviour of the
22
+ // tests is not to test case sensitivity on *nix and to assume that Windows is
23
+ // case-insensitive. Please see link below for some background.
24
+ //
25
+ // https://superuser.com/questions/266110/how-do-you-make-windows-7-fully-case-sensitive-with-respect-to-the-filesystem
26
+ //
27
+ // NOTE: NTFS can be made case-sensitive. However many Windows programs,
28
+ // including Windows Explorer do not handle gracefully multiple files that
29
+ // differ only in capitalization. It is possible that this can cause these tests
30
+ // to fail on some setups.
17
31
func TestHasFilepathPrefix (t * testing.T ) {
18
32
dir , err := ioutil .TempDir ("" , "dep" )
19
33
if err != nil {
20
34
t .Fatal (err )
21
35
}
22
36
defer os .RemoveAll (dir )
23
37
38
+ // dir2 is the same as dir but with different capitalization on Windows to
39
+ // test case insensitivity
40
+ var dir2 string
41
+ if runtime .GOOS == "windows" {
42
+ dir = strings .ToLower (dir )
43
+ dir2 = strings .ToUpper (dir )
44
+ } else {
45
+ dir2 = dir
46
+ }
47
+
24
48
cases := []struct {
25
49
path string
26
50
prefix string
27
51
want bool
28
52
}{
29
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir ), true },
30
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir , "a" ), true },
31
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir , "a" , "b" ), true },
32
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir , "c" ), false },
33
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir , "a" , "d" , "b" ), false },
34
- {filepath .Join (dir , "a" , "b" ), filepath .Join (dir , "a" , "b2" ), false },
35
- {filepath .Join (dir ), filepath .Join (dir , "a" , "b" ), false },
36
- {filepath .Join (dir , "ab" ), filepath .Join (dir , "a" , "b" ), false },
37
- {filepath .Join (dir , "ab" ), filepath .Join (dir , "a" ), false },
38
- {filepath .Join (dir , "123" ), filepath .Join (dir , "123" ), true },
39
- {filepath .Join (dir , "123" ), filepath .Join (dir , "1" ), false },
40
- {filepath .Join (dir , "⌘" ), filepath .Join (dir , "⌘" ), true },
41
- {filepath .Join (dir , "a" ), filepath .Join (dir , "⌘" ), false },
42
- {filepath .Join (dir , "⌘" ), filepath .Join (dir , "a" ), false },
53
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 ), true },
54
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 , "a" ), true },
55
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 , "a" , "b" ), true },
56
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 , "c" ), false },
57
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 , "a" , "d" , "b" ), false },
58
+ {filepath .Join (dir , "a" , "b" ), filepath .Join (dir2 , "a" , "b2" ), false },
59
+ {filepath .Join (dir ), filepath .Join (dir2 , "a" , "b" ), false },
60
+ {filepath .Join (dir , "ab" ), filepath .Join (dir2 , "a" , "b" ), false },
61
+ {filepath .Join (dir , "ab" ), filepath .Join (dir2 , "a" ), false },
62
+ {filepath .Join (dir , "123" ), filepath .Join (dir2 , "123" ), true },
63
+ {filepath .Join (dir , "123" ), filepath .Join (dir2 , "1" ), false },
64
+ {filepath .Join (dir , "⌘" ), filepath .Join (dir2 , "⌘" ), true },
65
+ {filepath .Join (dir , "a" ), filepath .Join (dir2 , "⌘" ), false },
66
+ {filepath .Join (dir , "⌘" ), filepath .Join (dir2 , "a" ), false },
43
67
}
44
68
45
69
for _ , c := range cases {
@@ -57,13 +81,36 @@ func TestHasFilepathPrefix(t *testing.T) {
57
81
}
58
82
}
59
83
84
+ // This function tests HadFilepathPrefix. It should test it on both case
85
+ // sensitive and insensitive situations. However, the only reliable way to test
86
+ // case-insensitive behaviour is if using case-insensitive filesystem. This
87
+ // cannot be guaranteed in an automated test. Therefore, the behaviour of the
88
+ // tests is not to test case sensitivity on *nix and to assume that Windows is
89
+ // case-insensitive. Please see link below for some background.
90
+ //
91
+ // https://superuser.com/questions/266110/how-do-you-make-windows-7-fully-case-sensitive-with-respect-to-the-filesystem
92
+ //
93
+ // NOTE: NTFS can be made case-sensitive. However many Windows programs,
94
+ // including Windows Explorer do not handle gracefully multiple files that
95
+ // differ only in capitalization. It is possible that this can cause these tests
96
+ // to fail on some setups.
60
97
func TestHasFilepathPrefix_Files (t * testing.T ) {
61
98
dir , err := ioutil .TempDir ("" , "dep" )
62
99
if err != nil {
63
100
t .Fatal (err )
64
101
}
65
102
defer os .RemoveAll (dir )
66
103
104
+ // dir2 is the same as dir but with different capitalization on Windows to
105
+ // test case insensitivity
106
+ var dir2 string
107
+ if runtime .GOOS == "windows" {
108
+ dir = strings .ToLower (dir )
109
+ dir2 = strings .ToUpper (dir )
110
+ } else {
111
+ dir2 = dir
112
+ }
113
+
67
114
existingFile := filepath .Join (dir , "exists" )
68
115
if _ , err := os .Create (existingFile ); err != nil {
69
116
t .Fatal (err )
@@ -76,8 +123,8 @@ func TestHasFilepathPrefix_Files(t *testing.T) {
76
123
prefix string
77
124
want bool
78
125
}{
79
- {existingFile , filepath .Join (dir ), false },
80
- {nonExistingFile , filepath .Join (dir ), true },
126
+ {existingFile , filepath .Join (dir2 ), false },
127
+ {nonExistingFile , filepath .Join (dir2 ), true },
81
128
}
82
129
83
130
for _ , c := range cases {
0 commit comments