Skip to content

Commit fbc6c46

Browse files
author
J. Henneberg
committed
- parameter: unknow_file and unknown_line delete, were not used, initial values in type were set instead
- extended report_suite similar to test_case_report - added one example in test_assert.F90 which gets an actual file_name and file_number as a parameter, for this /fpp (fortran preprocessor) has to be set
1 parent 04f9792 commit fbc6c46

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/assert_mod.F90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ module assert_mod
66

77
implicit none
88

9-
character(12), parameter :: unknown_file = 'Unknown file'
10-
integer, parameter :: unknown_line = 0
11-
129
interface assert_equal
1310
module procedure assert_equal_integer
1411
module procedure assert_equal_real4

src/test/test_assert.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ program test_assert
116116

117117
! -> real8
118118
call test_case_create('real8', test_suite_great_than)
119-
call assert_great_than(1.0D0, 1.0D0, suite=test_suite_great_than)
120-
call assert_great_than(2.0D0, 1.0D0, suite=test_suite_great_than)
119+
call assert_great_than(1.0D0, 1.0D0, __FILE__, __LINE__, test_suite_great_than)
120+
call assert_great_than(2.0D0, 1.0D0, __FILE__, __LINE__, test_suite_great_than)
121121

122122
! report
123123
call test_suite_report(test_suite_great_than)

src/test_case_mod.F90

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ module test_case_mod
2020
character(30) :: assert_operator
2121
character(256) :: left_operand
2222
character(256) :: right_operand = ''
23-
character(256) :: file_name
24-
integer line_number
25-
logical passed
23+
character(256) :: file_name = 'Unknown file'
24+
integer :: line_number = -1
25+
logical :: passed = .false.
2626
type(assert_result_type), pointer :: next => null()
2727
end type assert_result_type
2828

@@ -138,13 +138,12 @@ subroutine test_case_report(name, suite)
138138
write(log_err_unit, *) 'Assertion #' // trim(to_string(assert_result%id)) // ' failed with reason: ' // &
139139
'x (' // trim(assert_result%left_operand) // ') ' // trim(assert_result%assert_operator) // &
140140
' y (' // trim(assert_result%right_operand) // ')'
141-
write(log_err_unit, *)
142141
write(log_err_unit, *) 'Check line: ', trim(assert_result%file_name), ':', trim(to_string(assert_result%line_number))
143142
else
144143
write(log_err_unit, *) 'Assertion #' // trim(to_string(assert_result%id)) // ' failed with reason: ' // &
145144
'x is not ' // trim(assert_result%assert_operator) // '!'
146145
end if
147-
write(6, *)
146+
write(log_err_unit, *)
148147
end if
149148
assert_result => assert_result%next
150149
end do
@@ -187,6 +186,23 @@ subroutine test_suite_report(suite)
187186

188187
num_all_succeed_assert = num_all_succeed_assert + test_case%num_succeed_assert
189188
num_all_assert = num_all_assert + test_case%num_assert
189+
190+
assert_result => test_case%assert_result_head
191+
do while (associated(assert_result))
192+
if (.not. assert_result%passed) then
193+
if (assert_result%right_operand /= '') then
194+
write(log_err_unit, *) 'Assertion #' // trim(to_string(assert_result%id)) // ' failed with reason: ' // &
195+
'x (' // trim(assert_result%left_operand) // ') ' // trim(assert_result%assert_operator) // &
196+
' y (' // trim(assert_result%right_operand) // ')'
197+
write(log_err_unit, *) 'Check line: ', trim(assert_result%file_name), ':', trim(to_string(assert_result%line_number))
198+
else
199+
write(log_err_unit, *) 'Assertion #' // trim(to_string(assert_result%id)) // ' failed with reason: ' // &
200+
'x is not ' // trim(assert_result%assert_operator) // '!'
201+
end if
202+
write(log_err_unit, *)
203+
end if
204+
assert_result => assert_result%next
205+
end do
190206

191207
test_case => test_case%next
192208
end do

0 commit comments

Comments
 (0)