Skip to content

Commit 4336ee5

Browse files
committed
feat(assertion): assert with assertion_diagnosis_t
For cases wherein Julienne's defined operations prove insufficient for writing a test_dignosis_t expression, this commit adds an assert_with_association_diagnosis specific procedure supporting the call_julienne_assert generic interface. The new procedure facilitates user-customized assertion diagnoses such as call_julienne_assert(assertion_diagnosis_t(allocated(a), "...")) This commit also adds a corresponding unit test.
1 parent 4e06c47 commit 4336ee5

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/julienne/julienne_assertion_diagnosis_s.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@
2020
call assert_library_assert(test_diagnosis%test_passed_, diagnostics_string)
2121
end procedure
2222

23+
module procedure assert_with_assertion_diagnosis
24+
character(len=:), allocatable :: diagnostics_string
25+
diagnostics_string = assertion_diagnosis%diagnostics_string_
26+
if (present(file)) diagnostics_string = diagnostics_string // " in file " // file
27+
if (present(line)) diagnostics_string = diagnostics_string // " at line " // string_t(line)
28+
call assert_library_assert(assertion_diagnosis%test_passed_, diagnostics_string)
29+
end procedure
30+
2331
end submodule

src/julienne/julienne_test_diagnosis_m.F90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ pure module subroutine julienne_assert(test_diagnosis, file, line)
8181
integer, intent(in), optional :: line
8282
end subroutine
8383

84+
pure module subroutine assert_with_assertion_diagnosis(assertion_diagnosis, file, line)
85+
implicit none
86+
type(assertion_diagnosis_t), intent(in) :: assertion_diagnosis
87+
character(len=*), intent(in), optional :: file
88+
integer, intent(in), optional :: line
89+
end subroutine
90+
8491
end interface
8592

8693
interface operator(.all.)

test/assert_test_m.F90

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module assert_test_m
88
!! Test Julienne's assert generic interface
99

1010
use julienne_m, only : &
11-
call_julienne_assert &
11+
assertion_diagnosis_t &
12+
,call_julienne_assert &
1213
,test_diagnosis_t &
1314
,test_t &
1415
,test_description_t &
@@ -40,7 +41,8 @@ function results() result(test_results)
4041
type(test_result_t), allocatable :: test_results(:)
4142

4243
associate(descriptions => [ &
43-
test_description_t("invocation via macro with a test_diagnosis_t expression", check_macro_with_expression) &
44+
test_description_t("invocation via macro with a test_diagnosis_t expression", check_macro_with_expression) &
45+
,test_description_t("invocation via macro with an assertion_diagnosis_t argument", check_macro_with_assertion_diagnosis) &
4446
])
4547
associate(substring_in_subject => index(subject(), test_description_substring) /= 0)
4648
associate(substring_in_assertion_diagnosis => descriptions%contains_text(test_description_substring))
@@ -61,10 +63,12 @@ function results() result(test_results)
6163
type(test_result_t), allocatable :: test_results(:)
6264
type(test_description_t), allocatable :: descriptions(:)
6365
procedure(diagnosis_function_i), pointer :: &
64-
check_macro_with_expression_ptr => check_macro_with_expression
66+
check_macro_with_expression_ptr => check_macro_with_expression &
67+
check_macro_with_assertion_diagnosis_ptr => check_macro_with_assertion_diagnosis
6568

6669
descriptions = [ &
67-
test_description_t("invocation via macro with a test_diagnosis_t expression", check_macro_with_expression_ptr) &
70+
test_description_t("invocation via macro with a test_diagnosis_t expression", check_macro_with_expression_ptr) &
71+
,test_description_t("invocation via macro with an assertion_diagnosis_t argument", check_macro_with_assertion_diagnosis_ptr) &
6872
]
6973

7074
block
@@ -87,4 +91,10 @@ function check_macro_with_expression() result(test_diagnosis)
8791
test_diagnosis = test_diagnosis_t(.true., "")
8892
end function
8993

94+
function check_macro_with_assertion_diagnosis() result(test_diagnosis)
95+
type(test_diagnosis_t) test_diagnosis
96+
call_julienne_assert(assertion_diagnosis_t( success=.true., diagnostics_string="unexpected test failure"))
97+
test_diagnosis = test_diagnosis_t(.true., "")
98+
end function
99+
90100
end module assert_test_m

0 commit comments

Comments
 (0)