-
Notifications
You must be signed in to change notification settings - Fork 191
system: OS type query #942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+366
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
! Demonstrate usage of (non-cached) runtime OS query | ||
program example_get_runtime_os | ||
use stdlib_system, only: OS_NAME, get_runtime_os | ||
implicit none | ||
|
||
! Runtime OS detection (full inspection) | ||
print *, "Runtime OS Type: ", OS_NAME(get_runtime_os()) | ||
|
||
end program example_get_runtime_os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
! Demonstrate OS detection | ||
program example_os_type | ||
use stdlib_system, only: OS_TYPE, OS_NAME | ||
implicit none | ||
|
||
integer :: current_os | ||
|
||
! Cached OS detection | ||
current_os = OS_TYPE() | ||
print *, "Current OS Type: ", OS_NAME(current_os) | ||
|
||
end program example_os_type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ADDTEST(os) | ||
ADDTEST(sleep) | ||
ADDTEST(subprocess) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module test_os | ||
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test | ||
use stdlib_system, only: get_runtime_os, OS_WINDOWS, OS_UNKNOWN, OS_TYPE, is_windows | ||
|
||
implicit none | ||
|
||
contains | ||
|
||
!> Collect all exported unit tests | ||
subroutine collect_suite(testsuite) | ||
!> Collection of tests | ||
type(unittest_type), allocatable, intent(out) :: testsuite(:) | ||
|
||
testsuite = [ & | ||
new_unittest('test_get_runtime_os', test_get_runtime_os), & | ||
new_unittest('test_is_windows', test_is_windows) & | ||
] | ||
end subroutine collect_suite | ||
|
||
subroutine test_get_runtime_os(error) | ||
type(error_type), allocatable, intent(out) :: error | ||
integer :: os | ||
|
||
!> Get current OS | ||
os = get_runtime_os() | ||
|
||
call check(error, os /= OS_UNKNOWN, "running on an unknown/unsupported OS") | ||
|
||
end subroutine test_get_runtime_os | ||
|
||
!> If running on Windows (_WIN32 macro is defined), test that the appropriate OS flag is returned | ||
subroutine test_is_windows(error) | ||
type(error_type), allocatable, intent(out) :: error | ||
integer :: os_cached, os_runtime | ||
|
||
call check(error, OS_TYPE()==OS_WINDOWS .eqv. is_windows(), & | ||
"Cached OS type does not match _WIN32 macro presence") | ||
|
||
end subroutine test_is_windows | ||
|
||
|
||
end module test_os | ||
|
||
program tester | ||
use, intrinsic :: iso_fortran_env, only : error_unit | ||
use testdrive, only : run_testsuite, new_testsuite, testsuite_type | ||
use test_os, only : collect_suite | ||
|
||
implicit none | ||
|
||
integer :: stat, is | ||
type(testsuite_type), allocatable :: testsuites(:) | ||
character(len=*), parameter :: fmt = '("#", *(1x, a))' | ||
|
||
stat = 0 | ||
|
||
testsuites = [ & | ||
new_testsuite("os", collect_suite) & | ||
] | ||
|
||
do is = 1, size(testsuites) | ||
write(error_unit, fmt) "Testing:", testsuites(is)%name | ||
call run_testsuite(testsuites(is)%collect, error_unit, stat) | ||
end do | ||
|
||
if (stat > 0) then | ||
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!" | ||
error stop | ||
end if | ||
end program |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.