Skip to content

Commit 740d56a

Browse files
testing infrastructure
1 parent 4f706af commit 740d56a

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

R/testing-public-api.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,24 @@ catch_style_file_output <- function(file_in = c(
3737
ls_testable_encodings <- function() {
3838
c("non-utf8", if (cli::is_utf8_output()) "utf8")
3939
}
40+
41+
#' Test the dry argument
42+
#' @param path A path to pass to the `styler`.
43+
#' @param styler A function that takes `path`, typically a user exposed styler
44+
#' function that has side effects, like [style_file()].
45+
#' @keywords internal
46+
test_dry <- function(path, styler, styled = FALSE) {
47+
before <- readLines(path)
48+
summary <- styler(path, dry = "on")
49+
checker <- ifelse(styled, expect_false, expect_true)
50+
checker(summary$changed)
51+
expect_true(identical(before, readLines(path)))
52+
53+
if (styled) {
54+
expect_error(styler(path, dry = "fail"), NA)
55+
} else {
56+
expect_error(styler(path, dry = "fail"), "would be modified")
57+
}
58+
expect_error(styler(path, dry = "other option"), "one of")
59+
60+
}

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Addin
22
Addins
3+
api
34
AppVeyor
45
apriori
56
arg

man/test_dry.Rd

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

0 commit comments

Comments
 (0)