Skip to content

Commit 59da998

Browse files
committed
add tests
1 parent 2596c8c commit 59da998

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
ADDTEST(os)
12
ADDTEST(sleep)
23
ADDTEST(subprocess)

test/system/test_os.f90

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module test_os
2+
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
4+
5+
implicit none
6+
7+
contains
8+
9+
!> Collect all exported unit tests
10+
subroutine collect_suite(testsuite)
11+
!> Collection of tests
12+
type(unittest_type), allocatable, intent(out) :: testsuite(:)
13+
14+
testsuite = [ &
15+
new_unittest('test_get_runtime_os', test_get_runtime_os), &
16+
new_unittest('test_is_windows', test_is_windows) &
17+
]
18+
end subroutine collect_suite
19+
20+
subroutine test_get_runtime_os(error)
21+
type(error_type), allocatable, intent(out) :: error
22+
integer :: os
23+
24+
!> Get current OS
25+
os = get_runtime_os()
26+
27+
call check(error, os /= OS_UNKNOWN, "running on an unknown/unsupported OS")
28+
29+
end subroutine test_get_runtime_os
30+
31+
!> If running on Windows (_WIN32 macro is defined), test that the appropriate OS flag is returned
32+
subroutine test_is_windows(error)
33+
type(error_type), allocatable, intent(out) :: error
34+
integer :: os_cached, os_runtime
35+
36+
call check(error, OS_TYPE()==OS_WINDOWS .eqv. is_windows(), &
37+
"Cached OS type does not match _WIN32 macro presence")
38+
39+
end subroutine test_is_windows
40+
41+
42+
end module test_os
43+
44+
program tester
45+
use, intrinsic :: iso_fortran_env, only : error_unit
46+
use testdrive, only : run_testsuite, new_testsuite, testsuite_type
47+
use test_os, only : collect_suite
48+
49+
implicit none
50+
51+
integer :: stat, is
52+
type(testsuite_type), allocatable :: testsuites(:)
53+
character(len=*), parameter :: fmt = '("#", *(1x, a))'
54+
55+
stat = 0
56+
57+
testsuites = [ &
58+
new_testsuite("os", collect_suite) &
59+
]
60+
61+
do is = 1, size(testsuites)
62+
write(error_unit, fmt) "Testing:", testsuites(is)%name
63+
call run_testsuite(testsuites(is)%collect, error_unit, stat)
64+
end do
65+
66+
if (stat > 0) then
67+
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
68+
error stop
69+
end if
70+
end program

0 commit comments

Comments
 (0)