@@ -73,43 +73,54 @@ 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+ include [[i ]] <- TRUE
95+ } else {
96+ if (! is_string(expr [[2 ]])) {
97+ next
98+ }
99+
100+ test_desc <- as.character(expr [[2 ]])
101+ if (test_desc != desc ) {
102+ next
103+ }
104+
105+ if (found ) {
106+ abort(" Found multiple tests with specified description" , call = error_call )
107+ }
108+ include [[i ]] <- TRUE
109+ found <- TRUE
110+ exprs [[i ]][[3 ]] <- {
111+ find_matching_expr(expr [[3 ]], queue [- 1 ])
112+ }
113+ }
90114 }
91115
92- test_desc <- as.character(expr [[2 ]])
93- if (test_desc != desc ) {
94- next
116+ if (! found ) {
117+ abort(paste0(" Failed to find test with specified description: '" , desc , " '" ), call = error_call )
95118 }
96119
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
120+ exprs [include ]
105121 }
106122 }
107-
108- if (! found ) {
109- abort(" Failed to find test with specified description" , call = error_call )
110- }
111-
112- exprs [include ]
123+ find_matching_expr(exprs , desc_levels )
113124}
114125
115126# ' @rdname source_file
0 commit comments