Skip to content

Commit 730c7b6

Browse files
prepare for multi-file in and output
1 parent d3beb91 commit 730c7b6

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
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, encoding) {
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ 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"
@@ -168,7 +168,7 @@ 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"
173173
), encoding = encoding)
174174
expect_known_value(
@@ -181,7 +181,7 @@ 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"
186186
), encoding = encoding)
187187
expect_known_value(
@@ -202,7 +202,7 @@ test_that("Messages can be suppressed", {
202202
withr::with_options(
203203
list(cli.unicode = encoding == "utf8", styler.quiet = TRUE),
204204
{
205-
output <- catch_style_file_output(c(
205+
output <- catch_style_file_output(file.path(
206206
"public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R"
207207
), encoding = encoding)
208208
expect_equal(output, character(0))

0 commit comments

Comments
 (0)