From 9cc9a8a43e599410df412bd0120a5bb3717432f4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Thu, 26 May 2022 11:02:47 +0200 Subject: [PATCH 01/17] Upgrade to testthat 3e Closes #783 --- DESCRIPTION | 3 ++- .../renvpkg/tests/testthat/test-package-xyz.R | 2 +- .../tests/testthat/test-package-xyz.R | 2 +- .../tests/testthat/test-package-xyz.R | 2 +- .../tests/testthat/test-package-xyz.R | 2 +- .../tests/testthat/test-package-xyz.R | 2 +- tests/testthat/test-create_token.R | 2 +- tests/testthat/test-create_tree.R | 2 +- tests/testthat/test-curly-curly.R | 2 +- tests/testthat/test-encoding.R | 2 +- tests/testthat/test-exception_handling.R | 2 +- tests/testthat/test-helpers.R | 2 +- .../testthat/test-identify-roxygen-examples.R | 2 +- tests/testthat/test-indention_curly.R | 2 +- tests/testthat/test-indention_fun_calls.R | 2 +- tests/testthat/test-indention_multiple.R | 2 +- tests/testthat/test-indention_operators.R | 2 +- .../testthat/test-indention_round_brackets.R | 4 ++-- .../test-insertion_comment_interaction.R | 2 +- tests/testthat/test-line_breaks_and_other.R | 2 +- tests/testthat/test-line_breaks_fun_call.R | 2 +- tests/testthat/test-math_token_spacing.R | 2 +- tests/testthat/test-multiple_expressions.R | 2 +- tests/testthat/test-parse_comments.R | 2 +- tests/testthat/test-parsing.R | 2 +- tests/testthat/test-public_api.R | 20 +++++++++---------- tests/testthat/test-relocate_eq_assign.R | 2 +- tests/testthat/test-rmd.R | 2 +- tests/testthat/test-rnw.R | 2 +- tests/testthat/test-roundtrip.R | 2 +- .../testthat/test-roxygen-examples-complete.R | 2 +- tests/testthat/test-roxygen-examples-parse.R | 2 +- tests/testthat/test-scope-AsIs.R | 2 +- tests/testthat/test-scope-character.R | 2 +- tests/testthat/test-serialize_tests.R | 2 +- tests/testthat/test-spacing.R | 2 +- tests/testthat/test-square_brackets.R | 2 +- tests/testthat/test-start_line.R | 2 +- tests/testthat/test-strict.R | 2 +- tests/testthat/test-tidyeval.R | 2 +- tests/testthat/test-token_adding_removing.R | 2 +- tests/testthat/test-unary.R | 2 +- tests/testthat/test-unindention.R | 2 +- tests/testthat/test-unindention_regex.R | 2 +- tests/testthat/test-utils.R | 6 +++--- tests/testthat/test-varia.R | 2 +- 46 files changed, 59 insertions(+), 58 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ebad6820..62d162927 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,13 +39,14 @@ Suggests: rmarkdown, roxygen2, rstudioapi (>= 0.7), - testthat (>= 2.1.0) + testthat (>= 3.0.0) VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate", "pkgapi::api_roclet")) RoxygenNote: 7.1.2 +Config/testthat/edition: 3 Collate: 'addins.R' 'communicate.R' diff --git a/tests/testthat/public-api/renvpkg/tests/testthat/test-package-xyz.R b/tests/testthat/public-api/renvpkg/tests/testthat/test-package-xyz.R index 23dadd10a..88b20a597 100644 --- a/tests/testthat/public-api/renvpkg/tests/testthat/test-package-xyz.R +++ b/tests/testthat/public-api/renvpkg/tests/testthat/test-package-xyz.R @@ -1,4 +1,4 @@ -context("testing styler on package") + test_that("hi there", { I(am(a(package(x)))) diff --git a/tests/testthat/public-api/xyzpackage-qmd/tests/testthat/test-package-xyz.R b/tests/testthat/public-api/xyzpackage-qmd/tests/testthat/test-package-xyz.R index 23dadd10a..88b20a597 100644 --- a/tests/testthat/public-api/xyzpackage-qmd/tests/testthat/test-package-xyz.R +++ b/tests/testthat/public-api/xyzpackage-qmd/tests/testthat/test-package-xyz.R @@ -1,4 +1,4 @@ -context("testing styler on package") + test_that("hi there", { I(am(a(package(x)))) diff --git a/tests/testthat/public-api/xyzpackage-rmd/tests/testthat/test-package-xyz.R b/tests/testthat/public-api/xyzpackage-rmd/tests/testthat/test-package-xyz.R index 23dadd10a..88b20a597 100644 --- a/tests/testthat/public-api/xyzpackage-rmd/tests/testthat/test-package-xyz.R +++ b/tests/testthat/public-api/xyzpackage-rmd/tests/testthat/test-package-xyz.R @@ -1,4 +1,4 @@ -context("testing styler on package") + test_that("hi there", { I(am(a(package(x)))) diff --git a/tests/testthat/public-api/xyzpackage-rnw/tests/testthat/test-package-xyz.R b/tests/testthat/public-api/xyzpackage-rnw/tests/testthat/test-package-xyz.R index 23dadd10a..88b20a597 100644 --- a/tests/testthat/public-api/xyzpackage-rnw/tests/testthat/test-package-xyz.R +++ b/tests/testthat/public-api/xyzpackage-rnw/tests/testthat/test-package-xyz.R @@ -1,4 +1,4 @@ -context("testing styler on package") + test_that("hi there", { I(am(a(package(x)))) diff --git a/tests/testthat/public-api/xyzpackage/tests/testthat/test-package-xyz.R b/tests/testthat/public-api/xyzpackage/tests/testthat/test-package-xyz.R index 23dadd10a..88b20a597 100644 --- a/tests/testthat/public-api/xyzpackage/tests/testthat/test-package-xyz.R +++ b/tests/testthat/public-api/xyzpackage/tests/testthat/test-package-xyz.R @@ -1,4 +1,4 @@ -context("testing styler on package") + test_that("hi there", { I(am(a(package(x)))) diff --git a/tests/testthat/test-create_token.R b/tests/testthat/test-create_token.R index 4f28fd641..6fd22dd2d 100644 --- a/tests/testthat/test-create_token.R +++ b/tests/testthat/test-create_token.R @@ -1,4 +1,4 @@ -context("token insertion") + test_that("can create a token that has relevant columns", { pd_names <- c( diff --git a/tests/testthat/test-create_tree.R b/tests/testthat/test-create_tree.R index 21f3d3be8..b3b0ebb7f 100644 --- a/tests/testthat/test-create_tree.R +++ b/tests/testthat/test-create_tree.R @@ -1,4 +1,4 @@ -context("test tree creation") + test_that("create_trees outputs identical structure if trees have same structure", { skip_if_not_installed("DiagrammeR") diff --git a/tests/testthat/test-curly-curly.R b/tests/testthat/test-curly-curly.R index 040f039b7..d61299e75 100644 --- a/tests/testthat/test-curly-curly.R +++ b/tests/testthat/test-curly-curly.R @@ -1,4 +1,4 @@ -context("curly-curly") + test_that("curly-culry", { expect_warning(test_collection("curly-curly", diff --git a/tests/testthat/test-encoding.R b/tests/testthat/test-encoding.R index fe7d592a4..695890871 100644 --- a/tests/testthat/test-encoding.R +++ b/tests/testthat/test-encoding.R @@ -1,4 +1,4 @@ -context("non-ASCII characters are handled properly") + test_that("non-ASCII characters are handled properly for text styling", { expect_equal( diff --git a/tests/testthat/test-exception_handling.R b/tests/testthat/test-exception_handling.R index da4dd4658..607c0adde 100644 --- a/tests/testthat/test-exception_handling.R +++ b/tests/testthat/test-exception_handling.R @@ -1,4 +1,4 @@ -context("Exception handling") + test_that("style_text returns custom error", { expect_error(style_text("a <- 3 4"), "unexpected numeric constant") diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index f6728bbbe..d101ed82e 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -1,4 +1,4 @@ -context("various helpers") + test_that("can construct and print vertical", { expect_error(construct_vertical(c("1 + 1", "nw")), NA) diff --git a/tests/testthat/test-identify-roxygen-examples.R b/tests/testthat/test-identify-roxygen-examples.R index 1db5349f7..8eee143e2 100644 --- a/tests/testthat/test-identify-roxygen-examples.R +++ b/tests/testthat/test-identify-roxygen-examples.R @@ -1,4 +1,4 @@ -context("test-roxygen-examples-identify.R") + #' Things to consider: #' * one function declaration or many diff --git a/tests/testthat/test-indention_curly.R b/tests/testthat/test-indention_curly.R index 448ac209a..3d024a946 100644 --- a/tests/testthat/test-indention_curly.R +++ b/tests/testthat/test-indention_curly.R @@ -1,4 +1,4 @@ -context("indent curly brackets") + test_that("indention on one-liner curley only is not changed", { expect_warning(test_collection("indention_curly_brackets", diff --git a/tests/testthat/test-indention_fun_calls.R b/tests/testthat/test-indention_fun_calls.R index a0586b82e..f44c037b8 100644 --- a/tests/testthat/test-indention_fun_calls.R +++ b/tests/testthat/test-indention_fun_calls.R @@ -1,4 +1,4 @@ -context("test-indention_fun_calls.R") + test_that("edge cases work", { expect_warning(test_collection("indention_fun_calls", diff --git a/tests/testthat/test-indention_multiple.R b/tests/testthat/test-indention_multiple.R index cfa7b596f..a99634f3d 100644 --- a/tests/testthat/test-indention_multiple.R +++ b/tests/testthat/test-indention_multiple.R @@ -1,4 +1,4 @@ -context("test indent multiple") + test_that("multiple round brackets don't cause extraindention", { expect_warning(test_collection("indention_multiple", diff --git a/tests/testthat/test-indention_operators.R b/tests/testthat/test-indention_operators.R index 94697add7..3e62f85f8 100644 --- a/tests/testthat/test-indention_operators.R +++ b/tests/testthat/test-indention_operators.R @@ -1,4 +1,4 @@ -context("indention operators") + test_that("pipe is indended correctly", { expect_warning(test_collection("indention_operators", diff --git a/tests/testthat/test-indention_round_brackets.R b/tests/testthat/test-indention_round_brackets.R index ce222d926..c0c6a9409 100644 --- a/tests/testthat/test-indention_round_brackets.R +++ b/tests/testthat/test-indention_round_brackets.R @@ -1,4 +1,4 @@ -context("Function calls with round brackets") + test_that("one-line function call yields correct indention", { expect_warning(test_collection("indention_round_brackets", @@ -19,7 +19,7 @@ test_that(paste("multi-line function call yields correct indention"), { ## ............................................................................ -context("grouping arithmetic expressions with round brackets. ") + # Does NOT cover indention by operators such as +" diff --git a/tests/testthat/test-insertion_comment_interaction.R b/tests/testthat/test-insertion_comment_interaction.R index 25f633d46..698b58d03 100644 --- a/tests/testthat/test-insertion_comment_interaction.R +++ b/tests/testthat/test-insertion_comment_interaction.R @@ -1,4 +1,4 @@ -context("test comment token insertion interaction") + ## ............................................................................ ## strict = TRUE #### diff --git a/tests/testthat/test-line_breaks_and_other.R b/tests/testthat/test-line_breaks_and_other.R index 13c043cab..f410d25bb 100644 --- a/tests/testthat/test-line_breaks_and_other.R +++ b/tests/testthat/test-line_breaks_and_other.R @@ -1,4 +1,4 @@ -context("linebreaking added / removed correctly") + test_that("line breaks involing curly brackets", { expect_warning(test_collection("line_breaks_and_other", "curly", diff --git a/tests/testthat/test-line_breaks_fun_call.R b/tests/testthat/test-line_breaks_fun_call.R index 826c254e6..21236318b 100644 --- a/tests/testthat/test-line_breaks_fun_call.R +++ b/tests/testthat/test-line_breaks_fun_call.R @@ -1,4 +1,4 @@ -context("line breaks for function calls") + test_that("line breaks work in general", { expect_warning(test_collection("line_breaks_fun_call", "token_dependent_mixed", diff --git a/tests/testthat/test-math_token_spacing.R b/tests/testthat/test-math_token_spacing.R index c98aa0ab4..9b1aa9009 100644 --- a/tests/testthat/test-math_token_spacing.R +++ b/tests/testthat/test-math_token_spacing.R @@ -1,4 +1,4 @@ -context("math token spacing") + test_that("invalid tokens return error", { expect_error(test_collection( diff --git a/tests/testthat/test-multiple_expressions.R b/tests/testthat/test-multiple_expressions.R index e21660e8e..783f012dd 100644 --- a/tests/testthat/test-multiple_expressions.R +++ b/tests/testthat/test-multiple_expressions.R @@ -1,5 +1,5 @@ library("testthat") -context("multiple expressions") + test_that("simple multiple expressions are styled correctly", { expect_warning(test_collection("multiple_expressions", diff --git a/tests/testthat/test-parse_comments.R b/tests/testthat/test-parse_comments.R index f86635a0f..8c25496f6 100644 --- a/tests/testthat/test-parse_comments.R +++ b/tests/testthat/test-parse_comments.R @@ -1,5 +1,5 @@ library("testthat") -context("correctly treats comments") + test_that("spacing within comments is done correctly", { expect_warning(test_collection("parse_comments", diff --git a/tests/testthat/test-parsing.R b/tests/testthat/test-parsing.R index faf188cfa..c5cb2463a 100644 --- a/tests/testthat/test-parsing.R +++ b/tests/testthat/test-parsing.R @@ -1,4 +1,4 @@ -context("circumvent parsing bugs") + test_that("repreated parsing solves wrong parent assignment", { expect_warning( diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 7f351e84f..35b82501c 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -1,4 +1,4 @@ -context("public API") + @@ -131,7 +131,7 @@ test_that("styler does not return error when there is no file to style", { ), NA)) }) -context("public API - Rmd in style_file()") + test_that("styler can style Rmd file", { expect_false({ @@ -195,7 +195,7 @@ test_that("styler handles malformed Rmd file and invalid R code in chunk", { )) }) -context("messages are correct") + test_that("messages (via cat()) of style_file are correct", { @@ -209,7 +209,7 @@ test_that("messages (via cat()) of style_file are correct", { "xyzdir-dirty", "dirty-sample-with-scope-tokens.R" )) - expect_known_value( + expect_sknown_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/dirty-reference-with-scope-tokens-", @@ -222,7 +222,7 @@ test_that("messages (via cat()) of style_file are correct", { output <- catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R" )) - expect_known_value( + expect_sknown_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/clean-reference-with-scope-tokens-", @@ -235,7 +235,7 @@ test_that("messages (via cat()) of style_file are correct", { output <- catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R" )) - expect_known_value( + expect_sknown_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-", @@ -260,7 +260,7 @@ test_that("Messages can be suppressed", { ) }) -context("public API - Rmd in style_dir()") + test_that("styler can style R, Rmd and Rmarkdown files via style_dir()", { msg <- capture_output( @@ -295,7 +295,7 @@ test_that("styler can style .r and .rmd files only via style_dir()", { expect_false(any(grepl("random-rmd-script.Rmarkdown", msg, fixed = TRUE))) }) -context("public API - Rmd in style_pkg()") + test_that("styler can style R and Rmd files via style_pkg()", { msg <- capture_output( @@ -372,7 +372,7 @@ test_that("insufficient R version returns error", { expect_error(stop_insufficient_r_version()) }) -context("public API - Rnw in style_file()") + test_that("styler can style Rnw file", { @@ -400,7 +400,7 @@ test_that("styler handles malformed Rnw file and invalid R code in chunk", { )) }) -context("public API - Rnw in style_pkg()") + test_that("styler can style R, Rmd and Rnw files via style_pkg()", { msg <- capture_output( diff --git a/tests/testthat/test-relocate_eq_assign.R b/tests/testthat/test-relocate_eq_assign.R index 0395904a0..9718c5655 100644 --- a/tests/testthat/test-relocate_eq_assign.R +++ b/tests/testthat/test-relocate_eq_assign.R @@ -1,4 +1,4 @@ -context("EQ_ASSIGN relocation") + # Tests code in R/relevel.R test_that("tree hierarchy is the same no matter whether = or <- is used", { skip_if_not_installed("DiagrammeR") diff --git a/tests/testthat/test-rmd.R b/tests/testthat/test-rmd.R index fdcec529d..6ff803d80 100644 --- a/tests/testthat/test-rmd.R +++ b/tests/testthat/test-rmd.R @@ -1,4 +1,4 @@ -context("rmd") + test_that("can style .Rmd files", { expect_warning(test_collection("rmd", "simple", diff --git a/tests/testthat/test-rnw.R b/tests/testthat/test-rnw.R index ac7df86e6..1a9158d3f 100644 --- a/tests/testthat/test-rnw.R +++ b/tests/testthat/test-rnw.R @@ -1,4 +1,4 @@ -context("rnw") + test_that("can style .Rnw files", { expect_warning(test_collection( diff --git a/tests/testthat/test-roundtrip.R b/tests/testthat/test-roundtrip.R index 52b172803..692a5c27c 100644 --- a/tests/testthat/test-roundtrip.R +++ b/tests/testthat/test-roundtrip.R @@ -1,4 +1,4 @@ -context("roundtrip works") + test_that("parse_tree_must_be_identical works", { diff --git a/tests/testthat/test-roxygen-examples-complete.R b/tests/testthat/test-roxygen-examples-complete.R index dba323734..658b17510 100644 --- a/tests/testthat/test-roxygen-examples-complete.R +++ b/tests/testthat/test-roxygen-examples-complete.R @@ -1,4 +1,4 @@ -context("test-roxygen-examples-complete") + test_that("analogous to test-roxygen-examples-complete", { expect_warning(test_collection( diff --git a/tests/testthat/test-roxygen-examples-parse.R b/tests/testthat/test-roxygen-examples-parse.R index ceee270af..d733b1585 100644 --- a/tests/testthat/test-roxygen-examples-parse.R +++ b/tests/testthat/test-roxygen-examples-parse.R @@ -1,4 +1,4 @@ -context("test-roxygen-examples-parse") + test_that("simple examples can be parsed", { expected_out <- c("\n", "x <- 1\n") diff --git a/tests/testthat/test-scope-AsIs.R b/tests/testthat/test-scope-AsIs.R index 491fbaef3..97eec4ebf 100644 --- a/tests/testthat/test-scope-AsIs.R +++ b/tests/testthat/test-scope-AsIs.R @@ -1,4 +1,4 @@ -context("scope AsIs") + test_that("no indention manipulation but spaces manipulation", { expect_warning(test_collection( diff --git a/tests/testthat/test-scope-character.R b/tests/testthat/test-scope-character.R index 69096ffa3..256f7d670 100644 --- a/tests/testthat/test-scope-character.R +++ b/tests/testthat/test-scope-character.R @@ -1,4 +1,4 @@ -context("scope character") + test_that("no indention manipulation but spaces manipulation", { expect_warning(test_collection( diff --git a/tests/testthat/test-serialize_tests.R b/tests/testthat/test-serialize_tests.R index 94ae3bc2e..2b858a77a 100644 --- a/tests/testthat/test-serialize_tests.R +++ b/tests/testthat/test-serialize_tests.R @@ -1,4 +1,4 @@ -context("test testing functions") + test_that("No files to compare returns error", { expect_error(test_collection("serialize_tests", "xyz", diff --git a/tests/testthat/test-spacing.R b/tests/testthat/test-spacing.R index 2048933d4..9caadf9e4 100644 --- a/tests/testthat/test-spacing.R +++ b/tests/testthat/test-spacing.R @@ -1,4 +1,4 @@ -context("spacing") + test_that("curly braces", { expect_warning(test_collection( diff --git a/tests/testthat/test-square_brackets.R b/tests/testthat/test-square_brackets.R index 52cc75383..ccad96f0d 100644 --- a/tests/testthat/test-square_brackets.R +++ b/tests/testthat/test-square_brackets.R @@ -1,4 +1,4 @@ -context("indention square brackets") + test_that("square brackets cause indention", { expect_warning(test_collection( diff --git a/tests/testthat/test-start_line.R b/tests/testthat/test-start_line.R index 1994a2b53..f154dc555 100644 --- a/tests/testthat/test-start_line.R +++ b/tests/testthat/test-start_line.R @@ -1,4 +1,4 @@ -context("start token") + test_that("leading spaces are preserved at start of text", { expect_warning(test_collection("start_line", diff --git a/tests/testthat/test-strict.R b/tests/testthat/test-strict.R index 7e9c073b8..774096980 100644 --- a/tests/testthat/test-strict.R +++ b/tests/testthat/test-strict.R @@ -1,4 +1,4 @@ -context("test strict") + test_that("can style example source file with strict = TRUE", { expect_warning(test_collection( diff --git a/tests/testthat/test-tidyeval.R b/tests/testthat/test-tidyeval.R index e98ede417..76b7a2457 100644 --- a/tests/testthat/test-tidyeval.R +++ b/tests/testthat/test-tidyeval.R @@ -1,4 +1,4 @@ -context("tidyeval") + test_that("no spaces within bang-bang operator !!!", { expect_warning(test_collection("tidyeval", "bang_bang", diff --git a/tests/testthat/test-token_adding_removing.R b/tests/testthat/test-token_adding_removing.R index 3e8165b83..cd0026a0f 100644 --- a/tests/testthat/test-token_adding_removing.R +++ b/tests/testthat/test-token_adding_removing.R @@ -1,4 +1,4 @@ -context("adding / removing token") + test_that("other manipulations are correct (add braces, semi-colon etc.)", { expect_warning(test_collection("token_adding_removing", "mixed_token", diff --git a/tests/testthat/test-unary.R b/tests/testthat/test-unary.R index 26cb1f143..8fe52eb0c 100644 --- a/tests/testthat/test-unary.R +++ b/tests/testthat/test-unary.R @@ -1,4 +1,4 @@ -context("no spaces before unary operator") + test_that("no spaces before unary operator", { expect_warning(test_collection("unary_spacing", diff --git a/tests/testthat/test-unindention.R b/tests/testthat/test-unindention.R index 30e435ac6..cd06de29c 100644 --- a/tests/testthat/test-unindention.R +++ b/tests/testthat/test-unindention.R @@ -1,4 +1,4 @@ -context("unindention") + test_that("round brackets are unindented correctly", { expect_warning(test_collection("unindention", diff --git a/tests/testthat/test-unindention_regex.R b/tests/testthat/test-unindention_regex.R index 1790183bc..7e364fa46 100644 --- a/tests/testthat/test-unindention_regex.R +++ b/tests/testthat/test-unindention_regex.R @@ -1,4 +1,4 @@ -context("unindention regex") + test_that("forced regex token-dependent indention", { expect_warning(test_collection( "unindention_regex", "regex_force_with", diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 3d06222b9..b173ccd04 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,4 +1,4 @@ -context("test-utils") + test_that("non-comment-helpers", { pd <- compute_parse_data_nested("a <- # hi \n x %>% b()") @@ -8,13 +8,13 @@ test_that("non-comment-helpers", { }) test_that("files with and without blank EOF line are read correctly", { - expect_known_value( + expect_sknown_value( read_utf8(test_path("reference-objects/missing-blank-at-EOF.R")), test_path("reference-objects/return-read-utf8-missing-EOF"), update = getOption("styler.test_dir_writable", TRUE) ) - expect_known_value( + expect_sknown_value( read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R")), test_path("reference-objects/return-read-utf8-non-missing-EOF"), update = getOption("styler.test_dir_writable", TRUE) diff --git a/tests/testthat/test-varia.R b/tests/testthat/test-varia.R index 4519f4eae..422363a0d 100644 --- a/tests/testthat/test-varia.R +++ b/tests/testthat/test-varia.R @@ -1,4 +1,4 @@ -context("test-varia") + test_that("ensure_last_n_empty", { expect_equal( From 0d95261bf30227c0de44867122631268e7e601ab Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Thu, 26 May 2022 11:17:14 +0200 Subject: [PATCH 02/17] oops --- tests/testthat/test-public_api.R | 6 +++--- tests/testthat/test-utils.R | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 35b82501c..0d6775ae0 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -209,7 +209,7 @@ test_that("messages (via cat()) of style_file are correct", { "xyzdir-dirty", "dirty-sample-with-scope-tokens.R" )) - expect_sknown_value( + expect_known_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/dirty-reference-with-scope-tokens-", @@ -222,7 +222,7 @@ test_that("messages (via cat()) of style_file are correct", { output <- catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R" )) - expect_sknown_value( + expect_known_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/clean-reference-with-scope-tokens-", @@ -235,7 +235,7 @@ test_that("messages (via cat()) of style_file are correct", { output <- catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R" )) - expect_sknown_value( + expect_known_value( output, testthat_file(paste0( "public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-", diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b173ccd04..7b8e9a9f4 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -8,13 +8,13 @@ test_that("non-comment-helpers", { }) test_that("files with and without blank EOF line are read correctly", { - expect_sknown_value( + expect_known_value( read_utf8(test_path("reference-objects/missing-blank-at-EOF.R")), test_path("reference-objects/return-read-utf8-missing-EOF"), update = getOption("styler.test_dir_writable", TRUE) ) - expect_sknown_value( + expect_known_value( read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R")), test_path("reference-objects/return-read-utf8-non-missing-EOF"), update = getOption("styler.test_dir_writable", TRUE) From 38d27e7f418c6212d77d90359f0e0aaa13b6c475 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 12:14:32 +0200 Subject: [PATCH 03/17] `expect_known_value()`-> `expect_snapshot()` --- tests/testthat/_snaps/cache-with-r-cache.md | 30 ++++++++++++ tests/testthat/_snaps/public_api.md | 47 +++++++++++++++++++ tests/testthat/_snaps/utils.md | 24 ++++++++++ tests/testthat/test-cache-with-r-cache.R | 24 ++++------ tests/testthat/test-public_api.R | 52 +++++++-------------- tests/testthat/test-utils.R | 16 +++---- 6 files changed, 133 insertions(+), 60 deletions(-) create mode 100644 tests/testthat/_snaps/cache-with-r-cache.md create mode 100644 tests/testthat/_snaps/public_api.md create mode 100644 tests/testthat/_snaps/utils.md diff --git a/tests/testthat/_snaps/cache-with-r-cache.md b/tests/testthat/_snaps/cache-with-r-cache.md new file mode 100644 index 000000000..5a3a672dc --- /dev/null +++ b/tests/testthat/_snaps/cache-with-r-cache.md @@ -0,0 +1,30 @@ +# cached expressions are displayed propperly + + Code + cache_info[, c("n", "size", "last_modified", "activated")] + Output + # A tibble: 1 x 4 + n size last_modified activated + + 1 0 0 -Inf -Inf FALSE + +--- + + Code + cache_info[, c("n", "size", "activated")] + Output + # A tibble: 1 x 3 + n size activated + + 1 1 0 TRUE + +--- + + Code + cache_info[, c("n", "size", "activated")] + Output + # A tibble: 1 x 3 + n size activated + + 1 2 0 TRUE + diff --git a/tests/testthat/_snaps/public_api.md b/tests/testthat/_snaps/public_api.md new file mode 100644 index 000000000..6b0242216 --- /dev/null +++ b/tests/testthat/_snaps/public_api.md @@ -0,0 +1,47 @@ +# messages (via cat()) of style_file are correct + + Code + catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "dirty-sample-with-scope-tokens.R")) + Output + [1] "Styling 1 files:" + [2] " dirty-sample-with-scope-tokens.R i " + [3] "----------------------------------------" + [4] "Status\tCount\tLegend " + [5] "v \t0\tFile unchanged." + [6] "i \t1\tFile changed." + [7] "x \t0\tStyling threw an error." + [8] "----------------------------------------" + [9] "Please review the changes carefully!" + +--- + + Code + catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "clean-sample-with-scope-tokens.R")) + Output + [1] "Styling 1 files:" + [2] " clean-sample-with-scope-tokens.R v " + [3] "----------------------------------------" + [4] "Status\tCount\tLegend " + [5] "v \t1\tFile unchanged." + [6] "i \t0\tFile changed." + [7] "x \t0\tStyling threw an error." + [8] "----------------------------------------" + +--- + + Code + catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "dirty-sample-with-scope-spaces.R")) + Output + [1] "Styling 1 files:" + [2] " dirty-sample-with-scope-spaces.R i " + [3] "----------------------------------------" + [4] "Status\tCount\tLegend " + [5] "v \t0\tFile unchanged." + [6] "i \t1\tFile changed." + [7] "x \t0\tStyling threw an error." + [8] "----------------------------------------" + [9] "Please review the changes carefully!" + diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md new file mode 100644 index 000000000..afd921aca --- /dev/null +++ b/tests/testthat/_snaps/utils.md @@ -0,0 +1,24 @@ +# files with and without blank EOF line are read correctly + + Code + read_utf8(test_path("reference-objects/missing-blank-at-EOF.R")) + Output + $text + [1] "x" + + $missing_EOF_line_break + [1] TRUE + + +--- + + Code + read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R")) + Output + $text + [1] "x" + + $missing_EOF_line_break + [1] FALSE + + diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index 00209150e..dd19cb3c3 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -58,29 +58,23 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex test_that("cached expressions are displayed propperly", { cache_info <- cache_info("testthat", format = "tabular") - expect_known_value( - cache_info[, c("n", "size", "last_modified", "activated")], - file = test_path("reference-objects/cache-info-1"), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + cache_info[, c("n", "size", "last_modified", "activated")] + }) local_test_setup(cache = TRUE) style_text("1+1") cache_info <- cache_info(format = "tabular") cache_info$size <- round(cache_info$size, -2) - expect_known_value( - cache_info[, c("n", "size", "activated")], - file = test_path("reference-objects/cache-info-2"), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + cache_info[, c("n", "size", "activated")] + }) style_text("a <-function() NULL") cache_info <- cache_info(format = "tabular") cache_info$size <- round(cache_info$size, -2) - expect_known_value( - cache_info[, c("n", "size", "activated")], - file = test_path("reference-objects/cache-info-3"), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + cache_info[, c("n", "size", "activated")] + }) }) diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 0d6775ae0..46d6f8207 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -204,45 +204,27 @@ test_that("messages (via cat()) of style_file are correct", { list(cli.unicode = encoding == "utf8"), { # Message if scope > line_breaks and code changes - output <- catch_style_file_output(file.path( - "public-api", - "xyzdir-dirty", - "dirty-sample-with-scope-tokens.R" - )) - expect_known_value( - output, - testthat_file(paste0( - "public-api/xyzdir-dirty/dirty-reference-with-scope-tokens-", - encoding - )), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + catch_style_file_output(file.path( + "public-api", + "xyzdir-dirty", + "dirty-sample-with-scope-tokens.R" + )) + }) # No message if scope > line_breaks and code does not change - output <- catch_style_file_output(file.path( - "public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R" - )) - expect_known_value( - output, - testthat_file(paste0( - "public-api/xyzdir-dirty/clean-reference-with-scope-tokens-", - encoding - )), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + catch_style_file_output(file.path( + "public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R" + )) + }) # No message if scope <= line_breaks even if code is changed. - output <- catch_style_file_output(file.path( - "public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R" - )) - expect_known_value( - output, - testthat_file(paste0( - "public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-", - encoding - )), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + catch_style_file_output(file.path( + "public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R" + )) + }) } ) } diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 7b8e9a9f4..ed43923ff 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -8,15 +8,11 @@ test_that("non-comment-helpers", { }) test_that("files with and without blank EOF line are read correctly", { - expect_known_value( - read_utf8(test_path("reference-objects/missing-blank-at-EOF.R")), - test_path("reference-objects/return-read-utf8-missing-EOF"), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + read_utf8(test_path("reference-objects/missing-blank-at-EOF.R")) + }) - expect_known_value( - read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R")), - test_path("reference-objects/return-read-utf8-non-missing-EOF"), - update = getOption("styler.test_dir_writable", TRUE) - ) + expect_snapshot({ + read_utf8(test_path("reference-objects/non-missing-blank-at-EOF.R")) + }) }) From a6a1c041d25cec43961ed28662057090af220455 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 12:37:59 +0200 Subject: [PATCH 04/17] concatenate outputs --- tests/testthat/_snaps/public_api.md | 64 ++++++++++++++--------------- tests/testthat/test-public_api.R | 12 +++--- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/testthat/_snaps/public_api.md b/tests/testthat/_snaps/public_api.md index 6b0242216..da7b965ef 100644 --- a/tests/testthat/_snaps/public_api.md +++ b/tests/testthat/_snaps/public_api.md @@ -1,47 +1,47 @@ # messages (via cat()) of style_file are correct Code - catch_style_file_output(file.path("public-api", "xyzdir-dirty", - "dirty-sample-with-scope-tokens.R")) + cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "dirty-sample-with-scope-tokens.R")), sep = "\n") Output - [1] "Styling 1 files:" - [2] " dirty-sample-with-scope-tokens.R i " - [3] "----------------------------------------" - [4] "Status\tCount\tLegend " - [5] "v \t0\tFile unchanged." - [6] "i \t1\tFile changed." - [7] "x \t0\tStyling threw an error." - [8] "----------------------------------------" - [9] "Please review the changes carefully!" + Styling 1 files: + dirty-sample-with-scope-tokens.R i + ---------------------------------------- + Status Count Legend + v 0 File unchanged. + i 1 File changed. + x 0 Styling threw an error. + ---------------------------------------- + Please review the changes carefully! --- Code - catch_style_file_output(file.path("public-api", "xyzdir-dirty", - "clean-sample-with-scope-tokens.R")) + cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "clean-sample-with-scope-tokens.R")), sep = "\n") Output - [1] "Styling 1 files:" - [2] " clean-sample-with-scope-tokens.R v " - [3] "----------------------------------------" - [4] "Status\tCount\tLegend " - [5] "v \t1\tFile unchanged." - [6] "i \t0\tFile changed." - [7] "x \t0\tStyling threw an error." - [8] "----------------------------------------" + Styling 1 files: + clean-sample-with-scope-tokens.R v + ---------------------------------------- + Status Count Legend + v 1 File unchanged. + i 0 File changed. + x 0 Styling threw an error. + ---------------------------------------- --- Code - catch_style_file_output(file.path("public-api", "xyzdir-dirty", - "dirty-sample-with-scope-spaces.R")) + cat(catch_style_file_output(file.path("public-api", "xyzdir-dirty", + "dirty-sample-with-scope-spaces.R")), sep = "\n") Output - [1] "Styling 1 files:" - [2] " dirty-sample-with-scope-spaces.R i " - [3] "----------------------------------------" - [4] "Status\tCount\tLegend " - [5] "v \t0\tFile unchanged." - [6] "i \t1\tFile changed." - [7] "x \t0\tStyling threw an error." - [8] "----------------------------------------" - [9] "Please review the changes carefully!" + Styling 1 files: + dirty-sample-with-scope-spaces.R i + ---------------------------------------- + Status Count Legend + v 0 File unchanged. + i 1 File changed. + x 0 Styling threw an error. + ---------------------------------------- + Please review the changes carefully! diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 46d6f8207..524f2f320 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -205,25 +205,25 @@ test_that("messages (via cat()) of style_file are correct", { { # Message if scope > line_breaks and code changes expect_snapshot({ - catch_style_file_output(file.path( + cat(catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "dirty-sample-with-scope-tokens.R" - )) + )), sep = "\n") }) # No message if scope > line_breaks and code does not change expect_snapshot({ - catch_style_file_output(file.path( + cat(catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "clean-sample-with-scope-tokens.R" - )) + )), sep = "\n") }) # No message if scope <= line_breaks even if code is changed. expect_snapshot({ - catch_style_file_output(file.path( + cat(catch_style_file_output(file.path( "public-api", "xyzdir-dirty", "dirty-sample-with-scope-spaces.R" - )) + )), sep = "\n") }) } ) From 3291dfea6f8d07de9292031d932c759b9a4124b4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 13:20:54 +0200 Subject: [PATCH 05/17] more snapshots --- tests/testthat/_snaps/helpers.md | 15 +++++++++++++++ tests/testthat/_snaps/public_api.md | 7 +++++++ tests/testthat/_snaps/roundtrip.md | 9 +++++++++ tests/testthat/test-cache-with-r-cache.R | 6 +++--- tests/testthat/test-helpers.R | 7 ++----- tests/testthat/test-public_api.R | 2 +- tests/testthat/test-roundtrip.R | 4 ++-- 7 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/_snaps/helpers.md create mode 100644 tests/testthat/_snaps/roundtrip.md diff --git a/tests/testthat/_snaps/helpers.md b/tests/testthat/_snaps/helpers.md new file mode 100644 index 000000000..d27821d5d --- /dev/null +++ b/tests/testthat/_snaps/helpers.md @@ -0,0 +1,15 @@ +# can construct and print vertical + + Code + construct_vertical(c("1 + 1", "nw")) + Output + 1 + 1 + nw + +# can lookup tokens + + Code + lookup_new_special() + Output + [1] "SPECIAL-PIPE" "SPECIAL-IN" "SPECIAL-OTHER" + diff --git a/tests/testthat/_snaps/public_api.md b/tests/testthat/_snaps/public_api.md index da7b965ef..b55a037eb 100644 --- a/tests/testthat/_snaps/public_api.md +++ b/tests/testthat/_snaps/public_api.md @@ -45,3 +45,10 @@ ---------------------------------------- Please review the changes carefully! +# No sensitive to decimal option + + Code + style_text("1") + Output + 1 + diff --git a/tests/testthat/_snaps/roundtrip.md b/tests/testthat/_snaps/roundtrip.md new file mode 100644 index 000000000..4c326e73e --- /dev/null +++ b/tests/testthat/_snaps/roundtrip.md @@ -0,0 +1,9 @@ +# correct styling does not give an error + + Code + verify_roundtrip("1+1", "1 + 1") + +# corrupt styling does give an error + + The expression evaluated before the styling is not the same as the expression after styling. This should not happen. Please file a bug report on GitHub (https://github.com/r-lib/styler/issues) using a reprex. + diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index dd19cb3c3..c2aa6e75a 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -4,13 +4,13 @@ test_that("Cache management works", { local_test_setup(cache = TRUE) # at fresh startup expect_s3_class(cache_info(format = "tabular"), "tbl_df") - expect_error(capture.output(cache_info()), NA) + expect_output(cache_info()) expect_equal(basename(cache_activate()), styler_version) expect_equal(basename(cache_activate("xyz")), "xyz") expect_equal(getOption("styler.cache_name"), "xyz") # when cache xyz is activated, cache_info() shows deactivated for other caches expect_false(cache_info(styler_version, format = "tabular")$activated) - expect_error(capture.output(cache_info(format = "lucid")), NA) + expect_output(cache_info(format = "lucid")) # cache_info() defaults to the currently active cache expect_equal(basename(cache_info(format = "tabular")$location), "xyz") @@ -22,7 +22,7 @@ test_that("Cache management works", { ) expect_false(cache_info(format = "tabular")$activated) expect_equal(getOption("styler.cache_location"), NULL) - expect_error(cache_clear("testthat", ask = FALSE), NA) + expect_invisible(cache_clear("testthat", ask = FALSE)) }) test_that("top-level test: Caches top-level expressions efficiently on style_text()", { diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index d101ed82e..527c755c1 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -1,10 +1,7 @@ test_that("can construct and print vertical", { - expect_error(construct_vertical(c("1 + 1", "nw")), NA) - capture.output( - expect_error(construct_vertical(c("1 + 1", "nw")) %>% print(), NA) - ) + expect_snapshot({construct_vertical(c("1 + 1", "nw"))}) }) @@ -13,7 +10,7 @@ test_that("file types can be asserted", { }) test_that("can lookup tokens", { - expect_error(lookup_new_special(), NA) + expect_snapshot({lookup_new_special()}) }) test_that("can extend non-comment", { diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 524f2f320..d5c8e56d8 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -519,7 +519,7 @@ test_that("Can display warning on unset styler cache", { test_that("No sensitive to decimal option", { withr::local_options(OutDec = ",") - expect_error(style_text("1"), NA) + expect_snapshot({style_text("1")}) }) test_that("Can display warning on unset styler cache", { diff --git a/tests/testthat/test-roundtrip.R b/tests/testthat/test-roundtrip.R index 692a5c27c..c4624a160 100644 --- a/tests/testthat/test-roundtrip.R +++ b/tests/testthat/test-roundtrip.R @@ -13,11 +13,11 @@ test_that("parse_tree_must_be_identical works", { }) test_that("correct styling does not give an error", { - expect_error(verify_roundtrip("1+1", "1 + 1"), NA) + expect_snapshot({verify_roundtrip("1+1", "1 + 1")}) }) test_that("corrupt styling does give an error", { - expect_error(verify_roundtrip("1-1", "1 + 1"), "bug") + expect_snapshot_error(verify_roundtrip("1-1", "1 + 1")) }) From ed208cddf6940c66a741b600d773d1a469fe281d Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 13:31:38 +0200 Subject: [PATCH 06/17] replace invisible with silent --- tests/testthat/test-cache-with-r-cache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index c2aa6e75a..c278ee619 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -22,7 +22,7 @@ test_that("Cache management works", { ) expect_false(cache_info(format = "tabular")$activated) expect_equal(getOption("styler.cache_location"), NULL) - expect_invisible(cache_clear("testthat", ask = FALSE)) + expect_silent(cache_clear("testthat", ask = FALSE)) }) test_that("top-level test: Caches top-level expressions efficiently on style_text()", { From c1bbae94b2ee8139d3d015ae787ab0854402c3d5 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 14:00:25 +0200 Subject: [PATCH 07/17] delete binaries; skip cache test on R < 3.6 --- .../clean-reference-with-scope-tokens-non-utf8 | Bin 182 -> 0 bytes .../clean-reference-with-scope-tokens-utf8 | Bin 197 -> 0 bytes .../dirty-reference-with-scope-spaces-non-utf8 | Bin 204 -> 0 bytes .../dirty-reference-with-scope-spaces-utf8 | Bin 225 -> 0 bytes .../dirty-reference-with-scope-tokens-non-utf8 | Bin 204 -> 0 bytes .../dirty-reference-with-scope-tokens-utf8 | Bin 225 -> 0 bytes tests/testthat/test-cache-with-r-cache.R | 2 ++ 7 files changed, 2 insertions(+) delete mode 100644 tests/testthat/public-api/xyzdir-dirty/clean-reference-with-scope-tokens-non-utf8 delete mode 100644 tests/testthat/public-api/xyzdir-dirty/clean-reference-with-scope-tokens-utf8 delete mode 100644 tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-non-utf8 delete mode 100644 tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-utf8 delete mode 100644 tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-tokens-non-utf8 delete mode 100644 tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-tokens-utf8 diff --git a/tests/testthat/public-api/xyzdir-dirty/clean-reference-with-scope-tokens-non-utf8 b/tests/testthat/public-api/xyzdir-dirty/clean-reference-with-scope-tokens-non-utf8 deleted file mode 100644 index 46ebf02b7b88d3e1c50fd3834a2616f9c8ed9b7d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 182 zcmV;n07?HJiwFP!000001C@`x3&JoE#e)?wP9hy0Zg6l(v8$`#8dU|?WkU;&ZLK!QO4h&h0KP9QB5TvC~nnU}7hV5p#w zmYI`UY{kIP0FqHtNX|)3%+oDS%q_@C)h*8~$SL%`4UmQg}3HiUL%1 z#iJ<=1A?Ib5D6|xEGaGKbj~l$E8+A>O;62Bfw@f#Hm4p`l}N+5rFne|uBq diff --git a/tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-non-utf8 b/tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-non-utf8 deleted file mode 100644 index daf8f8da8de43e0a4ee147bf8ea05b71a376bb1e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 204 zcmV;-05ks|iwFP!000001D#K?3c@fD4JtyML^?X0(7`3euC9WUgV@D2q}L`8(~_jE z{d*%ei<5Zpj)V8^-MjmW5Hch4W$5!Tl63$jivU74g&(ytH9!tfDUI$pF)5VF`jI*Q zXf?7ydC8n;T4b)}0$p|k1(SBqeymBK6rTIe(NohIPcK-bDWg}?13l1lhytAvlA9XK zET&aJ^AGpMY@hF~_>7kp2jB+K+Qw#orcAFIxkIqnt6=A4yy`%3i&dxfxO)MH767ka G0RR9P{$0KR diff --git a/tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-utf8 b/tests/testthat/public-api/xyzdir-dirty/dirty-reference-with-scope-spaces-utf8 deleted file mode 100644 index 786eb1abe9839410c36f54e799e0cdf17ae65dff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 225 zcmV<703QDziwFP!000001I>`X3c@fD#)G=VNu)T+3F6jbS69KwL3D8q?X?NSv?Qsu zn}d%aPQHk*(-cJT!i?hnUz2jB0GLqbT844T?^g^XNMH&fTg2U|&@Qh*R35faUc zkZYqXAQswIzG0_aqF)NjeG_Fl`X*-)nqUw0?FH@jrM_Q(5-o>!u*?>QuCqc}y2TV# z+=QNOfl{d_c+-IFZWSOQakT4y@=6ZZK|A~OgY b&%)WWyyGwsF^x$fWi@*Pv4B-}1_A&8NBrX{(y z_V10@E>7aXI}YBvckgaX#@LJn3*Q4jvXuvCa}UPWDGgeg5+DI6lty_HkpYik?-nKHU)ln%jSr@S3i(^UtVv{^<3c^4Tg%`D1D-p4j5yUP*TU)`(LbS16k}+9aH(_^T zOlRQ{#LA0!ot(rCCXE+Rm>-5W1Mi!Cmoe62ovOB7VLg}J&D{0=jtV7p1TY6UNQHL6 z*tJro5K2RZXT>R1=;e}P&jv|~9wkTA*55*TdqKT@Deu>xM9neSk)X`-Ws+&)Ym88b zjkjU>yaS){mBWKf2eHr*hJLLMDhfXTs9)Nsd_Jnn=1CMA%t2^CV-n;43HxNDP*? "3.6") + cache_info <- cache_info("testthat", format = "tabular") expect_snapshot({ cache_info[, c("n", "size", "last_modified", "activated")] From 616e1374770eeddd6355ebe942c021d3692c41c8 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 14:08:35 +0200 Subject: [PATCH 08/17] avoid negation --- tests/testthat/test-cache-with-r-cache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index e4a421d98..0df8128bf 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -57,7 +57,7 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex test_that("cached expressions are displayed propperly", { - skip_if_not(getRversion() > "3.6") + skip_if(getRversion() <= "3.6") cache_info <- cache_info("testthat", format = "tabular") expect_snapshot({ From 6eccc0d08944de6fb6d22fbd40b692c8135015c7 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 14:20:12 +0200 Subject: [PATCH 09/17] can run only on R4 --- tests/testthat/test-cache-with-r-cache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index 0df8128bf..ed7617a34 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -57,7 +57,7 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex test_that("cached expressions are displayed propperly", { - skip_if(getRversion() <= "3.6") + skip_if(getRversion() <= "4.1") cache_info <- cache_info("testthat", format = "tabular") expect_snapshot({ From ae46df883f8e7456f6a7bec08f9e30cb327f3e5d Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 28 May 2022 14:28:46 +0200 Subject: [PATCH 10/17] only 4.2 and onwards --- tests/testthat/test-cache-with-r-cache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index ed7617a34..c5e4e3921 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -57,7 +57,7 @@ test_that("top-level test: Caches top-level expressions efficiently on style_tex test_that("cached expressions are displayed propperly", { - skip_if(getRversion() <= "4.1") + skip_if(getRversion() < "4.2") cache_info <- cache_info("testthat", format = "tabular") expect_snapshot({ From f1d87bdbce5300316b4acc7b5b2a270b840eb535 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 30 May 2022 22:49:22 +0200 Subject: [PATCH 11/17] use snapshots for error @lorenzwalthert Can you please check if this is what you want? More specifically, do you want to include snaphots of entire error messages or are you happy with the current approach of using regexps to check error messages? --- tests/testthat/_snaps/escaping.md | 28 ++++++++++++++++++++++++++++ tests/testthat/test-escaping.R | 24 ++++++++++++------------ 2 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/testthat/_snaps/escaping.md diff --git a/tests/testthat/_snaps/escaping.md b/tests/testthat/_snaps/escaping.md new file mode 100644 index 000000000..ae68a1c71 --- /dev/null +++ b/tests/testthat/_snaps/escaping.md @@ -0,0 +1,28 @@ +# escaping of characters works + + :2:7: unexpected '{' + 1: + 2: fun() { + ^ + +--- + + :3:0: unexpected end of input + 1: + 2: x <- + ^ + +--- + + :2:3: unexpected input + 1: + 2: 1 _ + ^ + +--- + + :6:0: unexpected end of input + 4: + 5: + ^ + diff --git a/tests/testthat/test-escaping.R b/tests/testthat/test-escaping.R index f9a5c7864..b3ca6ad32 100644 --- a/tests/testthat/test-escaping.R +++ b/tests/testthat/test-escaping.R @@ -3,19 +3,19 @@ test_that("escaping of characters works", { transformer = style_text ), NA) - expect_error(test_collection("escaping", "fail-parsing-1", - transformer = style_text - ), ":2:7: unexpected ") + expect_snapshot_error( + test_collection("escaping", "fail-parsing-1", transformer = style_text) + ) - expect_error(test_collection("escaping", "fail-parsing-2", - transformer = style_text - ), "x <-") + expect_snapshot_error( + test_collection("escaping", "fail-parsing-2", transformer = style_text) + ) - expect_error(test_collection("escaping", "fail-parsing-3", - transformer = style_text - )) + expect_snapshot_error( + test_collection("escaping", "fail-parsing-3", transformer = style_text) + ) - expect_error(test_collection("escaping", "fail-parsing-4", - transformer = style_text - ), ":6:0:") + expect_snapshot_error( + test_collection("escaping", "fail-parsing-4", transformer = style_text) + ) }) From 2005860e489e481f9de06e0cb226ddebfdfa9a19 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:12:24 +0200 Subject: [PATCH 12/17] Revert "use snapshots for error" This reverts commit f1d87bdbce5300316b4acc7b5b2a270b840eb535. --- tests/testthat/_snaps/escaping.md | 28 ---------------------------- tests/testthat/test-escaping.R | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 40 deletions(-) delete mode 100644 tests/testthat/_snaps/escaping.md diff --git a/tests/testthat/_snaps/escaping.md b/tests/testthat/_snaps/escaping.md deleted file mode 100644 index ae68a1c71..000000000 --- a/tests/testthat/_snaps/escaping.md +++ /dev/null @@ -1,28 +0,0 @@ -# escaping of characters works - - :2:7: unexpected '{' - 1: - 2: fun() { - ^ - ---- - - :3:0: unexpected end of input - 1: - 2: x <- - ^ - ---- - - :2:3: unexpected input - 1: - 2: 1 _ - ^ - ---- - - :6:0: unexpected end of input - 4: - 5: - ^ - diff --git a/tests/testthat/test-escaping.R b/tests/testthat/test-escaping.R index b3ca6ad32..f9a5c7864 100644 --- a/tests/testthat/test-escaping.R +++ b/tests/testthat/test-escaping.R @@ -3,19 +3,19 @@ test_that("escaping of characters works", { transformer = style_text ), NA) - expect_snapshot_error( - test_collection("escaping", "fail-parsing-1", transformer = style_text) - ) + expect_error(test_collection("escaping", "fail-parsing-1", + transformer = style_text + ), ":2:7: unexpected ") - expect_snapshot_error( - test_collection("escaping", "fail-parsing-2", transformer = style_text) - ) + expect_error(test_collection("escaping", "fail-parsing-2", + transformer = style_text + ), "x <-") - expect_snapshot_error( - test_collection("escaping", "fail-parsing-3", transformer = style_text) - ) + expect_error(test_collection("escaping", "fail-parsing-3", + transformer = style_text + )) - expect_snapshot_error( - test_collection("escaping", "fail-parsing-4", transformer = style_text) - ) + expect_error(test_collection("escaping", "fail-parsing-4", + transformer = style_text + ), ":6:0:") }) From 43377cdb8ed0b569ad336be54a6bc2d154490bc9 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:19:18 +0200 Subject: [PATCH 13/17] revert some more --- tests/testthat/test-cache-with-r-cache.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-cache-with-r-cache.R b/tests/testthat/test-cache-with-r-cache.R index c5e4e3921..a65d0372b 100644 --- a/tests/testthat/test-cache-with-r-cache.R +++ b/tests/testthat/test-cache-with-r-cache.R @@ -4,13 +4,13 @@ test_that("Cache management works", { local_test_setup(cache = TRUE) # at fresh startup expect_s3_class(cache_info(format = "tabular"), "tbl_df") - expect_output(cache_info()) + expect_error(capture.output(cache_info()), NA) expect_equal(basename(cache_activate()), styler_version) expect_equal(basename(cache_activate("xyz")), "xyz") expect_equal(getOption("styler.cache_name"), "xyz") # when cache xyz is activated, cache_info() shows deactivated for other caches expect_false(cache_info(styler_version, format = "tabular")$activated) - expect_output(cache_info(format = "lucid")) + expect_error(capture.output(cache_info(format = "lucid")), NA) # cache_info() defaults to the currently active cache expect_equal(basename(cache_info(format = "tabular")$location), "xyz") @@ -22,7 +22,7 @@ test_that("Cache management works", { ) expect_false(cache_info(format = "tabular")$activated) expect_equal(getOption("styler.cache_location"), NULL) - expect_silent(cache_clear("testthat", ask = FALSE)) + expect_error(cache_clear("testthat", ask = FALSE), NA) }) test_that("top-level test: Caches top-level expressions efficiently on style_text()", { From 2921c02ed8109a47af65b883f6c0bed0eab24ab3 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:27:08 +0200 Subject: [PATCH 14/17] `expect_equivalent()` -> `expect_equal()` --- tests/testthat/test-public_api.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index d5c8e56d8..9c12b1672 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -101,17 +101,18 @@ test_that("styler can style directories and exclude", { test_that("styler can style files", { # just one - capture_output(expect_equivalent( + capture_output(expect_equal( { out <- style_file(c( testthat_file("public-api", "xyzfile", "random-script.R") ), strict = FALSE) out$changed }, - rep(FALSE, 1) + rep(FALSE, 1), + ignore_attr = TRUE )) # multiple not in the same working directory - capture_output(expect_equivalent( + capture_output(expect_equal( { out <- style_file(c( testthat_file("public-api", "xyzfile", "random-script.R"), @@ -119,7 +120,8 @@ test_that("styler can style files", { ), strict = FALSE) out$changed }, - rep(FALSE, 2) + rep(FALSE, 2), + ignore_attr = TRUE )) }) From 0ac2aef657b8ff3e6c637154f3d3ff56498e583e Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:33:58 +0200 Subject: [PATCH 15/17] Update test-helpers.R --- tests/testthat/test-helpers.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index 527c755c1..55c654375 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -1,7 +1,9 @@ test_that("can construct and print vertical", { - expect_snapshot({construct_vertical(c("1 + 1", "nw"))}) + expect_snapshot({ + construct_vertical(c("1 + 1", "nw")) + }) }) @@ -10,7 +12,9 @@ test_that("file types can be asserted", { }) test_that("can lookup tokens", { - expect_snapshot({lookup_new_special()}) + expect_snapshot({ + lookup_new_special() + }) }) test_that("can extend non-comment", { From 9cea94032d96b235f38153f59b81851c84197e2e Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:34:25 +0200 Subject: [PATCH 16/17] Update test-public_api.R --- tests/testthat/test-public_api.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-public_api.R b/tests/testthat/test-public_api.R index 9c12b1672..6c4aac1fe 100644 --- a/tests/testthat/test-public_api.R +++ b/tests/testthat/test-public_api.R @@ -521,7 +521,9 @@ test_that("Can display warning on unset styler cache", { test_that("No sensitive to decimal option", { withr::local_options(OutDec = ",") - expect_snapshot({style_text("1")}) + expect_snapshot({ + style_text("1") + }) }) test_that("Can display warning on unset styler cache", { From 35d336fa03924661001f3a70ebcadf3ed0e1d8e2 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 31 May 2022 08:42:38 +0200 Subject: [PATCH 17/17] Update test-roundtrip.R --- tests/testthat/test-roundtrip.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-roundtrip.R b/tests/testthat/test-roundtrip.R index c4624a160..d50242bc2 100644 --- a/tests/testthat/test-roundtrip.R +++ b/tests/testthat/test-roundtrip.R @@ -13,7 +13,9 @@ test_that("parse_tree_must_be_identical works", { }) test_that("correct styling does not give an error", { - expect_snapshot({verify_roundtrip("1+1", "1 + 1")}) + expect_snapshot({ + verify_roundtrip("1+1", "1 + 1") + }) }) test_that("corrupt styling does give an error", {