Skip to content

Commit 9033c72

Browse files
committed
feat: rm user_defined_collectives from test/main
This is the first step in replacing the Vegetables tests with Sourcery's own minimalistic testing infrastructure.
1 parent 9ca9800 commit 9033c72

File tree

8 files changed

+65
-49
lines changed

8 files changed

+65
-49
lines changed

src/test_m.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module test_m
66
implicit none
77

88
private
9-
public :: test_t
9+
public :: test_t, test_result_t
1010

1111
type, abstract :: test_t
1212
!! Facilitate testing and test reporting
@@ -24,7 +24,7 @@ pure function subject_interface() result(specimen)
2424
end function
2525

2626
function results_interface() result(test_results)
27-
!! The result is an array of test outcomes for reporting
27+
!! The result is an array of test results for subsequent reporting in the "report" type-bound procedure
2828
import test_result_t
2929
type(test_result_t), allocatable :: test_results(:)
3030
end function

src/test_result_m.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ module test_result_m
99
!! Encapsulate test descriptions and outcomes and reporting
1010
private
1111
character(len=:), allocatable :: description_
12-
logical outcome_
12+
logical passed_
1313
contains
1414
procedure :: characterize
1515
end type
1616

1717
interface test_result_t
1818

19-
pure module function construct(description, outcome) result(test_result)
19+
pure module function construct(description, passed) result(test_result)
2020
!! The result is a test_result_t object with the components defined by the dummy arguments
2121
implicit none
2222
character(len=*), intent(in) :: description
23-
logical, intent(in) :: outcome
23+
logical, intent(in) :: passed
2424
type(test_result_t) test_result
2525
end function
2626

@@ -29,7 +29,7 @@ pure module function construct(description, outcome) result(test_result)
2929
interface
3030

3131
pure module function characterize(self) result(characterization)
32-
!! The result is a character test description and its outcome
32+
!! The result is a character description of the test and its outcome
3333
implicit none
3434
class(test_result_t), intent(in) :: self
3535
character(len=:), allocatable :: characterization

src/test_result_s.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
module procedure construct
77
test_result%description_ = description
8-
test_result%outcome_ = outcome
8+
test_result%passed_ = passed
99
end procedure
1010

1111
module procedure characterize
12-
characterization = merge("Pass: ", "Fail: ", self%outcome_) // self%description_
12+
characterization = merge("Passes on ", "Fails on ", self%passed_) // self%description_ // "."
1313
end procedure
1414

1515
end submodule test_result_s

src/test_s.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
print *, test%subject()
2020

2121
do i=1,size(test_results)
22-
print *," ",test_results(i)%characterize()
22+
print *," ",test_results(i)%characterize()
2323
end do
2424
#ifndef XLF
2525
end associate

tests/main.f90

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@ program main
66
contains
77
subroutine run()
88
use data_partition_test, only: &
9-
data_partition_data_partition => test_data_partition
9+
data_partition_data_partition => &
10+
test_data_partition
1011
use formats_test, only: &
11-
formats_object => test_object
12+
formats_object => &
13+
test_object
1214
use object_m_test, only: &
13-
object_m_object => test_object
14-
use user_defined_collectives_test, only: &
15-
user_defined_collectives_co_all => test_co_all
15+
object_m_object => &
16+
test_object
1617
use vegetables, only: test_item_t, test_that, run_tests
1718

19+
20+
1821
type(test_item_t) :: tests
19-
type(test_item_t) :: individual_tests(4)
22+
type(test_item_t) :: individual_tests(3)
2023

2124
individual_tests(1) = data_partition_data_partition()
2225
individual_tests(2) = formats_object()
2326
individual_tests(3) = object_m_object()
24-
individual_tests(4) = user_defined_collectives_co_all()
2527
tests = test_that(individual_tests)
2628

29+
2730
call run_tests(tests)
31+
2832
end subroutine
2933
end program
File renamed without changes.

tests/test-driver.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
program main
2+
use user_defined_collectives_test, only : collectives_test_t
3+
implicit none
4+
5+
type(collectives_test_t) collectives_test
6+
7+
call collectives_test%report()
8+
end program
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
module user_defined_collectives_test
2-
use Vegetables, only: Result_t, Test_Item_t, describe, it, assert_equals, assert_that, assert_not
32
use user_defined_collectives_m, only : co_all
3+
use test_m, only : test_t, test_result_t
44
implicit none
55

66
private
7-
public :: test_co_all
7+
public :: collectives_test_t
8+
9+
type, extends(test_t) :: collectives_test_t
10+
contains
11+
procedure, nopass :: subject
12+
procedure, nopass :: results
13+
end type
814

915
contains
1016

11-
function test_co_all() result(tests)
12-
type(Test_Item_t) :: tests
13-
14-
tests = describe( &
15-
"co_all", &
16-
[it( &
17-
"sets all arguments to .true. when previously .true. on all images", &
18-
check_co_all_with_all_true), &
19-
it( &
20-
"sets all arguments to .false. when previously .false. on image 1", &
21-
check_co_all_with_one_false)])
22-
end function
23-
24-
function check_co_all_with_all_true() result(result_)
25-
type(Result_t) :: result_
26-
logical all_true
27-
28-
all_true=.true.
29-
30-
call co_all(all_true)
31-
result_ = assert_that(all_true, "co_all argument remains .true. after call with all arguments .true.")
32-
end function
33-
34-
function check_co_all_with_one_false() result(result_)
35-
type(Result_t) :: result_
36-
logical all_true
37-
38-
all_true = merge(.false., .true., this_image()==1)
39-
call co_all(all_true)
40-
result_ = assert_not(all_true, "co_all argument is .false. after call with one argument .false.")
41-
end function
17+
pure function subject() result(specimen)
18+
character(len=:), allocatable :: specimen
19+
specimen = "The co_all subroutine"
20+
end function
21+
22+
function results() result(test_results)
23+
type(test_result_t), allocatable :: test_results(:)
24+
25+
test_results = [ &
26+
test_result_t("setting all arguments to .true. when previously .true. on all images", check_co_all_with_all_true()), &
27+
test_result_t("setting all arguments to .false. when previously .false. on image 1", check_co_all_with_one_false()) &
28+
]
29+
end function
30+
31+
function check_co_all_with_all_true() result(test_passed)
32+
logical test_passed, all_true
33+
34+
all_true=.true.
35+
call co_all(all_true)
36+
test_passed = all_true
37+
end function
38+
39+
function check_co_all_with_one_false() result(test_passed)
40+
logical test_passed, all_true
41+
42+
all_true = merge(.false., .true., this_image()==1)
43+
call co_all(all_true)
44+
test_passed = .not. all_true
45+
end function
4246

4347
end module user_defined_collectives_test

0 commit comments

Comments
 (0)