@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/ARM-software/golang-utils/utils/commonerrors"
14
14
"github.com/ARM-software/golang-utils/utils/commonerrors/errortest"
15
+ "github.com/ARM-software/golang-utils/utils/platform"
15
16
)
16
17
17
18
func TestFilepathStem (t * testing.T ) {
@@ -30,24 +31,52 @@ func TestFilepathStem(t *testing.T) {
30
31
}
31
32
32
33
func TestFilepathParents (t * testing.T ) {
33
-
34
- tests := []struct {
34
+ type PathTest struct {
35
35
path string
36
36
expectedParents []string
37
- }{
37
+ }
38
+ tests := []PathTest {
38
39
{},
39
40
{
40
41
path : " " ,
41
42
expectedParents : nil ,
42
43
},
44
+ {
45
+ path : "/" ,
46
+ expectedParents : nil ,
47
+ },
48
+ {
49
+ path : "." ,
50
+ expectedParents : nil ,
51
+ },
52
+ {
53
+ path : "./" ,
54
+ expectedParents : nil ,
55
+ },
56
+ {
57
+ path : "./blah" ,
58
+ expectedParents : []string {"." },
59
+ },
43
60
{
44
61
path : filepath .Join ("a" , "great" , "fake" , "path" , "blah" ),
45
62
expectedParents : []string {"a" , filepath .Join ("a" , "great" ), filepath .Join ("a" , "great" , "fake" ), filepath .Join ("a" , "great" , "fake" , "path" )},
46
63
},
47
64
{
65
+ path : "/foo/bar/setup.py" ,
66
+ expectedParents : []string {`foo` , filepath .Join (`foo` , `bar` )},
67
+ },
68
+ }
69
+
70
+ if platform .IsWindows () {
71
+ tests = append (tests , PathTest {
48
72
path : "C:/foo/bar/setup.py" ,
49
73
expectedParents : []string {"C:" , filepath .Join (`C:` , `\foo` ), filepath .Join (`C:` , `\foo` , `bar` )},
50
- },
74
+ })
75
+ } else {
76
+ tests = append (tests , PathTest {
77
+ path : "C:/foo/bar/setup.py" ,
78
+ expectedParents : []string {"C:" , filepath .Join (`C:` , `foo` ), filepath .Join (`C:` , `foo` , `bar` )},
79
+ })
51
80
}
52
81
for _ , tt := range tests {
53
82
t .Run (tt .path , func (t * testing.T ) {
0 commit comments