@@ -71,23 +71,32 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
71
71
t .Fatal (err )
72
72
}
73
73
}
74
- expectedHiddenPaths := make ([]string , 0 , 4 )
75
- expectedRegularPaths := make ([]string , 0 , 6 )
74
+ expectedPaths := make ([]string , 0 , 4 )
75
+ expectedSize := int64 (0 )
76
+
77
+ testInputs:
76
78
for p := range testInputs {
77
- path := filepath .Join (tmppath , p )
78
- stat , err := os .Stat (path )
79
- if err != nil {
80
- t .Fatal (err )
81
- }
82
- if ! fileFilter .ShouldExclude (stat ) {
83
- if isFullPathHidden (path ) {
84
- expectedHiddenPaths = append (expectedHiddenPaths , p )
85
- } else {
86
- expectedRegularPaths = append (expectedRegularPaths , p )
79
+ components := strings .Split (p , "/" )
80
+ var stat os.FileInfo
81
+ for i := range components {
82
+ stat , err = os .Stat (filepath .Join (
83
+ append ([]string {tmppath }, components [:i + 1 ]... )... ,
84
+ ))
85
+ if err != nil {
86
+ t .Fatal (err )
87
87
}
88
+ if fileFilter .ShouldExclude (stat ) {
89
+ continue testInputs
90
+ }
91
+ }
92
+ expectedPaths = append (expectedPaths , p )
93
+ if stat .Mode ().IsRegular () {
94
+ expectedSize += stat .Size ()
88
95
}
89
96
}
90
97
98
+ sort .Strings (expectedPaths )
99
+
91
100
stat , err := os .Stat (tmppath )
92
101
if err != nil {
93
102
t .Fatal (err )
@@ -102,9 +111,14 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
102
111
}
103
112
defer sf .Close ()
104
113
114
+ if size , err := sf .Size (); err != nil {
115
+ t .Fatalf ("failed to determine size: %s" , err )
116
+ } else if size != expectedSize {
117
+ t .Fatalf ("expected size %d, got size %d" , expectedSize , size )
118
+ }
119
+
105
120
rootFound := false
106
- actualRegularPaths := make ([]string , 0 , len (expectedRegularPaths ))
107
- actualHiddenPaths := make ([]string , 0 , len (expectedHiddenPaths ))
121
+ actualPaths := make ([]string , 0 , len (expectedPaths ))
108
122
err = Walk (sf , func (path string , nd Node ) error {
109
123
defer nd .Close ()
110
124
@@ -119,16 +133,15 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
119
133
rootFound = true
120
134
return nil
121
135
}
122
- if isFullPathHidden (path ) {
123
- actualHiddenPaths = append (actualHiddenPaths , path )
124
- } else {
125
- actualRegularPaths = append (actualRegularPaths , path )
126
- }
136
+ actualPaths = append (actualPaths , path )
127
137
if ! hidden && isFullPathHidden (path ) {
128
138
return fmt .Errorf ("found a hidden file" )
129
139
}
130
- if fileFilter .Rules .MatchesPath (path ) {
131
- return fmt .Errorf ("found a file that should be excluded" )
140
+ components := filepath .SplitList (path )
141
+ for i := range components {
142
+ if fileFilter .Rules .MatchesPath (filepath .Join (components [:i + 1 ]... )) {
143
+ return fmt .Errorf ("found a file that should be excluded" )
144
+ }
132
145
}
133
146
134
147
data , ok := testInputs [path ]
@@ -155,19 +168,27 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
155
168
}
156
169
return nil
157
170
})
171
+ if err != nil {
172
+ t .Fatal (err )
173
+ }
158
174
if ! rootFound {
159
175
t .Fatal ("didn't find the root" )
160
176
}
161
- for _ , regular := range expectedRegularPaths {
162
- if idx := sort .SearchStrings (actualRegularPaths , regular ); idx < 0 {
163
- t .Errorf ("missed regular path %q" , regular )
164
- }
177
+
178
+ if len (expectedPaths ) != len (actualPaths ) {
179
+ t .Fatalf ("expected %d paths, found %d" ,
180
+ len (expectedPaths ),
181
+ len (actualPaths ),
182
+ )
165
183
}
166
- if hidden && len (actualHiddenPaths ) != len (expectedHiddenPaths ) {
167
- for _ , missing := range expectedHiddenPaths {
168
- if idx := sort .SearchStrings (actualHiddenPaths , missing ); idx < 0 {
169
- t .Errorf ("missed hidden path %q" , missing )
170
- }
184
+
185
+ for i := range expectedPaths {
186
+ if expectedPaths [i ] != actualPaths [i ] {
187
+ t .Errorf (
188
+ "expected path %q does not match actual %q" ,
189
+ expectedPaths [i ],
190
+ actualPaths [i ],
191
+ )
171
192
}
172
193
}
173
194
}
0 commit comments