1- module compiler_test
1+ module compiler_test_m
22 ! ! Test compiler conformance with each scenario in which the Fortran 2018
33 ! ! standard mandates type finalization.
4- use veggies, only: result_t, test_item_t, describe, it, assert_equals, assert_that
4+ use test_m, only : test_t
5+ use test_result_m, only : test_result_t
56 use iso_fortran_env, only : compiler_version
67 implicit none
78
89 private
9- public :: test_sp_smart_pointer
10+ public :: compiler_test_t
11+
12+ type, extends(test_t) :: compiler_test_t
13+ contains
14+ procedure , nopass :: subject
15+ procedure , nopass :: results
16+ end type
1017
1118 type object_t
1219 integer dummy
@@ -24,23 +31,26 @@ module compiler_test
2431
2532contains
2633
27- function test_sp_smart_pointer () result(tests)
28- type (test_item_t) tests
29-
30- tests = &
31- describe( &
32- " The compiler" , &
33- [ it(" finalizes a non-allocatable object on the LHS of an intrinsic assignment" , check_lhs_object) &
34- ,it(" finalizes an allocated allocatable LHS of an intrinsic assignment" , check_allocated_allocatable_lhs) &
35- ,it(" finalizes a target when the associated pointer is deallocated" , check_target_deallocation) &
36- ,it(" finalizes an object upon explicit deallocation" , check_finalize_on_deallocate) &
37- ,it(" finalizes a non-pointer non-allocatable object at the END statement" , check_finalize_on_end) &
38- ,it(" finalizes a non-pointer non-allocatable object at the end of a block construct" , check_block_finalization) &
39- ,it(" finalizes a function reference on the RHS of an intrinsic assignment" , check_rhs_function_reference) &
40- ,it(" finalizes a specification expression function result" , check_specification_expression) &
41- ,it(" finalizes an intent(out) derived type dummy argument" , check_intent_out_finalization) &
42- ,it(" finalizes an allocatable component object" , check_allocatable_component_finalization) &
43- ])
34+ pure function subject () result(specimen)
35+ character (len= :), allocatable :: specimen
36+ specimen = " The compiler"
37+ end function
38+
39+ function results () result(test_results)
40+ type (test_result_t), allocatable :: test_results(:)
41+
42+ test_results = [ &
43+ test_result_t(" finalizes a non-allocatable object on the LHS of an intrinsic assignment" , check_lhs_object()) &
44+ ,test_result_t(" finalizes an allocated allocatable LHS of an intrinsic assignment" , check_allocated_allocatable_lhs()) &
45+ ,test_result_t(" finalizes a target when the associated pointer is deallocated" , check_target_deallocation()) &
46+ ,test_result_t(" finalizes an object upon explicit deallocation" , check_finalize_on_deallocate()) &
47+ ,test_result_t(" finalizes a non-pointer non-allocatable object at the END statement" , check_finalize_on_end()) &
48+ ,test_result_t(" finalizes a non-pointer non-allocatable object at END BLOCK statement" , check_block_finalization()) &
49+ ,test_result_t(" finalizes a function reference on the RHS of an intrinsic assignment" , check_rhs_function_reference()) &
50+ ,test_result_t(" finalizes a specification expression function result" , check_specification_expression()) &
51+ ,test_result_t(" finalizes an intent(out) derived type dummy argument" , check_intent_out_finalization()) &
52+ ,test_result_t(" finalizes an allocatable component object" , check_allocatable_component_finalization()) &
53+ ]
4454 end function
4555
4656 function construct_object () result(object)
@@ -56,58 +66,58 @@ subroutine count_finalizations(self)
5666 self % dummy = avoid_unused_variable_warning
5767 end subroutine
5868
59- function check_lhs_object () result(result_ )
69+ function check_lhs_object () result(test_passes )
6070 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
6171 ! ! "not an unallocated allocatable variable"
6272 type (object_t) lhs, rhs
63- type (result_t) result_
73+ logical test_passes
6474 integer initial_tally
6575
6676 rhs% dummy = avoid_unused_variable_warning
6777 initial_tally = finalizations
6878 lhs = rhs ! finalizes lhs
6979 associate(delta = > finalizations - initial_tally)
70- result_ = assert_equals( 1 , delta)
80+ test_passes = delta == 1
7181 end associate
7282 end function
7383
74- function check_allocated_allocatable_lhs () result(result_ )
84+ function check_allocated_allocatable_lhs () result(test_passes )
7585 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
7686 ! ! "allocated allocatable variable"
7787 type (object_t), allocatable :: lhs
7888 type (object_t) rhs
79- type (result_t) result_
89+ logical test_passes
8090 integer initial_tally
8191
8292 rhs% dummy = avoid_unused_variable_warning
8393 initial_tally = finalizations
8494 allocate (lhs)
8595 lhs = rhs ! finalizes lhs
8696 associate(delta = > finalizations - initial_tally)
87- result_ = assert_equals( 1 , delta)
97+ test_passes = delta == 1
8898 end associate
8999 end function
90100
91- function check_target_deallocation () result(result_ )
101+ function check_target_deallocation () result(test_passes )
92102 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2 behavior:
93103 ! ! "pointer is deallocated"
94- type (object_t), pointer :: object_ptr = > null ()
95- type (result_t) result_
104+ type (object_t), pointer :: object_ptr
105+ logical test_passes
96106 integer initial_tally
97107
98108 allocate (object_ptr, source= object_t(dummy= 0 ))
99109 initial_tally = finalizations
100110 deallocate (object_ptr) ! finalizes object
101111 associate(delta = > finalizations - initial_tally)
102- result_ = assert_equals( 1 , delta)
112+ test_passes = delta == 1
103113 end associate
104114 end function
105115
106- function check_allocatable_component_finalization () result(result_ )
116+ function check_allocatable_component_finalization () result(test_passes )
107117 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, para. 2 ("allocatable entity is deallocated")
108118 ! ! + 9.7.3.2, para. 6 ("INTENT(OUT) allocatable dummy argument is deallocated")
109119 type (wrapper_t), allocatable :: wrapper
110- type (result_t) result_
120+ logical test_passes
111121 integer initial_tally
112122
113123 initial_tally = finalizations
@@ -116,7 +126,7 @@ function check_allocatable_component_finalization() result(result_)
116126 allocate (wrapper% object)
117127 call finalize_intent_out_component(wrapper)
118128 associate(delta = > finalizations - initial_tally)
119- result_ = assert_equals( 1 , delta)
129+ test_passes = delta == 1
120130 end associate
121131
122132 contains
@@ -129,32 +139,32 @@ subroutine finalize_intent_out_component(output)
129139
130140 end function
131141
132- function check_finalize_on_deallocate () result(result_ )
142+ function check_finalize_on_deallocate () result(test_passes )
133143 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2:
134144 ! ! "allocatable entity is deallocated"
135145 type (object_t), allocatable :: object
136- type (result_t) result_
146+ logical test_passes
137147 integer initial_tally
138148
139149 initial_tally = finalizations
140150 allocate (object)
141151 object% dummy = 1
142152 deallocate (object) ! finalizes object
143153 associate(final_tally = > finalizations - initial_tally)
144- result_ = assert_equals( 1 , final_tally)
154+ test_passes = final_tally == 1
145155 end associate
146156 end function
147157
148- function check_finalize_on_end () result(result_ )
158+ function check_finalize_on_end () result(test_passes )
149159 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 3:
150160 ! ! "before return or END statement"
151- type (result_t) result_
161+ logical test_passes
152162 integer initial_tally
153163
154164 initial_tally = finalizations
155165 call finalize_on_end_subroutine() ! Finalizes local_obj
156166 associate(final_tally = > finalizations - initial_tally)
157- result_ = assert_equals( 1 , final_tally)
167+ test_passes = final_tally == 1
158168 end associate
159169
160170 contains
@@ -166,10 +176,10 @@ subroutine finalize_on_end_subroutine()
166176
167177 end function
168178
169- function check_block_finalization () result(result_ )
179+ function check_block_finalization () result(test_passes )
170180 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 4:
171181 ! ! "termination of the BLOCK construct"
172- type (result_t) result_
182+ logical test_passes
173183 integer initial_tally
174184
175185 initial_tally = finalizations
@@ -178,28 +188,28 @@ function check_block_finalization() result(result_)
178188 object % dummy = avoid_unused_variable_warning
179189 end block ! Finalizes object
180190 associate(delta = > finalizations - initial_tally)
181- result_ = assert_equals( 1 , delta)
191+ test_passes = delta == 1
182192 end associate
183193 end function
184194
185- function check_rhs_function_reference () result(result_ )
195+ function check_rhs_function_reference () result(test_passes )
186196 ! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 5 behavior:
187197 ! ! "nonpointer function result"
188198 type (object_t), allocatable :: object
189- type (result_t) result_
199+ logical test_passes
190200 integer initial_tally
191201
192202 initial_tally = finalizations
193203 object = construct_object() ! finalizes object_t result
194204 associate(delta = > finalizations - initial_tally)
195- result_ = assert_equals( 1 , delta)
205+ test_passes = delta == 1
196206 end associate
197207 end function
198208
199- function check_specification_expression () result(result_ )
209+ function check_specification_expression () result(test_passes )
200210 ! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 6:
201211 ! ! "specification expression function result"
202- type (result_t) result_
212+ logical test_passes
203213 integer exit_status
204214 logical error_termination_occurred
205215
@@ -209,18 +219,20 @@ function check_specification_expression() result(result_)
209219 exitstat = exit_status &
210220 )
211221 error_termination_occurred = exit_status /= 0
212- result_ = assert_that( error_termination_occurred)
222+ test_passes = error_termination_occurred
213223
214224 contains
215225
216- pure function fpm_compiler_arguments () result(args)
226+ function fpm_compiler_arguments () result(args)
217227 character (len= :), allocatable :: args
218228
219229 associate(compiler_identity= >compiler_version())
220- if (scan (compiler_identity, " GCC " )==1 ) then
230+ if (scan (compiler_identity, " GCC" )==1 ) then
221231 args = " "
222- else if (scan (compiler_identity, " NAG Fortran " )==1 ) then
232+ else if (scan (compiler_identity, " NAG" )==1 ) then
223233 args = " --compiler nagfor --flag -fpp"
234+ else if (scan (compiler_identity, " Intel" )==1 ) then
235+ args = " --compiler ifort --flag -coarray=shared"
224236 else
225237 error stop " ----> Unrecognized compiler_version() in function fpm_compiler_arguments. <----"
226238 end if
@@ -229,18 +241,17 @@ pure function fpm_compiler_arguments() result(args)
229241
230242 end function
231243
232-
233- function check_intent_out_finalization () result(result_)
244+ function check_intent_out_finalization () result(test_passes)
234245 ! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 7:
235246 ! ! "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
236- type (result_t) result_
247+ logical test_passes
237248 type (object_t) object
238249 integer initial_tally
239250
240251 initial_tally = finalizations
241252 call finalize_intent_out_arg(object)
242253 associate(delta = > finalizations - initial_tally)
243- result_ = assert_equals( 1 , delta)
254+ test_passes = delta == 1
244255 end associate
245256 contains
246257 subroutine finalize_intent_out_arg (output )
@@ -249,4 +260,4 @@ subroutine finalize_intent_out_arg(output)
249260 end subroutine
250261 end function
251262
252- end module compiler_test
263+ end module compiler_test_m
0 commit comments