1
- module compiler_test
1
+ module compiler_test_m
2
2
! ! Test compiler conformance with each scenario in which the Fortran 2018
3
3
! ! 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
5
6
use iso_fortran_env, only : compiler_version
6
7
implicit none
7
8
8
9
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
10
17
11
18
type object_t
12
19
integer dummy
@@ -24,23 +31,26 @@ module compiler_test
24
31
25
32
contains
26
33
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
+ ]
44
54
end function
45
55
46
56
function construct_object () result(object)
@@ -56,58 +66,58 @@ subroutine count_finalizations(self)
56
66
self % dummy = avoid_unused_variable_warning
57
67
end subroutine
58
68
59
- function check_lhs_object () result(result_ )
69
+ function check_lhs_object () result(test_passes )
60
70
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
61
71
! ! "not an unallocated allocatable variable"
62
72
type (object_t) lhs, rhs
63
- type (result_t) result_
73
+ logical test_passes
64
74
integer initial_tally
65
75
66
76
rhs% dummy = avoid_unused_variable_warning
67
77
initial_tally = finalizations
68
78
lhs = rhs ! finalizes lhs
69
79
associate(delta = > finalizations - initial_tally)
70
- result_ = assert_equals( 1 , delta)
80
+ test_passes = delta == 1
71
81
end associate
72
82
end function
73
83
74
- function check_allocated_allocatable_lhs () result(result_ )
84
+ function check_allocated_allocatable_lhs () result(test_passes )
75
85
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
76
86
! ! "allocated allocatable variable"
77
87
type (object_t), allocatable :: lhs
78
88
type (object_t) rhs
79
- type (result_t) result_
89
+ logical test_passes
80
90
integer initial_tally
81
91
82
92
rhs% dummy = avoid_unused_variable_warning
83
93
initial_tally = finalizations
84
94
allocate (lhs)
85
95
lhs = rhs ! finalizes lhs
86
96
associate(delta = > finalizations - initial_tally)
87
- result_ = assert_equals( 1 , delta)
97
+ test_passes = delta == 1
88
98
end associate
89
99
end function
90
100
91
- function check_target_deallocation () result(result_ )
101
+ function check_target_deallocation () result(test_passes )
92
102
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2 behavior:
93
103
! ! "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
96
106
integer initial_tally
97
107
98
108
allocate (object_ptr, source= object_t(dummy= 0 ))
99
109
initial_tally = finalizations
100
110
deallocate (object_ptr) ! finalizes object
101
111
associate(delta = > finalizations - initial_tally)
102
- result_ = assert_equals( 1 , delta)
112
+ test_passes = delta == 1
103
113
end associate
104
114
end function
105
115
106
- function check_allocatable_component_finalization () result(result_ )
116
+ function check_allocatable_component_finalization () result(test_passes )
107
117
! ! Test conformance with Fortran 2018 clause 7.5.6.3, para. 2 ("allocatable entity is deallocated")
108
118
! ! + 9.7.3.2, para. 6 ("INTENT(OUT) allocatable dummy argument is deallocated")
109
119
type (wrapper_t), allocatable :: wrapper
110
- type (result_t) result_
120
+ logical test_passes
111
121
integer initial_tally
112
122
113
123
initial_tally = finalizations
@@ -116,7 +126,7 @@ function check_allocatable_component_finalization() result(result_)
116
126
allocate (wrapper% object)
117
127
call finalize_intent_out_component(wrapper)
118
128
associate(delta = > finalizations - initial_tally)
119
- result_ = assert_equals( 1 , delta)
129
+ test_passes = delta == 1
120
130
end associate
121
131
122
132
contains
@@ -129,32 +139,32 @@ subroutine finalize_intent_out_component(output)
129
139
130
140
end function
131
141
132
- function check_finalize_on_deallocate () result(result_ )
142
+ function check_finalize_on_deallocate () result(test_passes )
133
143
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2:
134
144
! ! "allocatable entity is deallocated"
135
145
type (object_t), allocatable :: object
136
- type (result_t) result_
146
+ logical test_passes
137
147
integer initial_tally
138
148
139
149
initial_tally = finalizations
140
150
allocate (object)
141
151
object% dummy = 1
142
152
deallocate (object) ! finalizes object
143
153
associate(final_tally = > finalizations - initial_tally)
144
- result_ = assert_equals( 1 , final_tally)
154
+ test_passes = final_tally == 1
145
155
end associate
146
156
end function
147
157
148
- function check_finalize_on_end () result(result_ )
158
+ function check_finalize_on_end () result(test_passes )
149
159
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 3:
150
160
! ! "before return or END statement"
151
- type (result_t) result_
161
+ logical test_passes
152
162
integer initial_tally
153
163
154
164
initial_tally = finalizations
155
165
call finalize_on_end_subroutine() ! Finalizes local_obj
156
166
associate(final_tally = > finalizations - initial_tally)
157
- result_ = assert_equals( 1 , final_tally)
167
+ test_passes = final_tally == 1
158
168
end associate
159
169
160
170
contains
@@ -166,10 +176,10 @@ subroutine finalize_on_end_subroutine()
166
176
167
177
end function
168
178
169
- function check_block_finalization () result(result_ )
179
+ function check_block_finalization () result(test_passes )
170
180
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 4:
171
181
! ! "termination of the BLOCK construct"
172
- type (result_t) result_
182
+ logical test_passes
173
183
integer initial_tally
174
184
175
185
initial_tally = finalizations
@@ -178,28 +188,28 @@ function check_block_finalization() result(result_)
178
188
object % dummy = avoid_unused_variable_warning
179
189
end block ! Finalizes object
180
190
associate(delta = > finalizations - initial_tally)
181
- result_ = assert_equals( 1 , delta)
191
+ test_passes = delta == 1
182
192
end associate
183
193
end function
184
194
185
- function check_rhs_function_reference () result(result_ )
195
+ function check_rhs_function_reference () result(test_passes )
186
196
! ! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 5 behavior:
187
197
! ! "nonpointer function result"
188
198
type (object_t), allocatable :: object
189
- type (result_t) result_
199
+ logical test_passes
190
200
integer initial_tally
191
201
192
202
initial_tally = finalizations
193
203
object = construct_object() ! finalizes object_t result
194
204
associate(delta = > finalizations - initial_tally)
195
- result_ = assert_equals( 1 , delta)
205
+ test_passes = delta == 1
196
206
end associate
197
207
end function
198
208
199
- function check_specification_expression () result(result_ )
209
+ function check_specification_expression () result(test_passes )
200
210
! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 6:
201
211
! ! "specification expression function result"
202
- type (result_t) result_
212
+ logical test_passes
203
213
integer exit_status
204
214
logical error_termination_occurred
205
215
@@ -209,18 +219,20 @@ function check_specification_expression() result(result_)
209
219
exitstat = exit_status &
210
220
)
211
221
error_termination_occurred = exit_status /= 0
212
- result_ = assert_that( error_termination_occurred)
222
+ test_passes = error_termination_occurred
213
223
214
224
contains
215
225
216
- pure function fpm_compiler_arguments () result(args)
226
+ function fpm_compiler_arguments () result(args)
217
227
character (len= :), allocatable :: args
218
228
219
229
associate(compiler_identity= >compiler_version())
220
- if (scan (compiler_identity, " GCC " )==1 ) then
230
+ if (scan (compiler_identity, " GCC" )==1 ) then
221
231
args = " "
222
- else if (scan (compiler_identity, " NAG Fortran " )==1 ) then
232
+ else if (scan (compiler_identity, " NAG" )==1 ) then
223
233
args = " --compiler nagfor --flag -fpp"
234
+ else if (scan (compiler_identity, " Intel" )==1 ) then
235
+ args = " --compiler ifort --flag -coarray=shared"
224
236
else
225
237
error stop " ----> Unrecognized compiler_version() in function fpm_compiler_arguments. <----"
226
238
end if
@@ -229,18 +241,17 @@ pure function fpm_compiler_arguments() result(args)
229
241
230
242
end function
231
243
232
-
233
- function check_intent_out_finalization () result(result_)
244
+ function check_intent_out_finalization () result(test_passes)
234
245
! ! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 7:
235
246
! ! "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
236
- type (result_t) result_
247
+ logical test_passes
237
248
type (object_t) object
238
249
integer initial_tally
239
250
240
251
initial_tally = finalizations
241
252
call finalize_intent_out_arg(object)
242
253
associate(delta = > finalizations - initial_tally)
243
- result_ = assert_equals( 1 , delta)
254
+ test_passes = delta == 1
244
255
end associate
245
256
contains
246
257
subroutine finalize_intent_out_arg (output )
@@ -249,4 +260,4 @@ subroutine finalize_intent_out_arg(output)
249
260
end subroutine
250
261
end function
251
262
252
- end module compiler_test
263
+ end module compiler_test_m
0 commit comments