11test_that(" activated cache brings speedup on style_file() API" , {
2+ local_test_setup()
23 skip_on_cran()
34 n <- n_times_faster_with_cache(
45 test_path(" reference-objects/caching.R" ),
@@ -44,32 +45,41 @@ test_that("activated cache brings speedup on style_text() API on character scala
4445
4546
4647test_that(" trailing line breaks are ignored for caching" , {
48+ local_test_setup(cache = TRUE )
4749 text1 <- paste0(text , collapse = " \n " )
4850 text2 <- c(paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " )
49- n <- n_times_faster_with_cache(text1 , text2 , clear = " all but last" )
50- expect_equal(cache_info()$ n , 3 )
51+ style_text(text1 )
52+ style_text(text2 )
53+ expect_equal(cache_info(format = " tabular" )$ n , 3 )
5154 skip_on_cran()
55+ n <- n_times_faster_with_cache(text1 , text2 )
5256 expect_gt(n , 55 )
5357})
5458
5559test_that(" trailing line breaks are ignored for caching in one scalar" , {
60+ local_test_setup(cache = TRUE )
5661 text1 <- paste0(text , collapse = " \n " )
5762 text2 <- c(paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " )
58- n <- n_times_faster_with_cache(text1 , text2 , clear = " all but last" )
59- expect_equal(cache_info()$ n , 3 )
63+ style_text(text1 )
64+ style_text(text2 )
65+ expect_equal(cache_info(format = " tabular" )$ n , 3 )
6066 skip_on_cran()
67+ n <- n_times_faster_with_cache(text1 , text2 )
6168 expect_gt(n , 55 )
6269})
6370
6471test_that(" trailing line breaks are ignored for caching in one scalar" , {
72+ local_test_setup(cache = TRUE )
6573 text1 <- paste0(text , collapse = " \n " )
6674 text2 <- paste0(
6775 paste0(text , collapse = " \n " ), " \n " , " \n " , " \n " , " \n " ,
6876 collapse = " "
6977 )
70- n <- n_times_faster_with_cache(text1 , text2 , clear = " all but last" )
71- expect_equal(cache_info()$ n , 3 )
78+ style_text(text1 )
79+ style_text(text2 )
80+ expect_equal(cache_info(format = " tabular" )$ n , 3 )
7281 skip_on_cran()
82+ n <- n_times_faster_with_cache(text1 , text2 )
7383 expect_gt(n , 55 )
7484})
7585
@@ -112,31 +122,27 @@ test_that("speedup higher when cached roxygen example code is multiple expressio
112122
113123
114124
115- capture.output( test_that(" no speedup when tranformer changes" , {
125+ test_that(" no speedup when tranformer changes" , {
116126 skip_on_cran()
117- on.exit(clear_testthat_cache())
118- fresh_testthat_cache()
127+ local_test_setup()
119128 t1 <- tidyverse_style()
120129 first <- system.time(style_text(text , transformers = t1 ))
121130 t1 <- tidyverse_style(indent_by = 4 )
122131 second <- system.time(style_text(text , transformers = t1 ))
123132 expect_false(first [" elapsed" ] / 1.3 > second [" elapsed" ])
124- }))
133+ })
125134
126135
127- capture.output(test_that(" unactivated cache does not bring speedup" , {
128- skip_on_cran()
129- on.exit(clear_testthat_cache())
130- clear_testthat_cache()
136+ test_that(" unactivated cache does not bring speedup" , {
137+ skip_on_cran
138+ local_test_setup()
131139 first <- system.time(style_file(test_path(" reference-objects/caching.R" )))
132140 second <- system.time(style_file(test_path(" reference-objects/caching.R" )))
133141 expect_false(first [" elapsed" ] / 4 > second [" elapsed" ])
134- }))
142+ })
135143
136- capture.output(test_that(" avoid deleting comments #584 (see commit messages)" , {
137- on.exit(clear_testthat_cache())
138- clear_testthat_cache()
139- activate_testthat_cache()
144+ test_that(" avoid deleting comments #584 (see commit messages)" , {
145+ local_test_setup()
140146 text <- c(
141147 " 1 + 1" ,
142148 " # Comment" ,
@@ -151,12 +157,10 @@ capture.output(test_that("avoid deleting comments #584 (see commit messages)", {
151157 " NULL"
152158 )
153159 expect_equal(as.character(style_text(text2 )), text2 )
154- }))
160+ })
155161
156- capture.output(test_that(" avoid removing roxygen mask (see commit messages in #584)" , {
157- on.exit(clear_testthat_cache())
158- clear_testthat_cache()
159- activate_testthat_cache()
162+ test_that(" avoid removing roxygen mask (see commit messages in #584)" , {
163+ local_test_setup()
160164 text <- c(
161165 " c(" ,
162166 " 1, 2," ,
@@ -176,12 +180,10 @@ capture.output(test_that("avoid removing roxygen mask (see commit messages in #5
176180 " NULL"
177181 )
178182 expect_equal(as.character(style_text(text2 )), text2 )
179- }))
183+ })
180184
181- capture.output(test_that(" partial caching of multiple expressions on one line works" , {
182- on.exit(clear_testthat_cache())
183- clear_testthat_cache()
184- activate_testthat_cache()
185+ test_that(" partial caching of multiple expressions on one line works" , {
186+ local_test_setup()
185187 text <- " 1"
186188 style_text(text )
187189 text2 <- " 1 # comment"
@@ -195,7 +197,7 @@ capture.output(test_that("partial caching of multiple expressions on one line wo
195197 style_text(c(" mtcars %>%" , " f()" ))
196198 final_text <- c(" mtcars %>%" , " f() #" )
197199 expect_equal(as.character(style_text(final_text )), final_text )
198- }))
200+ })
199201
200202test_that(" cache is deactivated at end of caching related testthat file" , {
201203 expect_false(cache_is_activated())
0 commit comments