Skip to content

Commit 0211f6b

Browse files
committed
feat(test): select tests by description substring
1 parent 348af01 commit 0211f6b

File tree

6 files changed

+45
-7
lines changed

6 files changed

+45
-7
lines changed

src/sourcery/sourcery_test_description_m.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function test_function_i() result(passes)
2424
procedure(test_function_i), pointer, nopass :: test_function_ => null()
2525
contains
2626
procedure run
27+
procedure contains_text
2728
end type
2829

2930
interface test_description_t
@@ -47,6 +48,14 @@ impure elemental module function run(self) result(test_result)
4748
type(test_result_t) test_result
4849
end function
4950

51+
impure elemental module function contains_text(self, substring) result(match)
52+
!! The result is .true. if the test description includes the value of substring
53+
implicit none
54+
class(test_description_t), intent(in) :: self
55+
type(string_t), intent(in) :: substring
56+
logical match
57+
end function
58+
5059
end interface
5160

5261
end module sourcery_test_description_m

src/sourcery/sourcery_test_description_s.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
test_result = test_result_t(self%description_, self%test_function_())
1313
end procedure
1414

15+
module procedure contains_text
16+
match = index(self%description_%string(), substring%string()) /= 0
17+
end procedure
18+
1519
end submodule sourcery_test_description_s

src/sourcery/sourcery_test_m.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ module sourcery_test_m
66
implicit none
77

88
private
9-
public :: test_t, test_result_t
9+
public :: test_t, test_description_substring
10+
11+
character(len=:), allocatable, protected :: test_description_substring
1012

1113
type, abstract :: test_t
1214
!! Facilitate testing and test reporting

src/sourcery/sourcery_test_s.F90

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
submodule(sourcery_test_m) sourcery_test_s
22
use sourcery_user_defined_collectives_m, only : co_all
3+
use sourcery_command_line_m, only : command_line_t
34
implicit none
45

56
contains
67

78
module procedure report
89

910
associate(me => this_image())
10-
if (me==1) print *, new_line('a'), test%subject()
1111

12+
if (me==1) then
13+
14+
first_report: &
15+
if (.not. allocated(test_description_substring)) then
16+
block
17+
type(command_line_t) command_line
18+
test_description_substring = command_line%flag_value("--contains")
19+
end block
20+
if (len(test_description_substring)==0) then
21+
print *,"Running all tests."
22+
print *,"(Add '-- --contains <string> to run only tests with descriptions containing the specified string.)"
23+
else
24+
print *,"Running only tests with descriptions containing '", test_description_substring,"'."
25+
end if
26+
end if first_report
27+
28+
print *, new_line('a'), test%subject()
29+
30+
end if
31+
32+
call co_broadcast(test_description_substring, source_image=1)
33+
1234
#ifndef _CRAYFTN
1335
associate(test_results => test%results())
1436
associate(num_tests => size(test_results))

src/sourcery_m.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module sourcery_m
77
use sourcery_file_m, only : file_t
88
use sourcery_string_m, only : string_t, operator(.cat.)
99
use sourcery_test_result_m, only : test_result_t
10-
use sourcery_test_m, only : test_t
10+
use sourcery_test_m, only : test_t, test_description_substring
1111
use sourcery_user_defined_collectives_m, only : co_all
1212

1313
!! legacy modules (likely to be removed in a future release):

test/test_result_test.F90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module test_result_test_m
22
!! Verify test_result_t object behavior
33
use sourcery_string_m, only : string_t
4-
use sourcery_test_m, only : test_t, test_result_t
4+
use sourcery_test_result_m, only : test_result_t
55
use sourcery_test_description_m, only : test_description_t
6+
use sourcery_test_m, only : test_t, test_description_substring
67
#ifdef __GFORTRAN__
78
use sourcery_test_description_m, only : test_function_i
89
#endif
@@ -27,6 +28,7 @@ pure function subject() result(specimen)
2728
function results() result(test_results)
2829
type(test_result_t), allocatable :: test_results(:)
2930
type(test_description_t), allocatable :: test_descriptions(:)
31+
3032
#ifndef __GFORTRAN__
3133
test_descriptions = [ &
3234
test_description_t(string_t("constructing an array of test_result_t objects elementally"), check_array_result_construction) &
@@ -35,16 +37,15 @@ function results() result(test_results)
3537
#else
3638
! Work around missing Fortran 2008 feature: associating a procedure actual argument with a procedure pointer dummy argument:
3739
procedure(test_function_i), pointer :: check_array_ptr, check_single_ptr
38-
3940
check_array_ptr => check_array_result_construction
4041
check_single_ptr => check_single_image_failure
41-
4242
test_descriptions = [ &
4343
test_description_t(string_t("constructing an array of test_result_t objects elementally"), check_array_ptr), &
4444
test_description_t(string_t("reporting failure if the test fails on one image"), check_single_ptr) &
4545
]
4646
#endif
47-
test_results = test_descriptions%run()
47+
test_descriptions = pack(test_descriptions, test_descriptions%contains_text(string_t(test_description_substring)))
48+
test_results = test_descriptions%run()
4849
end function
4950

5051
function check_array_result_construction() result(passed)

0 commit comments

Comments
 (0)