Skip to content

Commit e0c0474

Browse files
author
Damian Rouson
committed
Print all errors in get_convert_char_array.f90
The previous version of this test error-terminated upon the first of 14 checks. The revised version prints all error messages before error-terminating if any were printed.
1 parent a772216 commit e0c0474

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

src/tests/unit/send-get/get_convert_char_array.f90

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
!!
55
!! FOO = BAR [N]
66
!!
7-
!! where
7+
!! where
88
!!
99
!! FOO BAR images
1010
!! character(len=20) character(len=10) N == me
@@ -41,6 +41,7 @@ program get_convert_char_array
4141
character(kind=1, len=5) :: str_k1_arr(1:4)
4242
character(kind=4, len=5), codimension[*] :: co_str_k4_arr(1:4)
4343
character(kind=4, len=5) :: str_k4_arr(1:4)
44+
logical :: error_printed=.false.
4445

4546
associate(me => this_image(), np => num_images())
4647
if (np < 2) error stop 'Can not run with less than 2 images.'
@@ -55,80 +56,103 @@ program get_convert_char_array
5556
if (me == 1) then
5657
str_k1_scal = co_str_k1_scal[1]
5758
print *, '#' // str_k1_scal // '#, len:', len(str_k1_scal)
58-
if (co_str_k1_scal /= str_k1_scal // ' ') error stop 'get scalar kind=1 to kind=1 self failed.'
59+
if (co_str_k1_scal /= str_k1_scal // ' ') call print_and_register( 'get scalar kind=1 to kind=1 self failed.')
5960

6061
str_k4_scal = co_str_k4_scal[1]
6162
print *, 4_'#' // str_k4_scal // 4_'#, len:', len(str_k4_scal)
62-
if (co_str_k4_scal /= str_k4_scal // 4_' ') error stop 'get scalar kind=4 to kind=4 self failed.'
63+
if (co_str_k4_scal /= str_k4_scal // 4_' ') call print_and_register( 'get scalar kind=4 to kind=4 self failed.')
6364

6465
str_k4_scal = co_str_k1_scal[1]
6566
print *, 4_'#' // str_k4_scal // 4_'#, len:', len(str_k4_scal)
66-
if (co_str_k4_scal /= str_k4_scal // 4_' ') error stop 'get scalar kind=1 to kind=4 self failed.'
67+
if (co_str_k4_scal /= str_k4_scal // 4_' ') call print_and_register( 'get scalar kind=1 to kind=4 self failed.')
6768

6869
str_k1_scal = co_str_k4_scal[1]
6970
print *, '#' // str_k1_scal // '#, len:', len(str_k1_scal)
70-
if (co_str_k1_scal /= str_k1_scal // ' ') error stop 'get scalar kind=4 to kind=1 self failed.'
71+
if (co_str_k1_scal /= str_k1_scal // ' ') call print_and_register( 'get scalar kind=4 to kind=1 self failed.')
7172
end if
7273

7374
! Do the same for arrays but on image 2
7475
if (me == 2) then
7576
str_k1_arr(:) = co_str_k1_arr(:)[2]
7677
print *, '#' // str_k1_arr(:) // '#, len:', len(str_k1_arr(1))
77-
if (any(str_k1_arr /= ['abc ', 'EFG ', 'klm ', 'NOP '])) error stop 'get array kind=1 to kind=1 self failed.'
78-
79-
print *, str_k4_arr
78+
if (any(str_k1_arr /= ['abc ', 'EFG ', 'klm ', 'NOP '])) &
79+
call print_and_register( 'get array kind=1 to kind=1 self failed.')
80+
81+
print *, str_k4_arr
8082
str_k4_arr(:) = co_str_k4_arr(:)[2]
8183
print *, 4_'#' // str_k4_arr(:) // 4_'#, len:', len(str_k4_arr(1))
82-
if (any(str_k4_arr /= [4_'abc ', 4_'EFG ', 4_'klm ', 4_'NOP '])) error stop 'get array kind=4 to kind=4 self failed.'
84+
if (any(str_k4_arr /= [4_'abc ', 4_'EFG ', 4_'klm ', 4_'NOP '])) &
85+
call print_and_register( 'get array kind=4 to kind=4 self failed.')
8386

8487
str_k4_arr(:) = co_str_k1_arr(:)[2]
8588
print *, 4_'#' // str_k4_arr(:) // 4_'#, len:', len(str_k4_arr(1))
86-
if (any(str_k4_arr /= [ 4_'abc ', 4_'EFG ', 4_'klm ', 4_'NOP '])) error stop 'get array kind=1 to kind=4 self failed.'
89+
if (any(str_k4_arr /= [ 4_'abc ', 4_'EFG ', 4_'klm ', 4_'NOP '])) &
90+
call print_and_register( 'get array kind=1 to kind=4 self failed.')
8791

8892
str_k1_arr(:) = co_str_k4_arr(:)[2]
8993
print *, '#' // str_k1_arr(:) // '#, len:', len(str_k1_arr(1))
90-
if (any(str_k1_arr /= ['abc ', 'EFG ', 'klm ', 'NOP '])) error stop 'get array kind=4 to kind=1 self failed.'
94+
if (any(str_k1_arr /= ['abc ', 'EFG ', 'klm ', 'NOP '])) &
95+
call print_and_register( 'get array kind=4 to kind=1 self failed.')
9196
end if
9297

9398
sync all
9499
if (me == 1) then
95100
str_k1_scal = co_str_k1_scal[2]
96101
print *, '#' // str_k1_scal // '#, len:', len(str_k1_scal)
97-
if (co_str_k1_scal /= str_k1_scal // ' ') error stop 'get kind=1 to kind=1 image 2 failed.'
102+
if (co_str_k1_scal /= str_k1_scal // ' ') call print_and_register( 'get kind=1 to kind=1 image 2 failed.')
98103

99104
str_k4_scal = co_str_k4_scal[2]
100105
print *, 4_'#' // str_k4_scal // 4_'#, len:', len(str_k4_scal)
101-
if (co_str_k4_scal /= str_k4_scal // 4_' ') error stop 'get kind=4 to kind=4 image 2 failed.'
106+
if (co_str_k4_scal /= str_k4_scal // 4_' ') call print_and_register( 'get kind=4 to kind=4 image 2 failed.')
102107
else if (me == 2) then
103108
str_k4_scal = co_str_k1_scal[1]
104109
print *, 4_'#' // str_k4_scal // 4_'#, len:', len(str_k4_scal)
105-
if (co_str_k4_scal /= str_k4_scal // 4_' ') error stop 'get kind=1 to kind=4 from image 1 failed.'
110+
if (co_str_k4_scal /= str_k4_scal // 4_' ') call print_and_register( 'get kind=1 to kind=4 from image 1 failed.')
106111

107112
str_k1_scal = co_str_k4_scal[1]
108113
print *, '#' // str_k1_scal // '#, len:', len(str_k1_scal)
109-
if (co_str_k1_scal /= str_k1_scal // ' ') error stop 'get kind=4 to kind=1 from image 1 failed.'
114+
if (co_str_k1_scal /= str_k1_scal // ' ') call print_and_register( 'get kind=4 to kind=1 from image 1 failed.')
110115
end if
111116

112117
str_k1_arr(:) = '#####'
113118
str_k4_arr(:) = 4_'#####'
114-
119+
115120
sync all
116121

117122
if (me == 1) then
118123
str_k1_arr(1:2) = co_str_k1_arr(::2)[2]
119124
print *, str_k1_arr
120125
if (any(str_k1_arr /= ['abc ', 'klm ', '#####', '#####'])) &
121-
& error stop "strided get char arr kind 1 to kind 1 failed."
126+
& call print_and_register( "strided get char arr kind 1 to kind 1 failed.")
122127

123128
str_k4_arr(1:2) = co_str_k4_arr(::2)[2]
124129
print *, str_k4_arr
125130
if (any(str_k4_arr /= [4_'abc ', 4_'klm ', 4_'#####', 4_'#####'] )) &
126-
& error stop "strided get char arr kind 4 to kind 4 failed."
131+
& call print_and_register( "strided get char arr kind 4 to kind 4 failed.")
127132
end if
128133

129-
sync all
130-
if (me == 1) print *, 'Test passed.'
134+
select case(me)
135+
case(1)
136+
if (error_printed) error stop
137+
sync images(2)
138+
print *, 'Test passed.'
139+
case(2)
140+
if (error_printed) error stop
141+
sync images(1)
142+
end select
143+
131144
end associate
145+
146+
contains
147+
148+
subroutine print_and_register(error_message)
149+
use iso_fortran_env, only : error_unit
150+
character(len=*), intent(in) :: error_message
151+
write(error_unit,*) error_message
152+
error_printed=.true.
153+
end subroutine
154+
132155
end program get_convert_char_array
133156

134157
! vim:ts=2:sts=2:sw=2:
158+

0 commit comments

Comments
 (0)