Skip to content
4 changes: 2 additions & 2 deletions src/julienne/julienne_multi_image_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module subroutine internal_co_sum_integer(a, result_image)
integer, intent(in), optional :: result_image
end subroutine

module subroutine internal_error_stop(stop_code_char)
module pure subroutine internal_error_stop(stop_code_char)
implicit none
character(len=*), intent(in) :: stop_code_char
end subroutine
Expand Down Expand Up @@ -78,7 +78,7 @@ subroutine julienne_co_sum_integer_interface(a, result_image)
procedure(julienne_co_sum_integer_interface), pointer :: julienne_co_sum_integer

abstract interface
subroutine julienne_error_stop_interface(stop_code_char)
pure subroutine julienne_error_stop_interface(stop_code_char)
implicit none
character(len=*), intent(in) :: stop_code_char
end subroutine
Expand Down
21 changes: 21 additions & 0 deletions src/julienne/julienne_stop_and_print_m.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
! Copyright (c), The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

module julienne_stop_and_print_m
!! Define a pure subroutine that terminates with an ERROR STOP message from a string_t
use julienne_string_m, only : string_t
Comment thread
rouson marked this conversation as resolved.
Resolved
use julienne_multi_image_m, only : internal_error_stop
implicit none

private
public :: stop_and_print

contains

pure subroutine stop_and_print(message)
implicit none
type(string_t), intent(in) :: message
call internal_error_stop(message%string())
end subroutine

end module
4 changes: 3 additions & 1 deletion src/julienne/julienne_test_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module julienne_test_m
type, abstract :: test_t
!! Facilitate testing and test reporting

integer :: dummy = 0 ! this is to ensure the type is default-initialized, to eliminate warnings

contains
procedure(subject_interface), nopass, deferred :: subject
procedure(results_interface), nopass, deferred :: results
Expand Down Expand Up @@ -61,4 +63,4 @@ module subroutine report(test, passes, tests, skips)

end interface

end module julienne_test_m
end module julienne_test_m
1 change: 1 addition & 0 deletions src/julienne_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module julienne_m
use julienne_file_m, only : file_t
use julienne_formats_m, only : separated_values, csv
use julienne_github_ci_m, only : github_ci
use julienne_stop_and_print_m, only : stop_and_print
use julienne_string_m, only : string_t, array_of_strings &
,operator(.cat.) &
,operator(.csv.) &
Expand Down
2 changes: 1 addition & 1 deletion test/modules/multi_image_test_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ subroutine julienne_callback_co_sum_integer(a, result_image)
# endif
end subroutine

subroutine julienne_callback_error_stop(stop_code_char)
pure subroutine julienne_callback_error_stop(stop_code_char)
implicit none
character(len=*), intent(in) :: stop_code_char

Expand Down
12 changes: 6 additions & 6 deletions test/modules/test_description_test_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ function check_constructors_match() result(test_diagnosis)

test_diagnosis = test_diagnosis_t( &
test_passed = test_description_t("foo", tautology_ptr) == test_description_t(string_t("foo"), tautology_ptr) &
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t(string_t("foo"), tautology_ptr)'&
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t(string_t("foo"), tautology_ptr)' &
)
test_diagnosis = test_diagnosis_t( &
test_passed = .not. (test_description_t("foo", tautology_ptr) == test_description_t("foo")) &
,diagnostics_string= 'test_description_t("foo", tautology_ptr) == test_description_t("foo")'&
,diagnostics_string= 'test_description_t("foo", tautology_ptr) == test_description_t("foo")' &
)
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_diagnosis = test_diagnosis .also. test_diagnosis_t( &
Expand All @@ -69,19 +69,19 @@ function check_constructors_match() result(test_diagnosis)
#endif
test_diagnosis = test_diagnosis .also. test_diagnosis_t( &
test_passed = test_description_t("foo", tautology_ptr) == test_description_t("foo", usher(tautology)) &
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t("foo", usher(tautology))'&
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t("foo", usher(tautology))' &
)
test_diagnosis = test_diagnosis .also. test_diagnosis_t( &
test_passed = test_description_t("foo", tautology_ptr) == test_description_t("foo", c_funloc(tautology_ptr)) &
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t("foo", c_funloc(tautology))'&
,diagnostics_string= 'test_description_t("foo", tautology_ptr) /= test_description_t("foo", c_funloc(tautology))' &
)
test_diagnosis = test_diagnosis .also. test_diagnosis_t( &
test_passed = test_description_t(string_t("foo"), tautology_ptr) == test_description_t(string_t("foo"), usher(tautology)) &
,diagnostics_string= 'test_description_t(string_t("foo"), tautology_ptr) /= test_description_t(string_t("foo"), usher(tautology))'&
,diagnostics_string= 'test_description_t(string_t("foo"), tautology_ptr) /= test_description_t(string_t("foo"), usher(tautology))' &
)
test_diagnosis = test_diagnosis .also. test_diagnosis_t( &
test_passed = test_description_t(string_t("foo"), tautology_ptr) == test_description_t(string_t("foo"), c_funloc(tautology_ptr)) &
,diagnostics_string= 'test_description_t(string_t("foo"), tautology_ptr) /= test_description_t(string_t("foo"), c_funloc(tautology))'&
,diagnostics_string= 'test_description_t(string_t("foo"), tautology_ptr) /= test_description_t(string_t("foo"), c_funloc(tautology))' &
)
contains
type(test_diagnosis_t) function tautology()
Expand Down
38 changes: 38 additions & 0 deletions test/test_stop_and_print.F90
Comment thread
rouson marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
! Copyright (c) 2024-2025, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "julienne-assert-macros.h"
#include "language-support.F90"

program stop_and_print_in_pure_procedure
!! Conditionally test printing via error termination inside a pure procedure
use julienne_m, only : command_line_t, string_t, operator(.csv.), stop_and_print
implicit none

#if HAVE_MULTI_IMAGE_SUPPORT
associate(command_line => command_line_t(), me => this_image())
#else
associate(command_line => command_line_t(), me => 1)
#endif
if (.not. command_line%argument_present([character(len=len("--help"))::"--help","-h"])) then
#if TEST_INTENTIONAL_FAILURE && ASSERTIONS
if (me==1) print '(a)', new_line('') // 'Test the intentional failure of stop_and_print in a pure procedure: ' // new_line('')
call pure_subroutine
#else
if (me==1) print '(a)', &
new_line('') // &
'Skipping the test in ' // __FILE__ // '.' // new_line('') // &
'Add the following to your fpm command to test the stop_and_print: --flag "-DASSERTIONS -DTEST_INTENTIONAL_FAILURE"' // &
new_line('')
#endif
end if
end associate

contains

pure subroutine pure_subroutine
integer, parameter :: array(*) = [1,2,3,4]
call stop_and_print("array = " // .csv. string_t(array))
end subroutine

end program
Loading