@@ -370,7 +370,7 @@ end subroutine test_get_file_size_dir
370
370
subroutine test_get_file_size_file (error )
371
371
type (error_type), allocatable , intent (out ) :: error
372
372
character (len= 256 ) :: filename
373
- integer :: ios, iunit
373
+ integer :: ios, iunit, iocmd
374
374
character (len= 512 ) :: msg
375
375
character (len= 20 ) :: text
376
376
@@ -379,8 +379,8 @@ subroutine test_get_file_size_file(error)
379
379
380
380
filename = " test_file.txt"
381
381
382
- ! Create a file
383
- open (newunit= iunit, file= filename, status= " replace" , action= ' write' , iostat= ios, iomsg= msg)
382
+ ! Create a file and open it in `stream` access
383
+ open (newunit= iunit, file= filename, status= " replace" , action= ' write' , access = ' stream ' , iostat= ios, iomsg= msg)
384
384
call check(error, ios == 0 , " Cannot create test file: " // trim (msg))
385
385
if (allocated (error)) return
386
386
@@ -389,18 +389,22 @@ subroutine test_get_file_size_file(error)
389
389
call check(error, size == 0 .and. err% ok(), " Empty file has a non-zero size!: " // to_string(size))
390
390
391
391
text = " Hello, World!"
392
- write (iunit, ' (A) ' , advance = ' NO ' , iostat= ios, iomsg= msg) text ! no newlines or additional bytes
392
+ write (iunit, iostat= ios, iomsg= msg) text ! no newlines or additional bytes
393
393
call check(error, ios == 0 , " Cannot write to test file: " // trim (msg))
394
- flush(iunit) ! flush the buffer
394
+
395
+ ! close the file to flush the previous write
396
+ ! `flush` doesn't seem to work on windows
397
+ close (iunit,iostat= ios,iomsg= msg)
398
+ call check(error, ios == 0 , " Cannot close test file: " // trim (msg))
395
399
396
400
! get the size of the file => should be len(text)
397
401
size = get_file_size(filename, err)
398
402
call check(error, size == len (text) .and. err% ok(), " file has an unexpected size!, Expected: " &
399
403
// to_string(len (text)) // " ,Got: " // to_string(size))
400
404
401
405
! Clean up: remove the file
402
- close (iunit,status = ' delete ' ,iostat = ios,iomsg = msg)
403
- call check(error, ios == 0 , " Cannot delete test file: " // trim (msg))
406
+ call execute_command_line( " rm " // filename, exitstat = ios, cmdstat = iocmd, cmdmsg = msg)
407
+ call check(error, ios == 0 .and. iocmd == 0 , " Cannot remove test file: " // trim (msg))
404
408
if (allocated (error)) return
405
409
end subroutine test_get_file_size_file
406
410
0 commit comments