Skip to content

Commit

Permalink
Update prif_error_stop to use quiet arg. Update tests to
Browse files Browse the repository at this point in the history
use quiet=false so that the current testing strategy can pass.
However, these tests will likely be removed anyway as the
testing strategy is fragile
  • Loading branch information
ktras committed Sep 17, 2024
1 parent 56507cc commit 014acc3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions example/support-test/error_stop_with_integer_code.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ program error_stop_with_integer_code
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool
logical(kind=c_bool), parameter :: true = .true._c_bool

call prif_init(init_exit_code)
call prif_error_stop(quiet=false, stop_code_int=expected_error_stop_code) ! a prif_error_stop unit test passes if this line executes error termination
call prif_stop(quiet=false) ! a prif_error_stop unit tests fails if this line runs
call prif_error_stop(quiet=true, stop_code_int=expected_error_stop_code) ! a prif_error_stop unit test passes if this line executes error termination
call prif_stop(quiet=true) ! a prif_error_stop unit tests fails if this line runs
end program
6 changes: 3 additions & 3 deletions example/support-test/error_stop_with_no_code.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ program error_stop_with_no_code
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool
logical(kind=c_bool), parameter :: true = .true._c_bool

call prif_init(init_exit_code)
call prif_error_stop(quiet=false) ! a prif_error_stop unit test passes if this line correctly executes error termination
call prif_stop(quiet=false) ! a prif_error_stop unit test fails if this line runs
call prif_error_stop(quiet=true) ! a prif_error_stop unit test passes if this line correctly executes error termination
call prif_stop(quiet=true) ! a prif_error_stop unit test fails if this line runs

end program
38 changes: 20 additions & 18 deletions src/caffeine/program_termination_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,48 @@ end subroutine prif_stop_character
end procedure prif_stop

module procedure prif_error_stop

!TODO: deal with argument `quiet`
if (present(stop_code_char)) then
call prif_error_stop_character(stop_code_char)
call prif_error_stop_character(quiet, stop_code_char)
else if (present(stop_code_int)) then
call prif_error_stop_integer(stop_code_int)
call prif_error_stop_integer(quiet, stop_code_int)
else
call prif_error_stop_integer()
call prif_error_stop_integer(quiet)
end if
end procedure prif_error_stop

subroutine prif_error_stop_character(stop_code)
subroutine prif_error_stop_character(quiet, stop_code)
!! stop all images and provide the stop_code as the process exit status
logical(c_bool), intent(in) :: quiet
character(len=*), intent(in) :: stop_code

write(error_unit, *) stop_code
flush error_unit
if (.not. quiet) then
write(error_unit, *) stop_code
flush error_unit
end if

call caf_decaffeinate(1_c_int) ! does not return
end subroutine

subroutine prif_error_stop_integer(stop_code)
subroutine prif_error_stop_integer(quiet, stop_code)
!! stop all images and provide the stop_code, or 1 if not present, as the process exit status
logical(c_bool), intent(in) :: quiet
integer(c_int), intent(in), optional :: stop_code
integer(c_int) :: exit_code

! TODO: Resolve test issue - writing to the error_unit, which is the semantics of PRIF
! breaks the current testing strategy for `prif_error_stop`
! We plan to change the testing strategy anyway, so once this is done, need to comment back
! in the code below related to the error_unit
if (present(stop_code)) then
! write(error_unit) "ERROR STOP ", stop_code
if (.not.quiet) then
write(error_unit) "ERROR STOP ", stop_code
flush error_unit
end if
exit_code = stop_code
else
! write(error_unit) "ERROR STOP"
else
if (.not.quiet) then
write(error_unit) "ERROR STOP"
flush error_unit
end if
exit_code = 1_c_int
end if

! flush error_unit

call caf_decaffeinate(exit_code) ! does not return
end subroutine

Expand Down

0 comments on commit 014acc3

Please sign in to comment.