diff --git a/tests/testthat/_snaps/methods.md b/tests/testthat/_snaps/methods.md new file mode 100644 index 000000000..27f3acf4b --- /dev/null +++ b/tests/testthat/_snaps/methods.md @@ -0,0 +1,108 @@ +# print.lint, print.lints support optional message wrapping : width = 10 + + Code + print(lints, width = width) + Output + :1:1: + warning: + [test_linter] + The + quick + brown + fox + jumps + over + the + lazy + dog. + a + ^ + +--- + + Code + print(lints) + Output + :1:1: + warning: + [test_linter] + The + quick + brown + fox + jumps + over + the + lazy + dog. + a + ^ + +# print.lint, print.lints support optional message wrapping : width = 20 + + Code + print(lints, width = width) + Output + :1:1: + warning: + [test_linter] + The quick brown + fox jumps over + the lazy dog. + a + ^ + +--- + + Code + print(lints) + Output + :1:1: + warning: + [test_linter] + The quick brown + fox jumps over + the lazy dog. + a + ^ + +# print.lint, print.lints support optional message wrapping : width = 40 + + Code + print(lints, width = width) + Output + :1:1: warning: [test_linter] The + quick brown fox jumps over the lazy + dog. + a + ^ + +--- + + Code + print(lints) + Output + :1:1: warning: [test_linter] The + quick brown fox jumps over the lazy + dog. + a + ^ + +# print.lint, print.lints support optional message wrapping : width = 80 + + Code + print(lints, width = width) + Output + :1:1: warning: [test_linter] The quick brown fox jumps over the lazy dog. + a + ^ + +--- + + Code + print(lints) + Output + :1:1: warning: [test_linter] The quick brown fox jumps over the lazy dog. + a + ^ + diff --git a/tests/testthat/test-lint.R b/tests/testthat/test-lint.R index 05337c8d8..1369360bf 100644 --- a/tests/testthat/test-lint.R +++ b/tests/testthat/test-lint.R @@ -105,7 +105,12 @@ test_that("lint() results do not depend on the position of the .lintr", { }) test_that("lint uses linter names", { - expect_lint("a = 2", list(linter = "bla"), linters = list(bla = assignment_linter()), parse_settings = FALSE) + expect_lint( + "a = 2", + list(linter = "bla"), + linters = list(bla = assignment_linter()), + parse_settings = FALSE + ) }) test_that("lint() results from file or text should be consistent", { diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index a79ac7591..0d003c597 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -170,6 +170,22 @@ local({ lints <- lint(text = "a", linters = test_linter()) lint <- lints[[1L]] + widths <- c(10L, 20L, 40L, 80L) + test_names <- paste0(": width = ", widths) + + patrick::with_parameters_test_that( + "print.lint, print.lints support optional message wrapping", + { + expect_snapshot(print(lints, width = width)) + + withr::with_options(c(lintr.format_width = width), { + expect_snapshot(print(lints)) + }) + }, + .test_name = test_names, + width = widths + ) + wrapped_strings <- c( "[test_linter]\n The\n quick\n brown\n fox\n jumps\n over\n the\n lazy\n dog.", "[test_linter]\n The quick brown\n fox jumps over\n the lazy dog.", @@ -178,22 +194,18 @@ local({ ) patrick::with_parameters_test_that( - "format.lint, format.lints, print.lint, print.lints support optional message wrapping", + "format.lint, format.lints support optional message wrapping", { expect_match(format(lint, width = width), wrapped_string, fixed = TRUE) expect_match(format(lints, width = width), wrapped_string, fixed = TRUE) - expect_output(print(lint, width = width), wrapped_string, fixed = TRUE) - expect_output(print(lints, width = width), wrapped_string, fixed = TRUE) withr::with_options(c(lintr.format_width = width), { expect_match(format(lint), wrapped_string, fixed = TRUE) expect_match(format(lints), wrapped_string, fixed = TRUE) - expect_output(print(lint), wrapped_string, fixed = TRUE) - expect_output(print(lints), wrapped_string, fixed = TRUE) }) }, - .test_name = c(10L, 20L, 40L, 80L), - width = c(10L, 20L, 40L, 80L), + .test_name = test_names, + width = widths, wrapped_string = wrapped_strings ) })