Skip to content

Commit 2ee49f3

Browse files
authored
Merge pull request #66 from sourceryinstitute/pass-only-if-all-pass
fix(test_result): pass only if all images pass test
2 parents 5ecdc18 + 0ca3195 commit 2ee49f3

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/sourcery/sourcery_test_result_m.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pure module function characterize(self) result(characterization)
3636
character(len=:), allocatable :: characterization
3737
end function
3838

39-
elemental module function passed(self) result(test_passed)
40-
!! The result is a character description of the test and its outcome
39+
impure elemental module function passed(self) result(test_passed)
40+
!! The result is true if and only if the test passed on all images
4141
implicit none
4242
class(test_result_t), intent(in) :: self
4343
logical test_passed

src/sourcery/sourcery_test_result_s.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
submodule(sourcery_test_result_m) sourcery_test_result_s
2+
use sourcery_user_defined_collectives_m, only : co_all
23
implicit none
34

45
contains
@@ -14,6 +15,7 @@
1415

1516
module procedure passed
1617
test_passed = self%passed_
18+
call co_all(test_passed)
1719
end procedure
1820

1921
end submodule sourcery_test_result_s

test/test_result_test.f90

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function results() result(test_results)
2323
type(test_result_t), allocatable :: test_results(:)
2424

2525
test_results = [ &
26-
test_result_t("constructs and array of test_result_t objects elementally", check_array_result_construction()) &
26+
test_result_t("constructing an array of test_result_t objects elementally", check_array_result_construction()), &
27+
test_result_t("reporting failure if the test fails on one image", check_single_image_failure()) &
2728
]
2829
end function
2930

@@ -36,4 +37,17 @@ pure function check_array_result_construction() result(passed)
3637
passed = size(test_results)==2
3738
end function
3839

40+
function check_single_image_failure() result(passed)
41+
type(test_result_t), allocatable :: test_result
42+
logical passed
43+
44+
if (this_image()==1) then
45+
test_result = test_result_t("image 1 fails", .false.)
46+
else
47+
test_result = test_result_t("all images other than 1 pass", .true.)
48+
end if
49+
50+
passed = .not. test_result%passed()
51+
end function
52+
3953
end module test_result_test_m

0 commit comments

Comments
 (0)