Skip to content

Commit 38e4b1f

Browse files
Merge pull request #1031 from r-lib/issue-1027
Run some tests sequentially
2 parents b80f5fb + ddba306 commit 38e4b1f

File tree

6 files changed

+64
-45
lines changed

6 files changed

+64
-45
lines changed

R/testing.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,11 @@ test_transformers_drop <- function(transformers) {
377377
}
378378
})
379379
}
380+
381+
382+
skip_during_parallel <- function() {
383+
Sys.getenv("STYLER_TEST_IS_TRULY_PARALLEL", TRUE) %>%
384+
toupper() %>%
385+
as.logical() %>%
386+
testthat::skip_if()
387+
}

tests/testthat.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
library(testthat)
22
library(styler)
3+
test_check("styler") # checks multiple files, in parallel
34

4-
test_check("styler")
5+
# checks file one by one, not parallel
6+
Sys.setenv(STYLER_TEST_IS_TRULY_PARALLEL = FALSE)
7+
test_file("testthat/test-cache-high-level-api.R")
8+
test_file("testthat/tests-cache-require-serial.R")

tests/testthat/test-cache-high-level-api.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ test_that("activated cache brings speedup on style_file() API", {
22
local_test_setup()
33
skip_on_cran()
44
skip_on_covr()
5+
skip_during_parallel()
56
n <- n_times_faster_with_cache(
67
test_path("reference-objects/caching.R"),
78
test_path("reference-objects/caching.R"),
@@ -27,6 +28,7 @@ text <- c(
2728
test_that("activated cache brings speedup on style_text() API on character vector", {
2829
skip_on_cran()
2930
skip_on_covr()
31+
skip_during_parallel()
3032
n <- n_times_faster_with_cache(
3133
text, text,
3234
fun = style_text
@@ -37,6 +39,7 @@ test_that("activated cache brings speedup on style_text() API on character vecto
3739
test_that("activated cache brings speedup on style_text() API on character scalar", {
3840
skip_on_cran()
3941
skip_on_covr()
42+
skip_during_parallel()
4043
text2 <- paste0(text, collapse = "\n")
4144

4245
n <- n_times_faster_with_cache(
@@ -56,6 +59,7 @@ test_that("trailing line breaks are ignored for caching", {
5659
expect_equal(cache_info(format = "tabular")$n, 3)
5760
skip_on_cran()
5861
skip_on_covr()
62+
skip_during_parallel()
5963
n <- n_times_faster_with_cache(text1, text2)
6064
expect_gt(n, 55)
6165
})
@@ -69,6 +73,7 @@ test_that("trailing line breaks are ignored for caching in one scalar", {
6973
expect_equal(cache_info(format = "tabular")$n, 3)
7074
skip_on_cran()
7175
skip_on_covr()
76+
skip_during_parallel()
7277
n <- n_times_faster_with_cache(text1, text2)
7378
expect_gt(n, 55)
7479
})
@@ -85,14 +90,15 @@ test_that("trailing line breaks are ignored for caching in one scalar", {
8590
expect_equal(cache_info(format = "tabular")$n, 3)
8691
skip_on_cran()
8792
skip_on_covr()
93+
skip_during_parallel()
8894
n <- n_times_faster_with_cache(text1, text2)
8995
expect_gt(n, 55)
9096
})
9197

9298
test_that("speedup higher when cached roxygen example code is multiple expressions", {
9399
skip_on_cran()
94100
skip_on_covr()
95-
101+
skip_during_parallel()
96102
text_long <- c(
97103
"#' Roxygen",
98104
"#' Comment",
@@ -132,6 +138,7 @@ test_that("speedup higher when cached roxygen example code is multiple expressio
132138
test_that("no speedup when tranformer changes", {
133139
skip_on_cran()
134140
skip_on_covr()
141+
skip_during_parallel()
135142
local_test_setup()
136143
t1 <- tidyverse_style()
137144
first <- system.time(style_text(text, transformers = t1))
@@ -145,6 +152,7 @@ test_that("unactivated cache does not bring speedup", {
145152
skip_on_cran()
146153
skip_on_covr()
147154
local_test_setup()
155+
skip_during_parallel()
148156
first <- system.time(style_file(test_path("reference-objects/caching.R")))
149157
second <- system.time(style_file(test_path("reference-objects/caching.R")))
150158
expect_false(first["elapsed"] / 4 > second["elapsed"])

tests/testthat/test-cache-interaction-roxygen-code-examples.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ test_that("roxzgen code examples are written to cache as both individual express
4242
)
4343
})
4444

45-
46-
test_that("roxzgen code examples are written to cache as whole expressions bring speedgain", {
47-
skip_on_cran()
48-
local_test_setup(cache = TRUE)
49-
text <- readLines(test_path("cache-with-r-cache/roxygen-cache-1.R"))
50-
first <- system.time(styled <- style_text(text))
51-
# don't use full cache, only roxygen cache
52-
styled[1] <- "#' This is a nother text"
53-
second <- system.time(style_text(styled))
54-
expect_gt(first["elapsed"], 4 * second["elapsed"])
55-
})
56-
5745
test_that("cache is deactivated at end of caching related testthat file", {
5846
expect_false(cache_is_activated())
5947
})

tests/testthat/test-cache-with-r-cache.R

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,6 @@ test_that("Cache management works", {
2525
expect_error(cache_clear("testthat", ask = FALSE), NA)
2626
})
2727

28-
test_that("top-level test: Caches top-level expressions efficiently on style_text()", {
29-
local_test_setup(cache = TRUE)
30-
text <- test_path("cache-with-r-cache/mlflow-1-in.R") %>%
31-
readLines()
32-
benchmark <- system.time(text_styled <- as.character(style_text(text)))
33-
expect_equal(text, text_styled)
34-
full_cached_benchmark <- system.time(text_styled2 <- as.character(style_text(text_styled)))
35-
expect_equal(text, text_styled2)
36-
37-
# modify one function declaration
38-
text_styled[2] <- gsub(")", " )", text_styled[2], fixed = TRUE)
39-
partially_cached_benchmark <- system.time(
40-
text_cached_partially <- as.character(style_text(text_styled))
41-
)
42-
expect_equal(text, text_cached_partially)
43-
cache_deactivate()
44-
not_cached_benchmark <- system.time(
45-
text_not_cached <- as.character(style_text(text_styled))
46-
)
47-
expect_equal(text, text_not_cached)
48-
49-
skip_on_cran()
50-
skip_on_covr()
51-
expect_lt(
52-
partially_cached_benchmark["elapsed"] * 2.4,
53-
not_cached_benchmark["elapsed"]
54-
)
55-
expect_lt(full_cached_benchmark["elapsed"] * 45, benchmark["elapsed"])
56-
})
57-
58-
5928
test_that("cached expressions are displayed propperly", {
6029
skip_if(getRversion() < "4.2")
6130

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
test_that("top-level test: Caches top-level expressions efficiently on style_text()", {
3+
local_test_setup(cache = TRUE)
4+
text <- test_path("cache-with-r-cache/mlflow-1-in.R") %>%
5+
readLines()
6+
benchmark <- system.time(text_styled <- as.character(style_text(text)))
7+
expect_equal(text, text_styled)
8+
full_cached_benchmark <- system.time(text_styled2 <- as.character(style_text(text_styled)))
9+
expect_equal(text, text_styled2)
10+
11+
# modify one function declaration
12+
text_styled[2] <- gsub(")", " )", text_styled[2], fixed = TRUE)
13+
partially_cached_benchmark <- system.time(
14+
text_cached_partially <- as.character(style_text(text_styled))
15+
)
16+
expect_equal(text, text_cached_partially)
17+
cache_deactivate()
18+
not_cached_benchmark <- system.time(
19+
text_not_cached <- as.character(style_text(text_styled))
20+
)
21+
expect_equal(text, text_not_cached)
22+
23+
skip_on_cran()
24+
skip_on_covr()
25+
expect_lt(
26+
partially_cached_benchmark["elapsed"] * 2.4,
27+
not_cached_benchmark["elapsed"]
28+
)
29+
expect_lt(full_cached_benchmark["elapsed"] * 45, benchmark["elapsed"])
30+
})
31+
32+
33+
test_that("roxzgen code examples are written to cache as whole expressions bring speedgain", {
34+
skip_on_cran()
35+
local_test_setup(cache = TRUE)
36+
text <- readLines(test_path("cache-with-r-cache/roxygen-cache-1.R"))
37+
first <- system.time(styled <- style_text(text))
38+
# don't use full cache, only roxygen cache
39+
styled[1] <- "#' This is a nother text"
40+
second <- system.time(style_text(styled))
41+
expect_gt(first["elapsed"], 4 * second["elapsed"])
42+
})

0 commit comments

Comments
 (0)