@@ -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
90- }
91-
92- test_desc <- as.character(expr [[2 ]])
93- if (test_desc != desc ) {
94- next
95- }
96-
97- if (found ) {
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 ) {
98106 abort(
99107 " Found multiple tests with specified description" ,
100108 call = error_call
101109 )
110+ }
111+ include [[i ]] <- TRUE
112+ found <- TRUE
113+ exprs [[i ]][[3 ]] <- {
114+ find_matching_expr(expr [[3 ]], queue [- 1 ])
115+ }
116+ }
102117 }
103- include [[i ]] <- TRUE
104- found <- TRUE
105- }
106- }
107118
108- if (! found ) {
109- abort(" Failed to find test with specified description" , call = error_call )
110- }
119+ if (! found ) {
120+ abort(paste0( " Failed to find test with specified description: ' " , desc , " ' " ) , call = error_call )
121+ }
111122
112- exprs [include ]
123+ exprs [include ]
124+ }
125+ }
126+ find_matching_expr(exprs , desc_levels )
113127}
114128
115129# ' @rdname source_file
0 commit comments