11module compiler_test
2- use vegetables, only: result_t, test_item_t, describe, it, assert_equals
2+ ! ! Test compiler conformance with each scenario in which the Fortran 2018
3+ ! ! standard mandates type finalization.
4+ use veggies, only: result_t, test_item_t, describe, it, assert_equals, assert_that
35 implicit none
46
57 private
@@ -54,7 +56,8 @@ subroutine count_finalizations(self)
5456 end subroutine
5557
5658 function check_lhs_object () result(result_)
57- ! ! Verify Fortran 2018 clause 7.5.6.3, paragraph 1 behavior: "not an unallocated allocatable variable"
59+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
60+ ! ! "not an unallocated allocatable variable"
5861 type (object_t) lhs, rhs
5962 type (result_t) result_
6063 integer initial_tally
@@ -68,7 +71,8 @@ function check_lhs_object() result(result_)
6871 end function
6972
7073 function check_allocated_allocatable_lhs () result(result_)
71- ! ! Verify Fortran 2018 clause 7.5.6.3, paragraph 1 behavior: "allocated allocatable variable"
74+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
75+ ! ! "allocated allocatable variable"
7276 type (object_t), allocatable :: lhs
7377 type (object_t) rhs
7478 type (result_t) result_
@@ -84,7 +88,8 @@ function check_allocated_allocatable_lhs() result(result_)
8488 end function
8589
8690 function check_target_deallocation () result(result_)
87- ! ! Verify Fortran 2018 clause 7.5.6.3, paragraph 2 behavior: "pointer is deallocated"
91+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2 behavior:
92+ ! ! "pointer is deallocated"
8893 type (object_t), pointer :: object_ptr = > null ()
8994 type (result_t) result_
9095 integer initial_tally
@@ -98,7 +103,7 @@ function check_target_deallocation() result(result_)
98103 end function
99104
100105 function check_allocatable_component_finalization () result(result_)
101- ! ! Tests 7.5.6.3, para. 2 ("allocatable entity is deallocated")
106+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, para. 2 ("allocatable entity is deallocated")
102107 ! ! + 9.7.3.2, para. 6 ("INTENT(OUT) allocatable dummy argument is deallocated")
103108 type (wrapper_t), allocatable :: wrapper
104109 type (result_t) result_
@@ -124,7 +129,8 @@ subroutine finalize_intent_out_component(output)
124129 end function
125130
126131 function check_finalize_on_deallocate () result(result_)
127- ! ! Tests 7.5.6.3, paragraph 2: "allocatable entity is deallocated"
132+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2:
133+ ! ! "allocatable entity is deallocated"
128134 type (object_t), allocatable :: object
129135 type (result_t) result_
130136 integer initial_tally
@@ -139,7 +145,8 @@ function check_finalize_on_deallocate() result(result_)
139145 end function
140146
141147 function check_finalize_on_end () result(result_)
142- ! ! Tests 7.5.6.3, paragraph 3: "before return or END statement"
148+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 3:
149+ ! ! "before return or END statement"
143150 type (result_t) result_
144151 integer initial_tally
145152
@@ -159,7 +166,8 @@ subroutine finalize_on_end_subroutine()
159166 end function
160167
161168 function check_block_finalization () result(result_)
162- ! ! Tests 7.5.6.3, paragraph 4: "termination of the BLOCK construct"
169+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 4:
170+ ! ! "termination of the BLOCK construct"
163171 type (result_t) result_
164172 integer initial_tally
165173
@@ -174,7 +182,8 @@ function check_block_finalization() result(result_)
174182 end function
175183
176184 function check_rhs_function_reference () result(result_)
177- ! ! Verify Fortran 2018 clause 7.5.6.3, paragraph 5 behavior: "nonpointer function result"
185+ ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 5 behavior:
186+ ! ! "nonpointer function result"
178187 type (object_t), allocatable :: object
179188 type (result_t) result_
180189 integer initial_tally
@@ -187,27 +196,25 @@ function check_rhs_function_reference() result(result_)
187196 end function
188197
189198 function check_specification_expression () result(result_)
190- ! ! Tests 7.5.6.3, paragraph 6: "specification expression function result"
199+ ! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 6:
200+ ! ! "specification expression function result"
191201 type (result_t) result_
192- integer initial_tally
193-
194- initial_tally = finalizations
195- call finalize_specification_expression
196- associate(delta = > finalizations - initial_tally)
197- result_ = assert_equals(1 , delta)
198- end associate
199-
200- contains
201-
202- subroutine finalize_specification_expression
203- character (len= size ([object_t(dummy= this_image())])) :: string ! Finalizes RHS function reference
204- string = " "
205- end subroutine
202+ integer exit_status
203+ logical error_termination_occurred
204+
205+ call execute_command_line( &
206+ command = " fpm run --example specification_expression_finalization > /dev/null 2>&1" , &
207+ wait = .true. , &
208+ exitstat = exit_status &
209+ )
210+ error_termination_occurred = exit_status /= 0
211+ result_ = assert_that(error_termination_occurred)
206212
207213 end function
208214
209215 function check_intent_out_finalization () result(result_)
210- ! ! Tests 7.5.6.3, paragraph 7: "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
216+ ! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 7:
217+ ! ! "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
211218 type (result_t) result_
212219 type (object_t) object
213220 integer initial_tally
0 commit comments