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 1 : 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 1 : Test = Test_type(moduleName=MODULE_NAME)
77 1 : call Test%run(test_sleep_1, "test_sleep_1")
78 1 : call Test%run(test_OS_type_1, "test_OS_type_1")
79 1 : call Test%run(test_OS_type_2, "test_OS_type_2")
80 1 : call Test%run(test_OS_type_3, "test_OS_type_3")
81 1 : call Test%run(test_copyFile_1, "test_copyFile_1")
82 1 : call Test%run(test_removeFile_1, "test_removeFile_1")
83 1 : call Test%run(test_removeFile_2, "test_removeFile_2")
84 1 : call Test%run(test_executeCmd_1, "test_executeCmd_1")
85 1 : call Test%run(test_executeCmd_2, "test_executeCmd_2")
86 1 : call Test%run(test_EnvVar_type_1, "test_EnvVar_type_1")
87 1 : call Test%run(test_EnvVar_type_2, "test_EnvVar_type_2")
88 1 : call Test%run(test_EnvVar_type_3, "test_EnvVar_type_3")
89 1 : call Test%run(test_CmdArg_type_1, "test_CmdArg_type_1")
90 1 : call Test%run(test_SysCmd_type_1, "test_SysCmd_type_1")
91 1 : call Test%run(test_getSystemInfo_1, "test_getSystemInfo_1")
92 1 : call Test%run(test_SystemInfo_type_1, "test_SystemInfo_type_1")
93 1 : call Test%run(test_RandomFileName_type_1, "test_RandomFileName_type_1")
94 1 : call Test%finalize()
95 :
96 1 : end subroutine test_System
97 :
98 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 :
100 1 : function test_sleep_1() result(assertion)
101 1 : use Constants_mod, only: RK
102 : use Err_mod, only: Err_type
103 : implicit none
104 : logical :: assertion
105 1 : type(Err_type) :: Err
106 1 : call sleep(0.1_RK, Err)
107 1 : assertion = .not. Err%occurred
108 1 : end function test_sleep_1
109 :
110 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 :
112 1 : function test_SystemInfo_type_1() result(assertion)
113 : implicit none
114 : logical :: assertion
115 1 : type(SystemInfo_type) :: SystemInfo
116 1 : assertion = .true.
117 1 : SystemInfo = SystemInfo_type(pid = Test%Image%id)
118 1 : assertion = .not. SystemInfo%Err%occurred .and. allocated(SystemInfo%Records) .and. size(SystemInfo%Records) > 0
119 35 : 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 1 : function test_EnvVar_type_1() result(assertion)
129 :
130 1 : use String_mod, only: num2str
131 : implicit none
132 : logical :: assertion
133 1 : type(EnvVar_type) :: EnvVar
134 1 : 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 1 : EnvVar%name = ""
140 1 : call EnvVar%get(EnvVar%name,EnvVar%value,EnvVar%length,EnvVar%Err)
141 : !assertion = EnvVar%Err%occurred
142 :
143 1 : 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 1 : function test_EnvVar_type_2() result(assertion)
153 :
154 1 : use String_mod, only: num2str
155 : implicit none
156 : logical :: assertion
157 1 : type(EnvVar_type) :: EnvVar
158 1 : 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 1 : EnvVar%name = "OS"
164 1 : 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 1 : 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 1 : function test_EnvVar_type_3() result(assertion)
187 :
188 1 : use String_mod, only: num2str
189 : implicit none
190 : logical :: assertion
191 1 : type(EnvVar_type) :: EnvVar
192 1 : 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 1 : EnvVar%name = "OS"
198 1 : 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 1 : 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 1 : function test_CmdArg_type_1() result(assertion)
211 :
212 1 : use String_mod, only: num2str
213 : implicit none
214 : !integer :: i
215 : logical :: assertion
216 1 : type(CmdArg_type) :: CmdArg
217 1 : 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 1 : call CmdArg%query()
223 1 : 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 2 : 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 1 : function test_OS_type_1() result(assertion)
246 :
247 1 : use String_mod, only: log2str
248 : implicit none
249 : logical :: assertion
250 1 : type(OS_type) :: OS
251 :
252 1 : assertion = .true.
253 :
254 : #if defined CODECOV_ENABLED
255 1 : mv_osCacheActivated = .false.
256 1 : 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 1 : 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 1 : 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 1 : function test_OS_type_2() result(assertion)
286 :
287 1 : use String_mod, only: log2str, getLowerCase
288 : implicit none
289 : logical :: assertion
290 1 : type(OS_type) :: OS
291 :
292 1 : assertion = .true.
293 :
294 : #if defined CODECOV_ENABLED
295 1 : mv_osCacheActivated = .false.
296 1 : 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 1 : call OS%Shell%query()
303 1 : 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 1 : 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 1 : 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 1 : function test_OS_type_3() result(assertion)
349 :
350 1 : use String_mod, only: log2str, getLowerCase
351 : implicit none
352 : logical :: assertion
353 1 : type(OS_type) :: OS
354 :
355 1 : assertion = .true.
356 :
357 : #if defined CODECOV_ENABLED
358 1 : mv_osCacheActivated = .false.
359 1 : 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 1 : 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 1 : 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 1 : 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 1 : function test_SysCmd_type_1() result(assertion)
410 :
411 1 : use String_mod, only: log2str
412 : implicit none
413 : logical :: assertion
414 1 : type(SysCmd_type) :: SysCmd
415 1 : type(OS_type) :: OS
416 :
417 1 : call OS%query()
418 1 : assertion = .not. OS%Err%occurred
419 1 : 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 1 : if (OS%Shell%isUnix) then
436 1 : SysCmd = SysCmd_type("ls >/dev/null 2>&1", .true.)
437 : !assertion = .not. SysCmd%Err%occurred
438 : !if (.not. assertion) return
439 1 : 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 1 : 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 1 : function test_executeCmd_1() result(assertion)
454 :
455 1 : use String_mod, only: log2str
456 : implicit none
457 : logical :: assertion
458 1 : type(OS_type) :: OS
459 : integer :: exitstat
460 : logical, parameter :: wait = .true.
461 1 : character(:), allocatable :: command
462 :
463 1 : call OS%query()
464 1 : assertion = .not. OS%Err%occurred
465 1 : 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 1 : if (OS%Shell%isUnix) then
473 1 : 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 1 : call executeCmd(command,wait,exitstat,OS%Err)
481 : !assertion = .not. OS%Err%occurred
482 : !if (.not. assertion) return
483 :
484 1 : 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 1 : function test_executeCmd_2() result(assertion)
494 :
495 1 : use String_mod, only: log2str
496 : implicit none
497 : logical :: assertion
498 1 : type(OS_type) :: OS
499 1 : character(:), allocatable :: command
500 :
501 1 : call OS%query()
502 1 : assertion = .not. OS%Err%occurred
503 1 : 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 1 : if (OS%Shell%isUnix) then
511 1 : 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 1 : call executeCmd(command, Err = OS%Err)
519 :
520 1 : end function test_executeCmd_2
521 :
522 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523 :
524 1 : function test_RandomFileName_type_1() result(assertion)
525 :
526 1 : use String_mod, only: log2str
527 : implicit none
528 : logical :: assertion
529 1 : type(RandomFileName_type) :: RFN
530 : logical :: fileExists
531 :
532 1 : RFN = RandomFileName_type(key="test_RandomFileName_type")
533 1 : assertion = .not. RFN%Err%occurred
534 1 : if (.not. assertion) return
535 :
536 1 : inquire(file=RFN%path,exist=fileExists)
537 1 : assertion = assertion .and. .not. fileExists
538 1 : assertion = assertion .and. RFN%dir == ""
539 1 : assertion = assertion .and. RFN%key == "test_RandomFileName_type" ! // "_image_" // num2str(this_image())
540 1 : assertion = assertion .and. RFN%ext == ".rfn"
541 :
542 1 : 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 1 : end function test_RandomFileName_type_1
554 :
555 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556 :
557 1 : function test_removeFile_1() result(assertion)
558 :
559 1 : use String_mod, only: log2str
560 : implicit none
561 : logical :: assertion
562 1 : type(RandomFileName_type) :: RFN
563 : logical :: fileExists
564 : integer :: fileUnit
565 :
566 1 : RFN = RandomFileName_type(key="test_RandomFileName_type")
567 1 : assertion = .not. RFN%Err%occurred
568 1 : if (.not. assertion) return
569 :
570 1 : open(newunit=fileUnit,file=RFN%path,status="new")
571 1 : close(fileUnit)
572 :
573 1 : call removeFile(path=RFN%path,Err=RFN%Err)
574 1 : assertion = assertion .and. .not. RFN%Err%occurred
575 1 : if (.not. assertion) return
576 :
577 1 : inquire(file=RFN%path,exist=fileExists)
578 1 : assertion = assertion .and. .not. fileExists
579 :
580 1 : end function test_removeFile_1
581 :
582 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 :
584 1 : function test_removeFile_2() result(assertion)
585 :
586 1 : use Constants_mod, only: RK
587 : use String_mod, only: log2str
588 : implicit none
589 : logical :: assertion
590 1 : type(RandomFileName_type) :: RFN
591 : logical :: fileExists
592 : integer :: fileUnit
593 :
594 1 : RFN = RandomFileName_type(key="test_RandomFileName_type")
595 1 : assertion = .not. RFN%Err%occurred
596 1 : if (.not. assertion) return
597 :
598 1 : open(newunit=fileUnit,file=RFN%path,status="new")
599 1 : close(fileUnit)
600 :
601 1 : call removeFile(path=RFN%path)
602 1 : inquire(file=RFN%path,exist=fileExists)
603 1 : assertion = assertion .and. .not. fileExists
604 :
605 1 : 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 1 : function test_getSystemInfo_1() result(assertion)
615 :
616 1 : use JaggedArray_mod, only: CharVec_type
617 : use Err_mod, only: Err_type
618 : implicit none
619 : logical :: assertion
620 1 : type(CharVec_type), allocatable :: List(:)
621 1 : type(Err_type) :: Err
622 :
623 1 : 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 1 : call getSystemInfo(List,Err)
630 : !assertion = .not. Err%occurred
631 :
632 34 : end function test_getSystemInfo_1
633 :
634 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635 :
636 1 : function test_copyFile_1() result(assertion)
637 :
638 1 : use Constants_mod, only: RK
639 : implicit none
640 : logical :: assertion
641 1 : type(RandomFileName_type) :: RFN
642 1 : type(OS_type) :: OS
643 : logical :: fileExists
644 : integer :: fileUnit
645 :
646 1 : RFN = RandomFileName_type(key="test_RandomFileName_type")
647 1 : assertion = .not. RFN%Err%occurred
648 1 : if (.not. assertion) return
649 :
650 1 : open(newunit=fileUnit,file=RFN%path,status="new")
651 1 : close(fileUnit)
652 :
653 1 : call OS%query()
654 1 : assertion = .not. OS%Err%occurred
655 1 : if (.not. assertion) return
656 :
657 1 : call copyFile(RFN%path, RFN%path//".copy", OS%Shell%isUnix, OS%Err)
658 1 : assertion = .not. OS%Err%occurred
659 1 : if (.not. assertion) return
660 :
661 1 : inquire(file=RFN%path//".copy",exist=fileExists)
662 1 : assertion = assertion .and. fileExists
663 :
664 1 : call removeFile(RFN%path)
665 1 : inquire(file=RFN%path,exist=fileExists)
666 1 : assertion = assertion .and. .not. fileExists
667 :
668 1 : call removeFile(RFN%path//".copy")
669 1 : inquire(file=RFN%path//".copy",exist=fileExists)
670 1 : assertion = assertion .and. .not. fileExists
671 :
672 1 : end function test_copyFile_1
673 :
674 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 :
676 : end module Test_System_mod ! LCOV_EXCL_LINE
|