Skip to content

Commit 103cf9b

Browse files
committed
add test
1 parent a89bc91 commit 103cf9b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/system/test_os.f90

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module test_os
22
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
3-
use stdlib_system, only: get_runtime_os, OS_WINDOWS, OS_UNKNOWN, OS_TYPE, is_windows
3+
use stdlib_system, only: get_runtime_os, OS_WINDOWS, OS_UNKNOWN, OS_TYPE, is_windows, null_device
44

55
implicit none
66

@@ -13,7 +13,8 @@ subroutine collect_suite(testsuite)
1313

1414
testsuite = [ &
1515
new_unittest('test_get_runtime_os', test_get_runtime_os), &
16-
new_unittest('test_is_windows', test_is_windows) &
16+
new_unittest('test_is_windows', test_is_windows), &
17+
new_unittest('test_null_device', test_null_device) &
1718
]
1819
end subroutine collect_suite
1920

@@ -38,6 +39,26 @@ subroutine test_is_windows(error)
3839

3940
end subroutine test_is_windows
4041

42+
!> Test that the null_device is valid by writing something to it
43+
subroutine test_null_device(error)
44+
type(error_type), allocatable, intent(out) :: error
45+
integer :: unit, ios
46+
character(len=512) :: iomsg
47+
48+
! Try opening the null device for writing
49+
open(newunit=unit, file=null_device(), status='old', action='write', iostat=ios, iomsg=iomsg)
50+
call check(error, ios==0, 'Cannot open null_device unit: '//trim(iomsg))
51+
if (allocated(error)) return
52+
53+
write(unit, *, iostat=ios, iomsg=iomsg) 'Hello, World!'
54+
call check(error, ios==0, 'Cannot write to null_device unit: '//trim(iomsg))
55+
if (allocated(error)) return
56+
57+
close(unit, iostat=ios, iomsg=iomsg)
58+
call check(error, ios==0, 'Cannot close null_device unit: '//trim(iomsg))
59+
if (allocated(error)) return
60+
61+
end subroutine test_null_device
4162

4263
end module test_os
4364

0 commit comments

Comments
 (0)