Skip to content

Commit fed3de5

Browse files
committed
make test work on windows
1 parent c58be5e commit fed3de5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

test/system/test_filesystem.f90

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ end subroutine test_get_file_size_dir
370370
subroutine test_get_file_size_file(error)
371371
type(error_type), allocatable, intent(out) :: error
372372
character(len=256) :: filename
373-
integer :: ios, iunit
373+
integer :: ios, iunit, iocmd
374374
character(len=512) :: msg
375375
character(len=20) :: text
376376

@@ -379,8 +379,8 @@ subroutine test_get_file_size_file(error)
379379

380380
filename = "test_file.txt"
381381

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)
384384
call check(error, ios == 0, "Cannot create test file: " // trim(msg))
385385
if (allocated(error)) return
386386

@@ -389,18 +389,22 @@ subroutine test_get_file_size_file(error)
389389
call check(error, size == 0 .and. err%ok(), "Empty file has a non-zero size!: " // to_string(size))
390390

391391
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
393393
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))
395399

396400
! get the size of the file => should be len(text)
397401
size = get_file_size(filename, err)
398402
call check(error, size == len(text) .and. err%ok(), "file has an unexpected size!, Expected: " &
399403
// to_string(len(text)) // " ,Got: " // to_string(size))
400404

401405
! 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))
404408
if (allocated(error)) return
405409
end subroutine test_get_file_size_file
406410

0 commit comments

Comments
 (0)