@@ -82,134 +82,6 @@ test_that("checks its inputs", {
8282 })
8383})
8484
85- # filter_desc -------------------------------------------------------------
86-
87- test_that(" works with all subtest types" , {
88- code <- exprs(
89- test_that(" foo" , {}),
90- describe(" bar" , {}),
91- it(" baz" , {})
92- )
93- expect_equal(filter_desc(code , " foo" ), code [1 ])
94- expect_equal(filter_desc(code , " bar" ), code [2 ])
95- expect_equal(filter_desc(code , " baz" ), code [3 ])
96- })
97-
98- test_that(" only returns non-subtest code before subtest" , {
99- code <- exprs(
100- f(),
101- test_that(" bar" , {}),
102- describe(" foo" , {}),
103- g(),
104- h()
105- )
106- expect_equal(filter_desc(code , " foo" ), code [c(1 , 3 )])
107- })
108-
109- test_that(" can select recursively" , {
110- code <- exprs(
111- x <- 1 ,
112- describe(" a" , {
113- y <- 1
114- describe(" b" , {
115- z <- 1
116- })
117- y <- 2
118- }),
119- x <- 2
120- )
121-
122- expect_equal(
123- filter_desc(code , c(" a" , " b" )),
124- exprs(
125- x <- 1 ,
126- describe(" a" , {
127- y <- 1
128- describe(" b" , {
129- z <- 1
130- })
131- })
132- )
133- )
134- })
135-
136- test_that(" works on code like the describe() example" , {
137- code <- exprs(
138- describe(" math library" , {
139- x1 <- 1
140- x2 <- 1
141- describe(" addition()" , {
142- it(" can add two numbers" , {
143- expect_equal(x1 + x2 , addition(x1 , x2 ))
144- })
145- })
146- describe(" division()" , {
147- x1 <- 10
148- x2 <- 2
149- it(" can divide two numbers" , {
150- expect_equal(x1 / x2 , division(x1 , x2 ))
151- })
152- it(" can handle division by 0" ) # not yet implemented
153- })
154- })
155- )
156-
157- expect_equal(
158- filter_desc(
159- code ,
160- c(" math library" , " division()" , " can divide two numbers" )
161- ),
162- exprs(
163- describe(" math library" , {
164- x1 <- 1
165- x2 <- 1
166- describe(" division()" , {
167- x1 <- 10
168- x2 <- 2
169- it(" can divide two numbers" , {
170- expect_equal(x1 / x2 , division(x1 , x2 ))
171- })
172- })
173- })
174- )
175- )
176-
177- # what happens for an unimplemented specification?
178- expect_snapshot(
179- error = TRUE ,
180- filter_desc(
181- code ,
182- c(" math library" , " division()" , " can handle division by 0" )
183- )
184- )
185- })
186-
187- test_that(" preserve srcrefs" , {
188- code <- parse(
189- keep.source = TRUE ,
190- text = '
191- test_that("foo", {
192- # this is a comment
193- })
194- '
195- )
196- expect_snapshot(filter_desc(code , " foo" ))
197- })
198-
199- test_that(" errors if zero or duplicate labels" , {
200- code <- exprs(
201- f(),
202- test_that(" baz" , {}),
203- test_that(" baz" , {}),
204- g()
205- )
206-
207- expect_snapshot(error = TRUE , {
208- filter_desc(code , " baz" )
209- filter_desc(code , " missing" )
210- })
211- })
212-
21385test_that(" source_dir()" , {
21486 res <- source_dir(" test_dir" , pattern = " hello" , chdir = TRUE , wrap = FALSE )
21587 expect_equal(res [[1 ]](), " Hello World" )
@@ -233,3 +105,14 @@ test_that("source_dir()", {
233105 )
234106 expect_equal(res [[1 ]](), " Hello World" )
235107})
108+
109+ test_that(" source_file selects correct descriptions" , {
110+ reporter <- CheckReporter $ new()
111+ with_reporter(reporter , {
112+ source_file(" /home/kubajal/development/testthat/tests/testthat/test_dir/test-desc.R" , desc = c(" math library" , " addition|division" , " works for 4 and (1|7)" ), wrap = FALSE )
113+ })
114+ expect_equal(reporter $ problems $ size(), 1 )
115+ expect_equal(reporter $ skips $ size(), 1 )
116+ expect_equal(reporter $ n_ok , 3 )
117+ })
118+
0 commit comments