@@ -73,43 +73,57 @@ filter_desc <- function(exprs, desc = NULL, error_call = caller_env()) {
7373 if (is.null(desc )) {
7474 return (exprs )
7575 }
76+ desc_levels <- if (is.list(desc )) {
77+ desc
78+ } else {
79+ as.list(desc )
80+ }
7681
77- found <- FALSE
78- include <- rep(FALSE , length(exprs ))
79-
80- for (i in seq_along(exprs )) {
81- expr <- exprs [[i ]]
82-
83- if (! is_call(expr , c(" test_that" , " describe" ), n = 2 )) {
84- if (! found ) {
85- include [[i ]] <- TRUE
86- }
82+ find_matching_expr <- function (exprs , queue ) {
83+ if (length(queue ) == 0 ) {
84+ exprs
8785 } else {
88- if (! is_string(expr [[2 ]])) {
89- next
86+ found <- FALSE
87+ include <- rep(FALSE , length(exprs ))
88+ desc <- queue [[1 ]]
89+
90+ for (i in seq_along(exprs )) {
91+ expr <- exprs [[i ]]
92+
93+ if (! is_call(expr , c(" test_that" , " describe" , " it" ), n = 2 )) {
94+ if (! found ) {
95+ include [[i ]] <- TRUE
96+ }
97+ } else {
98+ if (! is_string(expr [[2 ]])) {
99+ next
100+ }
101+
102+ test_desc <- as.character(expr [[2 ]])
103+ if (test_desc != desc ) {
104+ next
105+ }
106+
107+ if (found ) {
108+ abort(
109+ " Found multiple tests with specified description" ,
110+ call = error_call
111+ )
112+ }
113+ include [[i ]] <- TRUE
114+ found <- TRUE
115+ exprs [[i ]][[3 ]] <- find_matching_expr(expr [[3 ]], queue [- 1 ])
116+ }
90117 }
91118
92- test_desc <- as.character(expr [[2 ]])
93- if (test_desc != desc ) {
94- next
119+ if (! found ) {
120+ abort(" Failed to find test with specified description" , call = error_call )
95121 }
96122
97- if (found ) {
98- abort(
99- " Found multiple tests with specified description" ,
100- call = error_call
101- )
102- }
103- include [[i ]] <- TRUE
104- found <- TRUE
123+ exprs [include ]
105124 }
106125 }
107-
108- if (! found ) {
109- abort(" Failed to find test with specified description" , call = error_call )
110- }
111-
112- exprs [include ]
126+ find_matching_expr(exprs , desc_levels )
113127}
114128
115129# ' @rdname source_file
0 commit comments