Skip to content

Commit 551dca9

Browse files
authored
Merge pull request #32 from sourceryinstitute/tallies
Report test tallies
2 parents f5dc594 + af6225a commit 551dca9

File tree

7 files changed

+54
-38
lines changed

7 files changed

+54
-38
lines changed

src/test_m.F90 renamed to src/test_m.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ function results_interface() result(test_results)
3333

3434
interface
3535

36-
module subroutine report(test)
37-
!! Report test results
36+
module subroutine report(test, passes, tests)
37+
!! Print the test results and increment the tallies of passing tests and total tests
3838
implicit none
3939
class(test_t), intent(in) :: test
40+
integer, intent(inout) :: passes, tests
4041
end subroutine
4142

4243
end interface

src/test_result_m.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module test_result_m
1212
logical passed_
1313
contains
1414
procedure :: characterize
15+
procedure :: passed
1516
end type
1617

1718
interface test_result_t
@@ -35,6 +36,13 @@ pure module function characterize(self) result(characterization)
3536
character(len=:), allocatable :: characterization
3637
end function
3738

39+
elemental module function passed(self) result(test_passed)
40+
!! The result is a character description of the test and its outcome
41+
implicit none
42+
class(test_result_t), intent(in) :: self
43+
logical test_passed
44+
end function
45+
3846
end interface
3947

4048
end module test_result_m

src/test_result_s.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
characterization = merge("passes on ", "FAILS on ", self%passed_) // self%description_ // "."
1313
end procedure
1414

15+
module procedure passed
16+
test_passed = self%passed_
17+
end procedure
18+
1519
end submodule test_result_s

src/test_s.F90

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/test_s.f90

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
submodule(test_m) test_s
2+
implicit none
3+
4+
contains
5+
6+
module procedure report
7+
integer i
8+
9+
associate(test_results => test%results())
10+
print *
11+
print *, test%subject()
12+
associate(num_tests => size(test_results))
13+
tests = tests + num_tests
14+
do i=1,num_tests
15+
print *," ",test_results(i)%characterize()
16+
end do
17+
associate(num_passes => count(test_results%passed()))
18+
print '(a,2(i0,a))'," ",num_passes," of ", num_tests," tests pass."
19+
passes = passes + num_passes
20+
end associate
21+
end associate
22+
end associate
23+
24+
end procedure
25+
26+
end submodule test_s

test/main.f90

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ program main
55
use formats_test, only : formats_test_t
66
implicit none
77

8-
type(data_partition_test_t) data_partition_test
98
type(collectives_test_t) collectives_test
10-
type(object_test_t) object_test
9+
type(data_partition_test_t) data_partition_test
1110
type(formats_test_t) formats_test
11+
type(object_test_t) object_test
12+
13+
integer :: passes=0, tests=0
14+
15+
call data_partition_test%report(passes, tests)
16+
call collectives_test%report(passes, tests)
17+
call object_test%report(passes, tests)
18+
call formats_test%report(passes, tests)
19+
20+
print *
21+
print *,"_________ In total, ",passes," of ",tests, " tests pass. _________"
1222

13-
call data_partition_test%report()
14-
call collectives_test%report()
15-
call object_test%report()
16-
call formats_test%report()
1723
end program

test/object_m_test.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pure function subject() result(specimen)
2525
specimen = "The object_m type"
2626
end function
2727

28-
pure function results() result(test_results)
28+
function results() result(test_results)
2929
type(test_result_t), allocatable :: test_results(:)
3030

3131
test_results = [ &

0 commit comments

Comments
 (0)