@@ -180,8 +180,69 @@ function testFtruncate(cb) {
180
180
fs . writeFileSync ( file5 , 'Hi' ) ;
181
181
const fd = fs . openSync ( file5 , 'r+' ) ;
182
182
process . on ( 'exit' , ( ) => fs . closeSync ( fd ) ) ;
183
+
184
+ [ '' , false , null , { } , [ ] ] . forEach ( ( i ) => {
185
+ common . expectsError (
186
+ ( ) => fs . ftruncate ( fd , i ) ,
187
+ {
188
+ code : 'ERR_INVALID_ARG_TYPE' ,
189
+ type : TypeError ,
190
+ message : 'The "len" argument must be of type number'
191
+ }
192
+ ) ;
193
+ } ) ;
194
+
183
195
fs . ftruncate ( fd , undefined , common . mustCall ( function ( err ) {
184
196
assert . ifError ( err ) ;
185
197
assert ( fs . readFileSync ( file5 ) . equals ( Buffer . from ( '' ) ) ) ;
186
198
} ) ) ;
187
199
}
200
+
201
+ {
202
+ const file6 = path . resolve ( tmp , 'truncate-file-6.txt' ) ;
203
+ fs . writeFileSync ( file6 , 'Hi' ) ;
204
+ const fd = fs . openSync ( file6 , 'r+' ) ;
205
+ process . on ( 'exit' , ( ) => fs . closeSync ( fd ) ) ;
206
+ fs . ftruncate ( fd , - 1 , common . mustCall ( function ( err ) {
207
+ assert . ifError ( err ) ;
208
+ assert ( fs . readFileSync ( file6 ) . equals ( Buffer . from ( '' ) ) ) ;
209
+ } ) ) ;
210
+ }
211
+
212
+ [ '' , false , null , undefined , { } , [ ] ] . forEach ( ( i ) => {
213
+ common . expectsError (
214
+ ( ) => fs . ftruncate ( i ) ,
215
+ {
216
+ code : 'ERR_INVALID_ARG_TYPE' ,
217
+ type : TypeError ,
218
+ message : 'The "fd" argument must be of type number'
219
+ }
220
+ ) ;
221
+ common . expectsError (
222
+ ( ) => fs . ftruncateSync ( i ) ,
223
+ {
224
+ code : 'ERR_INVALID_ARG_TYPE' ,
225
+ type : TypeError ,
226
+ message : 'The "fd" argument must be of type number'
227
+ }
228
+ ) ;
229
+ } ) ;
230
+
231
+ [ - 1 , 0xFFFFFFFF + 1 ] . forEach ( ( i ) => {
232
+ common . expectsError (
233
+ ( ) => fs . ftruncate ( i ) ,
234
+ {
235
+ code : 'ERR_OUT_OF_RANGE' ,
236
+ type : RangeError ,
237
+ message : 'The "fd" argument is out of range'
238
+ }
239
+ ) ;
240
+ common . expectsError (
241
+ ( ) => fs . ftruncateSync ( i ) ,
242
+ {
243
+ code : 'ERR_OUT_OF_RANGE' ,
244
+ type : RangeError ,
245
+ message : 'The "fd" argument is out of range'
246
+ }
247
+ ) ;
248
+ } ) ;
0 commit comments