Skip to content

Commit d5b8b0e

Browse files
Merge pull request #701 from lorenzwalthert/preprare-parallel
- Prepare for multi-file in and output (#701).
2 parents d3beb91 + 9cf0288 commit d5b8b0e

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

R/testing-public-api.R

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#' Capture and post-process the output of `style_file` without causing side
22
#' effects
33
#'
4-
#' @param file_in A vector passed to [testthat_file()] to construct the path
4+
#' @param file_in A vector with paths relative to `tests/testthat` the path
55
#' to the reference file.
66
#' @return
7-
#' A character vector with the captured output of [style_file()] called on
7+
#' A list. Each element is a character vector with the captured output of
8+
#' [style_file()] called on
89
#' `file_in` ran in a temp dir to avoid side effects on the input file (because
910
#' the next time the test would ran, the file would not need styling). The
1011
#' styling is carried out with a temporary working directory change to keep
@@ -16,13 +17,8 @@
1617
#' how many characters the path of the temporary directory has.
1718
#' @importFrom utils capture.output
1819
#' @keywords internal
19-
catch_style_file_output <- function(file_in = c(
20-
"public-api",
21-
"xyzdir-dirty",
22-
"dirty-sample-with-scope-tokens.R"
23-
),
24-
encoding) {
25-
file_in <- do.call(testthat_file, as.list(file_in))
20+
catch_style_file_output <- function(file_in) {
21+
file_in <- testthat_file(file_in)
2622
temp_path <- copy_to_tempdir(file_in)
2723
raw_output <- withr::with_dir(
2824
dirname(temp_path),

man/catch_style_file_output.Rd

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-public_api.R

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ test_that("messages (via cat()) of style_file are correct", {
153153
list(cli.unicode = encoding == "utf8"),
154154
{
155155
# Message if scope > line_breaks and code changes
156-
output <- catch_style_file_output(c(
156+
output <- catch_style_file_output(file.path(
157157
"public-api",
158158
"xyzdir-dirty",
159159
"dirty-sample-with-scope-tokens.R"
160-
), encoding = encoding)
160+
))
161161
expect_known_value(
162162
output,
163163
testthat_file(paste0(
@@ -168,9 +168,9 @@ test_that("messages (via cat()) of style_file are correct", {
168168
)
169169

170170
# No message if scope > line_breaks and code does not change
171-
output <- catch_style_file_output(c(
171+
output <- catch_style_file_output(file.path(
172172
"public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R"
173-
), encoding = encoding)
173+
))
174174
expect_known_value(
175175
output,
176176
testthat_file(paste0(
@@ -181,9 +181,9 @@ test_that("messages (via cat()) of style_file are correct", {
181181
)
182182

183183
# No message if scope <= line_breaks even if code is changed.
184-
output <- catch_style_file_output(c(
184+
output <- catch_style_file_output(file.path(
185185
"public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R"
186-
), encoding = encoding)
186+
))
187187
expect_known_value(
188188
output,
189189
testthat_file(paste0(
@@ -198,17 +198,15 @@ test_that("messages (via cat()) of style_file are correct", {
198198
})
199199

200200
test_that("Messages can be suppressed", {
201-
for (encoding in ls_testable_encodings()) {
202201
withr::with_options(
203-
list(cli.unicode = encoding == "utf8", styler.quiet = TRUE),
202+
list(styler.quiet = TRUE),
204203
{
205-
output <- catch_style_file_output(c(
204+
output <- catch_style_file_output(file.path(
206205
"public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R"
207-
), encoding = encoding)
206+
))
208207
expect_equal(output, character(0))
209208
}
210209
)
211-
}
212210
})
213211

214212
context("public API - Rmd in style_dir()")

0 commit comments

Comments
 (0)