The ParaMonte Documentation Website
Current view: top level - kernel/tests - Test_System_mod.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 191 191 100.0 %
Date: 2021-01-08 13:07:16 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!
       4             : !!!!   MIT License
       5             : !!!!
       6             : !!!!   ParaMonte: plain powerful parallel Monte Carlo library.
       7             : !!!!
       8             : !!!!   Copyright (C) 2012-present, The Computational Data Science Lab
       9             : !!!!
      10             : !!!!   This file is part of the ParaMonte library.
      11             : !!!!
      12             : !!!!   Permission is hereby granted, free of charge, to any person obtaining a 
      13             : !!!!   copy of this software and associated documentation files (the "Software"), 
      14             : !!!!   to deal in the Software without restriction, including without limitation 
      15             : !!!!   the rights to use, copy, modify, merge, publish, distribute, sublicense, 
      16             : !!!!   and/or sell copies of the Software, and to permit persons to whom the 
      17             : !!!!   Software is furnished to do so, subject to the following conditions:
      18             : !!!!
      19             : !!!!   The above copyright notice and this permission notice shall be 
      20             : !!!!   included in all copies or substantial portions of the Software.
      21             : !!!!
      22             : !!!!   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
      23             : !!!!   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
      24             : !!!!   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
      25             : !!!!   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
      26             : !!!!   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
      27             : !!!!   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
      28             : !!!!   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      29             : !!!!
      30             : !!!!   ACKNOWLEDGMENT
      31             : !!!!
      32             : !!!!   ParaMonte is an honor-ware and its currency is acknowledgment and citations.
      33             : !!!!   As per the ParaMonte library license agreement terms, if you use any parts of 
      34             : !!!!   this library for any purposes, kindly acknowledge the use of ParaMonte in your 
      35             : !!!!   work (education/research/industry/development/...) by citing the ParaMonte 
      36             : !!!!   library as described on this page:
      37             : !!!!
      38             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
      39             : !!!!
      40             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      41             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      42             : 
      43             : !>  \brief This module contains tests of the module [System_mod](@ref system_mod).
      44             : !>  \author Amir Shahmoradi
      45             : 
      46             : module Test_System_mod
      47             : 
      48             :     use System_mod
      49             :     use Test_mod, only: Test_type
      50             :     implicit none
      51             : 
      52             :     private
      53             :     public :: test_System
      54             : 
      55             :     type(Test_type) :: Test
      56             : 
      57             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      58             : 
      59             : contains
      60             : 
      61             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      62             : 
      63           3 :     subroutine test_System()
      64             : 
      65             :         implicit none
      66             : 
      67             :         ! On Windows subsystem for Linux, various runtime errors arise with the following tests, in particular, with 
      68             :         ! test_SysCmd_type_1 and test_SystemInfo_type_1 with such error messages as the following:
      69             :         !
      70             :         !   Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
      71             :         !
      72             :         ! Therefore, these tests might be only enabled for code-coverage and instrumentation purposes.
      73             :         !
      74             :         ! See: https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-execute-command-line-runtime-error-depends-on-memory/m-p/1168196#M145090
      75             : 
      76           3 :         Test = Test_type(moduleName=MODULE_NAME)
      77           3 :         call Test%run(test_sleep_1, "test_sleep_1")
      78           3 :         call Test%run(test_OS_type_1, "test_OS_type_1")
      79           3 :         call Test%run(test_OS_type_2, "test_OS_type_2")
      80           3 :         call Test%run(test_OS_type_3, "test_OS_type_3")
      81           3 :         call Test%run(test_copyFile_1, "test_copyFile_1")
      82           3 :         call Test%run(test_removeFile_1, "test_removeFile_1")
      83           3 :         call Test%run(test_removeFile_2, "test_removeFile_2")
      84           3 :         call Test%run(test_executeCmd_1, "test_executeCmd_1")
      85           3 :         call Test%run(test_executeCmd_2, "test_executeCmd_2")
      86           3 :         call Test%run(test_EnvVar_type_1, "test_EnvVar_type_1")
      87           3 :         call Test%run(test_EnvVar_type_2, "test_EnvVar_type_2")
      88           3 :         call Test%run(test_EnvVar_type_3, "test_EnvVar_type_3")
      89           3 :         call Test%run(test_CmdArg_type_1, "test_CmdArg_type_1")
      90           3 :         call Test%run(test_SysCmd_type_1, "test_SysCmd_type_1")
      91           3 :         call Test%run(test_getSystemInfo_1, "test_getSystemInfo_1")
      92           3 :         call Test%run(test_SystemInfo_type_1, "test_SystemInfo_type_1")
      93           3 :         call Test%run(test_RandomFileName_type_1, "test_RandomFileName_type_1")
      94           3 :         call Test%finalize()
      95             : 
      96           3 :     end subroutine test_System
      97             : 
      98             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      99             : 
     100           3 :     function test_sleep_1() result(assertion)
     101           3 :         use Constants_mod, only: RK
     102             :         use Err_mod, only: Err_type
     103             :         implicit none
     104             :         logical         :: assertion
     105           3 :         type(Err_type)  :: Err
     106           3 :         call sleep(0.1_RK, Err)
     107           3 :         assertion = .not. Err%occurred
     108           3 :     end function test_sleep_1
     109             : 
     110             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     111             : 
     112           3 :     function test_SystemInfo_type_1() result(assertion)
     113             :         implicit none
     114             :         logical                 :: assertion
     115           3 :         type(SystemInfo_type)   :: SystemInfo
     116           3 :         assertion = .true.
     117           3 :         SystemInfo = SystemInfo_type(pid = Test%Image%id)
     118           3 :         assertion = .not. SystemInfo%Err%occurred .and. allocated(SystemInfo%Records) .and. size(SystemInfo%Records) > 0
     119         105 :     end function test_SystemInfo_type_1
     120             : 
     121             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     122             : 
     123             :     !> \brief
     124             :     !> Test whether environmental variables can be successfully queried.
     125             :     !> 
     126             :     !> \todo
     127             :     !> This test needs further improvements in the future. See comments in the body of the test.
     128           3 :     function test_EnvVar_type_1() result(assertion)
     129             : 
     130           3 :         use String_mod, only: num2str
     131             :         implicit none
     132             :         logical                 :: assertion
     133           3 :         type(EnvVar_type)       :: EnvVar
     134           3 :         assertion = .true.
     135             : 
     136             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     137             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     138             : 
     139           3 :         EnvVar%name = ""
     140           3 :         call EnvVar%get(EnvVar%name,EnvVar%value,EnvVar%length,EnvVar%Err)
     141             :         !assertion = EnvVar%Err%occurred
     142             : 
     143           3 :     end function test_EnvVar_type_1
     144             : 
     145             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     146             : 
     147             :     !> \brief
     148             :     !> Test whether environmental variables can be successfully queried.
     149             :     !> 
     150             :     !> \todo
     151             :     !> This test needs further improvements in the future. See comments in the body of the test.
     152           3 :     function test_EnvVar_type_2() result(assertion)
     153             : 
     154           3 :         use String_mod, only: num2str
     155             :         implicit none
     156             :         logical                 :: assertion
     157           3 :         type(EnvVar_type)       :: EnvVar
     158           3 :         assertion = .true.
     159             : 
     160             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     161             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     162             : 
     163           3 :         EnvVar%name = "OS"
     164           3 :         call EnvVar%get(EnvVar%name,EnvVar%value,EnvVar%length,EnvVar%Err)
     165             :         !assertion = .not. EnvVar%Err%occurred .and. allocated(EnvVar%name) .and. allocated(EnvVar%value)
     166             : 
     167             :         !if (Test%isDebugMode .and. .not. assertion) then
     168             :         !! LCOV_EXCL_START
     169             :         !    write(Test%outputUnit,"(2A)")
     170             :         !    write(Test%outputUnit,"(2A)")   "EnvVar%name     : ", EnvVar%name
     171             :         !    write(Test%outputUnit,"(2A)")   "EnvVar%value    : ", EnvVar%value
     172             :         !    write(Test%outputUnit,"(2A)")   "EnvVar%length   : ", num2str(EnvVar%length)
     173             :         !    write(Test%outputUnit,"(2A)")
     174             :         !end if
     175             :         !! LCOV_EXCL_STOP
     176             : 
     177           3 :     end function test_EnvVar_type_2
     178             : 
     179             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     180             : 
     181             :     !> \brief
     182             :     !> Test whether environmental variables can be successfully queried.
     183             :     !> 
     184             :     !> \todo
     185             :     !> This test needs further improvements in the future. See comments in the body of the test.
     186           3 :     function test_EnvVar_type_3() result(assertion)
     187             : 
     188           3 :         use String_mod, only: num2str
     189             :         implicit none
     190             :         logical                 :: assertion
     191           3 :         type(EnvVar_type)       :: EnvVar
     192           3 :         assertion = .true.
     193             : 
     194             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     195             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     196             : 
     197           3 :         EnvVar%name = "OS"
     198           3 :         call EnvVar%get(EnvVar%name, EnvVar%value, Err = EnvVar%Err)
     199             :         !assertion = .not. EnvVar%Err%occurred .and. allocated(EnvVar%name) .and. allocated(EnvVar%value)
     200             : 
     201           3 :     end function test_EnvVar_type_3
     202             : 
     203             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     204             : 
     205             :     !> \brief
     206             :     !> Test whether input command line arguments can be successfully retrieved.
     207             :     !> 
     208             :     !> \todo
     209             :     !> This test needs further improvements in the future. See comments in the body of the test.
     210           3 :     function test_CmdArg_type_1() result(assertion)
     211             : 
     212           3 :         use String_mod, only: num2str
     213             :         implicit none
     214             :        !integer                 :: i
     215             :         logical                 :: assertion
     216           3 :         type(CmdArg_type)       :: CmdArg
     217           3 :         assertion = .true.
     218             : 
     219             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     220             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     221             : 
     222           3 :         call CmdArg%query()
     223           3 :         assertion = .not. CmdArg%Err%occurred
     224             :         !if (.not. assertion) return
     225             : 
     226             :         !if (Test%isDebugMode .and. .not. assertion) then
     227             :         !! LCOV_EXCL_START
     228             :         !    write(Test%outputUnit,"(2A)")
     229             :         !    write(Test%outputUnit,"(2A)")   "CmdArg%cmd      : ", CmdArg%cmd
     230             :         !    write(Test%outputUnit,"(2A)")   "CmdArg%count    : ", num2str(CmdArg%count)
     231             :         !    write(Test%outputUnit,      "(*('CmdArg%slash    : ', 2A))") (CmdArg%Arg(i)%record, new_line('a'), i=1,CmdArg%count)
     232             :         !    write(Test%outputUnit,"(2A)")
     233             :         !end if
     234             :         !! LCOV_EXCL_STOP
     235             : 
     236           6 :     end function test_CmdArg_type_1
     237             : 
     238             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     239             : 
     240             :     !> \brief
     241             :     !> Query Shell first and then OS to ensure caching the Shell query results work correctly.
     242             :     !> 
     243             :     !> \todo
     244             :     !> This test needs further improvements in the future. See comments in the body of the test.
     245           3 :     function test_OS_type_1() result(assertion)
     246             : 
     247           3 :         use String_mod, only: log2str
     248             :         implicit none
     249             :         logical                 :: assertion
     250           3 :         type(OS_type)           :: OS
     251             : 
     252           3 :         assertion = .true.
     253             : 
     254             : #if defined CODECOV_ENABLED
     255           3 :         mv_osCacheActivated = .false.
     256           3 :         mv_shCacheActivated = .false.
     257             : #endif
     258             : 
     259             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     260             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     261             : 
     262           3 :         call OS%query()
     263             :         !assertion = .not. OS%Err%occurred .and. .not. OS%Shell%Err%occurred
     264             :         !if (.not. assertion) return
     265             : 
     266             :         !if (Test%isDebugMode .and. .not. assertion) then
     267             :         !! LCOV_EXCL_START
     268             :         !    write(Test%outputUnit,"(2A)")
     269             :         !    write(Test%outputUnit,"(2A)")   "OS%name     : ", OS%name
     270             :         !    write(Test%outputUnit,"(2A)")   "OS%slash    : ", OS%slash
     271             :         !    write(Test%outputUnit,"(2A)")   "OS%isWindows: ", log2str(OS%isWindows)
     272             :         !    write(Test%outputUnit,"(2A)")
     273             :         !end if
     274             :         !! LCOV_EXCL_STOP
     275             : 
     276           3 :     end function test_OS_type_1
     277             : 
     278             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     279             : 
     280             :     !> \brief
     281             :     !> Query Shell first and then OS to ensure caching the Shell query results work correctly.
     282             :     !> 
     283             :     !> \todo
     284             :     !> This test needs further improvements in the future. See comments in the body of the test.
     285           3 :     function test_OS_type_2() result(assertion)
     286             : 
     287           3 :         use String_mod, only: log2str, getLowerCase
     288             :         implicit none
     289             :         logical                 :: assertion
     290           3 :         type(OS_type)           :: OS
     291             : 
     292           3 :         assertion = .true.
     293             : 
     294             : #if defined CODECOV_ENABLED
     295           3 :         mv_osCacheActivated = .false.
     296           3 :         mv_shCacheActivated = .false.
     297             : #endif
     298             : 
     299             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     300             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     301             : 
     302           3 :         call OS%Shell%query()
     303           3 :         call queryRuntimeShell(OS%Shell)
     304             :         !assertion = assertion .and. .not. OS%Shell%Err%occurred
     305             : 
     306             :         !if (Test%isDebugMode .and. .not. assertion) then
     307             :         !! LCOV_EXCL_START
     308             :         !    write(Test%outputUnit,"(2A)")
     309             :         !    write(Test%outputUnit,"(2A)")   "OS%name           : ", OS%name
     310             :         !    write(Test%outputUnit,"(2A)")   "OS%slash          : ", OS%slash
     311             :         !    write(Test%outputUnit,"(2A)")   "OS%isWindows      : ", log2str(OS%isWindows)
     312             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%name     : ", OS%Shell%name
     313             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%slash    : ", OS%Shell%slash
     314             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%isUnix   : ", log2str(OS%Shell%isUnix)
     315             :         !    write(Test%outputUnit,"(2A)")
     316             :         !end if
     317             :         !! LCOV_EXCL_STOP
     318             : 
     319             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     320             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     321             : 
     322           3 :         call OS%query()
     323             :         !assertion = assertion .and. .not. OS%Err%occurred .and. .not. OS%Shell%Err%occurred
     324             : 
     325             :         !if (Test%isDebugMode .and. .not. assertion) then
     326             :         !! LCOV_EXCL_START
     327             :         !    write(Test%outputUnit,"(2A)")
     328             :         !    write(Test%outputUnit,"(2A)")   "OS%name           : ", OS%name
     329             :         !    write(Test%outputUnit,"(2A)")   "OS%slash          : ", OS%slash
     330             :         !    write(Test%outputUnit,"(2A)")   "OS%isWindows      : ", log2str(OS%isWindows)
     331             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%name     : ", OS%Shell%name
     332             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%slash    : ", OS%Shell%slash
     333             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%isUnix   : ", log2str(OS%Shell%isUnix)
     334             :         !    write(Test%outputUnit,"(2A)")
     335             :         !end if
     336             :         ! LCOV_EXCL_STOP
     337             : 
     338           3 :     end function test_OS_type_2
     339             : 
     340             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     341             : 
     342             :     !> \brief
     343             :     !> Query OS first without shell query and then query OS with shell. 
     344             :     !> This will test the remaining uncovered cached conditions in `queryOS()`.
     345             :     !> 
     346             :     !> \todo
     347             :     !> This test needs further improvements in the future. See comments in the body of the test.
     348           3 :     function test_OS_type_3() result(assertion)
     349             : 
     350           3 :         use String_mod, only: log2str, getLowerCase
     351             :         implicit none
     352             :         logical                 :: assertion
     353           3 :         type(OS_type)           :: OS
     354             : 
     355           3 :         assertion = .true.
     356             : 
     357             : #if defined CODECOV_ENABLED
     358           3 :         mv_osCacheActivated = .false.
     359           3 :         mv_shCacheActivated = .false.
     360             : #endif
     361             : 
     362             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     363             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     364             : 
     365           3 :         call OS%query(shellQueryEnabled = .false.)
     366             :         !assertion = assertion .and. .not. OS%Shell%Err%occurred
     367             : 
     368             :         !if (Test%isDebugMode .and. .not. assertion) then
     369             :         !! LCOV_EXCL_START
     370             :         !    write(Test%outputUnit,"(2A)")
     371             :         !    write(Test%outputUnit,"(2A)")   "OS%name           : ", OS%name
     372             :         !    write(Test%outputUnit,"(2A)")   "OS%slash          : ", OS%slash
     373             :         !    write(Test%outputUnit,"(2A)")   "OS%isWindows      : ", log2str(OS%isWindows)
     374             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%name     : ", OS%Shell%name
     375             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%slash    : ", OS%Shell%slash
     376             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%isUnix   : ", log2str(OS%Shell%isUnix)
     377             :         !    write(Test%outputUnit,"(2A)")
     378             :         !end if
     379             :         !! LCOV_EXCL_STOP
     380             : 
     381             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     382             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     383             : 
     384           3 :         call OS%query(shellQueryEnabled = .true.)
     385             :         !assertion = assertion .and. .not. OS%Err%occurred .and. .not. OS%Shell%Err%occurred
     386             : 
     387             :         !if (Test%isDebugMode .and. .not. assertion) then
     388             :         !! LCOV_EXCL_START
     389             :         !    write(Test%outputUnit,"(2A)")
     390             :         !    write(Test%outputUnit,"(2A)")   "OS%name           : ", OS%name
     391             :         !    write(Test%outputUnit,"(2A)")   "OS%slash          : ", OS%slash
     392             :         !    write(Test%outputUnit,"(2A)")   "OS%isWindows      : ", log2str(OS%isWindows)
     393             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%name     : ", OS%Shell%name
     394             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%slash    : ", OS%Shell%slash
     395             :         !    write(Test%outputUnit,"(2A)")   "OS%Shell%isUnix   : ", log2str(OS%Shell%isUnix)
     396             :         !    write(Test%outputUnit,"(2A)")
     397             :         !end if
     398             :         ! LCOV_EXCL_STOP
     399             : 
     400           3 :     end function test_OS_type_3
     401             : 
     402             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     403             : 
     404             :     !> \brief
     405             :     !> Test the success of a SysCmd action.
     406             :     !> 
     407             :     !> \todo
     408             :     !> This test needs further improvements in the future. See comments in the body of the test.
     409           3 :     function test_SysCmd_type_1() result(assertion)
     410             : 
     411           3 :         use String_mod, only: log2str
     412             :         implicit none
     413             :         logical                 :: assertion
     414           3 :         type(SysCmd_type)       :: SysCmd
     415           3 :         type(OS_type)           :: OS
     416             : 
     417           3 :         call OS%query()
     418           3 :         assertion = .not. OS%Err%occurred
     419           3 :         if (.not. assertion) return
     420             : 
     421             :         ! No assertion evaluation below as execute_command_line() is prone to failure:
     422             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     423             :         ! The `Err` argument handles exceptions.
     424             : 
     425             : #if defined OS_IS_WINDOWS
     426             :         if (OS%Shell%isCMD .or. OS%Shell%isPowerShell) then
     427             :             SysCmd = SysCmd_type("dir > nul 2>&1", .true.)
     428             :             !assertion = .not. SysCmd%Err%occurred
     429             :             !if (.not. assertion) return
     430             :             SysCmd = SysCmd_type("dir > nul 2>&1", .false.)
     431             :             !assertion = .not. SysCmd%Err%occurred
     432             :             !if (.not. assertion) return
     433             :         end if
     434             : #endif
     435           3 :         if (OS%Shell%isUnix) then
     436           3 :             SysCmd = SysCmd_type("ls >/dev/null 2>&1", .true.)
     437             :             !assertion = .not. SysCmd%Err%occurred
     438             :             !if (.not. assertion) return
     439           3 :             SysCmd = SysCmd_type("ls >/dev/null 2>&1", .false.)
     440             :             !assertion = .not. SysCmd%Err%occurred
     441             :             !if (.not. assertion) return
     442             :         end if
     443             : 
     444           3 :     end function test_SysCmd_type_1
     445             : 
     446             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     447             : 
     448             :     !> \brief
     449             :     !> Test the success of a SysCmd action.
     450             :     !> 
     451             :     !> \todo
     452             :     !> This test needs further improvements in the future. See comments in the body of the test.
     453           3 :     function test_executeCmd_1() result(assertion)
     454             : 
     455           3 :         use String_mod, only: log2str
     456             :         implicit none
     457             :         logical                     :: assertion
     458           3 :         type(OS_type)               :: OS
     459             :         integer                     :: exitstat
     460             :         logical, parameter          :: wait = .true.
     461           3 :         character(:), allocatable   :: command
     462             : 
     463           3 :         call OS%query()
     464           3 :         assertion = .not. OS%Err%occurred
     465           3 :         if (.not. assertion) return
     466             : 
     467             : #if defined OS_IS_WINDOWS
     468             :         if (OS%Shell%isCMD .or. OS%Shell%isPowerShell) then
     469             :             command = "dir > nul 2>&1"
     470             :         end if
     471             : #endif
     472           3 :         if (OS%Shell%isUnix) then
     473           3 :             command = "ls >/dev/null 2>&1"
     474             :         end if
     475             : 
     476             :         ! No assertion evaluation here as execute_command_line() is prone to failure:
     477             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     478             :         ! The `Err` argument handles exceptions.
     479             : 
     480           3 :         call executeCmd(command,wait,exitstat,OS%Err)
     481             :         !assertion = .not. OS%Err%occurred
     482             :         !if (.not. assertion) return
     483             : 
     484           3 :     end function test_executeCmd_1
     485             : 
     486             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     487             : 
     488             :     !> \brief
     489             :     !> Test the success of a SysCmd action.
     490             :     !> 
     491             :     !> \todo
     492             :     !> This test needs further improvements in the future. See comments in the body of the test.
     493           3 :     function test_executeCmd_2() result(assertion)
     494             : 
     495           3 :         use String_mod, only: log2str
     496             :         implicit none
     497             :         logical                     :: assertion
     498           3 :         type(OS_type)               :: OS
     499           3 :         character(:), allocatable   :: command
     500             : 
     501           3 :         call OS%query()
     502           3 :         assertion = .not. OS%Err%occurred
     503           3 :         if (.not. assertion) return
     504             : 
     505             : #if defined OS_IS_WINDOWS
     506             :         if (OS%Shell%isCMD .or. OS%Shell%isPowerShell) then
     507             :             command = "dir > nul 2>&1"
     508             :         end if
     509             : #endif
     510           3 :         if (OS%Shell%isUnix) then
     511           3 :             command = "ls >/dev/null 2>&1"
     512             :         end if
     513             : 
     514             :         ! No assertion evaluation here as execute_command_line() is prone to failure:
     515             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     516             :         ! The `Err` argument handles exceptions.
     517             : 
     518           3 :         call executeCmd(command, Err = OS%Err)
     519             : 
     520           3 :     end function test_executeCmd_2
     521             : 
     522             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     523             : 
     524           3 :     function test_RandomFileName_type_1() result(assertion)
     525             : 
     526           3 :         use String_mod, only: log2str
     527             :         implicit none
     528             :         logical                     :: assertion
     529           3 :         type(RandomFileName_type)   :: RFN
     530             :         logical                     :: fileExists
     531             : 
     532           3 :         RFN = RandomFileName_type(key="test_RandomFileName_type")
     533           3 :         assertion = .not. RFN%Err%occurred
     534           3 :         if (.not. assertion) return
     535             : 
     536           3 :         inquire(file=RFN%path,exist=fileExists)
     537           3 :         assertion = assertion .and. .not. fileExists
     538           3 :         assertion = assertion .and. RFN%dir == ""
     539           3 :         assertion = assertion .and. RFN%key == "test_RandomFileName_type"  !  // "_image_" // num2str(this_image())
     540           3 :         assertion = assertion .and. RFN%ext == ".rfn"
     541             : 
     542           3 :         if (Test%isDebugMode .and. .not. assertion) then
     543             :         ! LCOV_EXCL_START
     544             :             write(Test%outputUnit,"(2A)")
     545             :             write(Test%outputUnit,"(2A)")   "RFN%path     : ", RFN%path
     546             :             write(Test%outputUnit,"(2A)")   "RFN%dir      : ", RFN%dir
     547             :             write(Test%outputUnit,"(2A)")   "RFN%key      : ", RFN%key
     548             :             write(Test%outputUnit,"(2A)")   "RFN%ext      : ", RFN%ext
     549             :             write(Test%outputUnit,"(2A)")
     550             :         end if
     551             :         ! LCOV_EXCL_STOP
     552             : 
     553           3 :     end function test_RandomFileName_type_1
     554             : 
     555             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     556             : 
     557           3 :     function test_removeFile_1() result(assertion)
     558             : 
     559           3 :         use String_mod, only: log2str
     560             :         implicit none
     561             :         logical                     :: assertion
     562           3 :         type(RandomFileName_type)   :: RFN
     563             :         logical                     :: fileExists
     564             :         integer                     :: fileUnit
     565             : 
     566           3 :         RFN = RandomFileName_type(key="test_RandomFileName_type")
     567           3 :         assertion = .not. RFN%Err%occurred
     568           3 :         if (.not. assertion) return
     569             : 
     570           3 :         open(newunit=fileUnit,file=RFN%path,status="new")
     571           3 :         close(fileUnit)
     572             : 
     573           3 :         call removeFile(path=RFN%path,Err=RFN%Err)
     574           3 :         assertion = assertion .and. .not. RFN%Err%occurred
     575           3 :         if (.not. assertion) return
     576             : 
     577           3 :         inquire(file=RFN%path,exist=fileExists)
     578           3 :         assertion = assertion .and. .not. fileExists
     579             : 
     580           3 :     end function test_removeFile_1
     581             : 
     582             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     583             : 
     584           3 :     function test_removeFile_2() result(assertion)
     585             : 
     586           3 :         use Constants_mod, only: RK
     587             :         use String_mod, only: log2str
     588             :         implicit none
     589             :         logical                     :: assertion
     590           3 :         type(RandomFileName_type)   :: RFN
     591             :         logical                     :: fileExists
     592             :         integer                     :: fileUnit
     593             : 
     594           3 :         RFN = RandomFileName_type(key="test_RandomFileName_type")
     595           3 :         assertion = .not. RFN%Err%occurred
     596           3 :         if (.not. assertion) return
     597             : 
     598           3 :         open(newunit=fileUnit,file=RFN%path,status="new")
     599           3 :         close(fileUnit)
     600             : 
     601           3 :         call removeFile(path=RFN%path)
     602           3 :         inquire(file=RFN%path,exist=fileExists)
     603           3 :         assertion = assertion .and. .not. fileExists
     604             : 
     605           3 :     end function test_removeFile_2
     606             : 
     607             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     608             : 
     609             :     !> \brief
     610             :     !> Obtain the system info without providing the cachefile name, in which case, no cache file will be generated.
     611             :     !>
     612             :     !> \todo
     613             :     !> This test needs further improvements in the future. See comments in the body of the test.
     614           3 :     function test_getSystemInfo_1() result(assertion)
     615             : 
     616           3 :         use JaggedArray_mod, only: CharVec_type
     617             :         use Err_mod, only: Err_type
     618             :         implicit none
     619             :         logical                         :: assertion
     620           3 :         type(CharVec_type), allocatable :: List(:)
     621           3 :         type(Err_type)                  :: Err
     622             : 
     623           3 :         assertion = .true.
     624             : 
     625             :         ! No assertion evaluation here as execute_command_line() is prone to failure:
     626             :         ! Fortran runtime error: EXECUTE_COMMAND_LINE: Termination status of the command-language interpreter cannot be obtained
     627             :         ! The `Err` argument handles exceptions.
     628             : 
     629           3 :         call getSystemInfo(List,Err)
     630             :         !assertion = .not. Err%occurred
     631             : 
     632         102 :     end function test_getSystemInfo_1
     633             : 
     634             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     635             : 
     636           3 :     function test_copyFile_1() result(assertion)
     637             : 
     638           3 :         use Constants_mod, only: RK
     639             :         implicit none
     640             :         logical                     :: assertion
     641           3 :         type(RandomFileName_type)   :: RFN
     642           3 :         type(OS_type)               :: OS
     643             :         logical                     :: fileExists
     644             :         integer                     :: fileUnit
     645             : 
     646           3 :         RFN = RandomFileName_type(key="test_RandomFileName_type")
     647           3 :         assertion = .not. RFN%Err%occurred
     648           3 :         if (.not. assertion) return
     649             : 
     650           3 :         open(newunit=fileUnit,file=RFN%path,status="new")
     651           3 :         close(fileUnit)
     652             : 
     653           3 :         call OS%query()
     654           3 :         assertion = .not. OS%Err%occurred
     655           3 :         if (.not. assertion) return
     656             : 
     657           3 :         call copyFile(RFN%path, RFN%path//".copy", OS%Shell%isUnix, OS%Err)
     658           3 :         assertion = .not. OS%Err%occurred
     659           3 :         if (.not. assertion) return
     660             : 
     661           3 :         inquire(file=RFN%path//".copy",exist=fileExists)
     662           3 :         assertion = assertion .and. fileExists
     663             : 
     664           3 :         call removeFile(RFN%path)
     665           3 :         inquire(file=RFN%path,exist=fileExists)
     666           3 :         assertion = assertion .and. .not. fileExists
     667             : 
     668           3 :         call removeFile(RFN%path//".copy")
     669           3 :         inquire(file=RFN%path//".copy",exist=fileExists)
     670           3 :         assertion = assertion .and. .not. fileExists
     671             : 
     672           3 :     end function test_copyFile_1
     673             : 
     674             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     675             : 
     676             : end module Test_System_mod ! LCOV_EXCL_LINE

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021