1
1
use std:: { env, process} ;
2
- use wasi_tests:: { create_tmp_dir, open_scratch_directory, TESTCONFIG } ;
2
+ use wasi_tests:: { create_tmp_dir, open_scratch_directory} ;
3
3
4
4
unsafe fn test_file_allocate ( dir_fd : wasi:: Fd ) {
5
5
// Create a file in the scratch directory.
@@ -25,21 +25,22 @@ unsafe fn test_file_allocate(dir_fd: wasi::Fd) {
25
25
let mut stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
26
26
assert_eq ! ( stat. size, 0 , "file size should be 0" ) ;
27
27
28
- if TESTCONFIG . support_fd_allocate ( ) {
29
- // Allocate some size
30
- wasi:: fd_allocate ( file_fd, 0 , 100 ) . expect ( "allocating size" ) ;
31
- stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
32
- assert_eq ! ( stat. size, 100 , "file size should be 100" ) ;
28
+ match wasi:: fd_allocate ( file_fd, 0 , 100 ) {
29
+ Ok ( ( ) ) => {
30
+ stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
31
+ assert_eq ! ( stat. size, 100 , "file size should be 100" ) ;
33
32
34
- // Allocate should not modify if less than current size
35
- wasi:: fd_allocate ( file_fd, 10 , 10 ) . expect ( "allocating size less than current size" ) ;
36
- stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
37
- assert_eq ! ( stat. size, 100 , "file size should remain unchanged at 100" ) ;
33
+ // Allocate should not modify if less than current size
34
+ wasi:: fd_allocate ( file_fd, 10 , 10 ) . expect ( "allocating size less than current size" ) ;
35
+ stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
36
+ assert_eq ! ( stat. size, 100 , "file size should remain unchanged at 100" ) ;
38
37
39
- // Allocate should modify if offset+len > current_len
40
- wasi:: fd_allocate ( file_fd, 90 , 20 ) . expect ( "allocating size larger than current size" ) ;
41
- stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
42
- assert_eq ! ( stat. size, 110 , "file size should increase from 100 to 110" ) ;
38
+ // Allocate should modify if offset+len > current_len
39
+ wasi:: fd_allocate ( file_fd, 90 , 20 ) . expect ( "allocating size larger than current size" ) ;
40
+ stat = wasi:: fd_filestat_get ( file_fd) . expect ( "reading file stats" ) ;
41
+ assert_eq ! ( stat. size, 110 , "file size should increase from 100 to 110" ) ;
42
+ } ,
43
+ Err ( err) => { assert_eq ! ( err, wasi:: ERRNO_NOTSUP , "allocating size" ) ; }
43
44
}
44
45
wasi:: fd_close ( file_fd) . expect ( "closing a file" ) ;
45
46
wasi:: path_unlink_file ( dir_fd, "file" ) . expect ( "removing a file" ) ;
0 commit comments