From 6d1547a05d3a161e1950edc28388111df1cb26a5 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 13:22:39 -0400 Subject: [PATCH 01/10] Use recent standalone files --- ...azyeval.R => import-standalone-lazyeval.R} | 21 +- ...bj-type.R => import-standalone-obj-type.R} | 45 ++- ...heck.R => import-standalone-types-check.R} | 277 ++++++++++++------ 3 files changed, 231 insertions(+), 112 deletions(-) rename R/{compat-lazyeval.R => import-standalone-lazyeval.R} (81%) rename R/{compat-obj-type.R => import-standalone-obj-type.R} (89%) rename R/{compat-types-check.R => import-standalone-types-check.R} (65%) diff --git a/R/compat-lazyeval.R b/R/import-standalone-lazyeval.R similarity index 81% rename from R/compat-lazyeval.R rename to R/import-standalone-lazyeval.R index 67fc4936a..f3e94f02c 100644 --- a/R/compat-lazyeval.R +++ b/R/import-standalone-lazyeval.R @@ -1,8 +1,19 @@ -# nocov start - compat-lazyeval (last updated: rlang 0.3.0) - +# Standalone file: do not edit by hand +# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-lazyeval.R +# Generated by: usethis::use_standalone("r-lib/rlang", "lazyeval") +# ---------------------------------------------------------------------- +# +# --- +# repo: r-lib/rlang +# file: standalone-lazyeval.R +# last-updated: 2018-09-18 +# license: https://unlicense.org +# imports: rlang +# --- +# # This file serves as a reference for compatibility functions for lazyeval. -# Please find the most recent version in rlang's repository. - +# +# nocov start warn_underscored <- function() { return(NULL) @@ -48,7 +59,7 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) { }, list = if (inherits(lazy, "lazy")) { - lazy <- new_quosure(lazy$expr, lazy$env) + lazy = new_quosure(lazy$expr, lazy$env) } ) diff --git a/R/compat-obj-type.R b/R/import-standalone-obj-type.R similarity index 89% rename from R/compat-obj-type.R rename to R/import-standalone-obj-type.R index d86dca51b..47268d620 100644 --- a/R/compat-obj-type.R +++ b/R/import-standalone-obj-type.R @@ -1,7 +1,26 @@ -# nocov start --- r-lib/rlang compat-obj-type +# Standalone file: do not edit by hand +# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-obj-type.R +# Generated by: usethis::use_standalone("r-lib/rlang", "obj-type") +# ---------------------------------------------------------------------- # -# Changelog -# ========= +# --- +# repo: r-lib/rlang +# file: standalone-obj-type.R +# last-updated: 2024-02-14 +# license: https://unlicense.org +# imports: rlang (>= 1.1.0) +# --- +# +# ## Changelog +# +# 2024-02-14: +# - `obj_type_friendly()` now works for S7 objects. +# +# 2023-05-01: +# - `obj_type_friendly()` now only displays the first class of S3 objects. +# +# 2023-03-30: +# - `stop_input_type()` now handles `I()` input literally in `arg`. # # 2022-10-04: # - `obj_type_friendly(value = TRUE)` now shows numeric scalars @@ -36,7 +55,8 @@ # - Added support for matrices and arrays (#141). # - Added documentation. # - Added changelog. - +# +# nocov start #' Return English-friendly type #' @param x Any R object. @@ -55,7 +75,7 @@ obj_type_friendly <- function(x, value = TRUE) { if (inherits(x, "quosure")) { type <- "quosure" } else { - type <- paste(class(x), collapse = "/") + type <- class(x)[[1L]] } return(sprintf("a <%s> object", type)) } @@ -251,19 +271,19 @@ vec_type_friendly <- function(x, length = FALSE) { #' Return OO type #' @param x Any R object. #' @return One of `"bare"` (for non-OO objects), `"S3"`, `"S4"`, -#' `"R6"`, or `"R7"`. +#' `"R6"`, or `"S7"`. #' @noRd obj_type_oo <- function(x) { if (!is.object(x)) { return("bare") } - class <- inherits(x, c("R6", "R7_object"), which = TRUE) + class <- inherits(x, c("R6", "S7_object"), which = TRUE) if (class[[1]]) { "R6" } else if (class[[2]]) { - "R7" + "S7" } else if (isS4(x)) { "S4" } else { @@ -288,7 +308,7 @@ stop_input_type <- function(x, show_value = TRUE, arg = caller_arg(x), call = caller_env()) { - # From compat-cli.R + # From standalone-cli.R cli <- env_get_list( nms = c("format_arg", "format_code"), last = topenv(), @@ -305,10 +325,15 @@ stop_input_type <- function(x, if (length(what)) { what <- oxford_comma(what) } + if (inherits(arg, "AsIs")) { + format_arg <- identity + } else { + format_arg <- cli$format_arg + } message <- sprintf( "%s must be %s, not %s.", - cli$format_arg(arg), + format_arg(arg), what, obj_type_friendly(x, value = show_value) ) diff --git a/R/compat-types-check.R b/R/import-standalone-types-check.R similarity index 65% rename from R/compat-types-check.R rename to R/import-standalone-types-check.R index 3689ca5f2..ef8c5a1d5 100644 --- a/R/compat-types-check.R +++ b/R/import-standalone-types-check.R @@ -1,12 +1,40 @@ -# nocov start --- r-lib/rlang compat-types-check +# Standalone file: do not edit by hand +# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-types-check.R +# Generated by: usethis::use_standalone("r-lib/rlang", "types-check") +# ---------------------------------------------------------------------- # -# Dependencies -# ============ +# --- +# repo: r-lib/rlang +# file: standalone-types-check.R +# last-updated: 2023-03-13 +# license: https://unlicense.org +# dependencies: standalone-obj-type.R +# imports: rlang (>= 1.1.0) +# --- # -# - compat-obj-type.R +# ## Changelog # -# Changelog -# ========= +# 2024-08-15: +# - `check_character()` gains an `allow_na` argument (@martaalcalde, #1724) +# +# 2023-03-13: +# - Improved error messages of number checkers (@teunbrand) +# - Added `allow_infinite` argument to `check_number_whole()` (@mgirlich). +# - Added `check_data_frame()` (@mgirlich). +# +# 2023-03-07: +# - Added dependency on rlang (>= 1.1.0). +# +# 2023-02-15: +# - Added `check_logical()`. +# +# - `check_bool()`, `check_number_whole()`, and +# `check_number_decimal()` are now implemented in C. +# +# - For efficiency, `check_number_whole()` and +# `check_number_decimal()` now take a `NULL` default for `min` and +# `max`. This makes it possible to bypass unnecessary type-checking +# and comparisons in the default case of no bounds checks. # # 2022-10-07: # - `check_number_whole()` and `_decimal()` no longer treat @@ -30,25 +58,21 @@ # # 2022-08-11: # - Added changelog. +# +# nocov start # Scalars ----------------------------------------------------------------- +.standalone_types_check_dot_call <- .Call + check_bool <- function(x, ..., allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { - if (!missing(x)) { - if (is_bool(x)) { - return(invisible(NULL)) - } - if (allow_null && is_null(x)) { - return(invisible(NULL)) - } - if (allow_na && identical(x, NA)) { - return(invisible(NULL)) - } + if (!missing(x) && .standalone_types_check_dot_call(ffi_standalone_is_bool_1.0.7, x, allow_na, allow_null)) { + return(invisible(NULL)) } stop_input_type( @@ -141,22 +165,41 @@ check_name <- function(x, ) } +IS_NUMBER_true <- 0 +IS_NUMBER_false <- 1 +IS_NUMBER_oob <- 2 + check_number_decimal <- function(x, ..., - min = -Inf, - max = Inf, + min = NULL, + max = NULL, allow_infinite = TRUE, allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { - .rlang_types_check_number( + if (missing(x)) { + exit_code <- IS_NUMBER_false + } else if (0 == (exit_code <- .standalone_types_check_dot_call( + ffi_standalone_check_number_1.0.7, + x, + allow_decimal = TRUE, + min, + max, + allow_infinite, + allow_na, + allow_null + ))) { + return(invisible(NULL)) + } + + .stop_not_number( x, ..., + exit_code = exit_code, + allow_decimal = TRUE, min = min, max = max, - allow_decimal = TRUE, - allow_infinite = allow_infinite, allow_na = allow_na, allow_null = allow_null, arg = arg, @@ -166,19 +209,35 @@ check_number_decimal <- function(x, check_number_whole <- function(x, ..., - min = -Inf, - max = Inf, + min = NULL, + max = NULL, + allow_infinite = FALSE, allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { - .rlang_types_check_number( + if (missing(x)) { + exit_code <- IS_NUMBER_false + } else if (0 == (exit_code <- .standalone_types_check_dot_call( + ffi_standalone_check_number_1.0.7, + x, + allow_decimal = FALSE, + min, + max, + allow_infinite, + allow_na, + allow_null + ))) { + return(invisible(NULL)) + } + + .stop_not_number( x, ..., + exit_code = exit_code, + allow_decimal = FALSE, min = min, max = max, - allow_decimal = FALSE, - allow_infinite = FALSE, allow_na = allow_na, allow_null = allow_null, arg = arg, @@ -186,23 +245,38 @@ check_number_whole <- function(x, ) } -.rlang_types_check_number <- function(x, - ..., - min = -Inf, - max = Inf, - allow_decimal = FALSE, - allow_infinite = FALSE, - allow_na = FALSE, - allow_null = FALSE, - arg = caller_arg(x), - call = caller_env()) { +.stop_not_number <- function(x, + ..., + exit_code, + allow_decimal, + min, + max, + allow_na, + allow_null, + arg, + call) { if (allow_decimal) { what <- "a number" } else { what <- "a whole number" } - .stop <- function(x, what, ...) stop_input_type( + if (exit_code == IS_NUMBER_oob) { + min <- min %||% -Inf + max <- max %||% Inf + + if (min > -Inf && max < Inf) { + what <- sprintf("%s between %s and %s", what, min, max) + } else if (x < min) { + what <- sprintf("%s larger than or equal to %s", what, min) + } else if (x > max) { + what <- sprintf("%s smaller than or equal to %s", what, max) + } else { + abort("Unexpected state in OOB check", .internal = TRUE) + } + } + + stop_input_type( x, what, ..., @@ -211,66 +285,6 @@ check_number_whole <- function(x, arg = arg, call = call ) - - if (!missing(x)) { - is_number <- is_number( - x, - allow_decimal = allow_decimal, - allow_infinite = allow_infinite - ) - - if (is_number) { - if (min > -Inf && max < Inf) { - what <- sprintf("a number between %s and %s", min, max) - } else { - what <- NULL - } - if (x < min) { - what <- what %||% sprintf("a number larger than %s", min) - .stop(x, what, ...) - } - if (x > max) { - what <- what %||% sprintf("a number smaller than %s", max) - .stop(x, what, ...) - } - return(invisible(NULL)) - } - - if (allow_null && is_null(x)) { - return(invisible(NULL)) - } - if (allow_na && (identical(x, NA) || - identical(x, na_dbl) || - identical(x, na_int))) { - return(invisible(NULL)) - } - } - - .stop(x, what, ...) -} - -is_number <- function(x, - allow_decimal = FALSE, - allow_infinite = FALSE) { - if (!typeof(x) %in% c("integer", "double")) { - return(FALSE) - } - if (!is.numeric(x)) { - return(FALSE) - } - if (length(x) != 1) { - return(FALSE) - } - if (is.na(x)) { - return(FALSE) - } - if (!allow_decimal && !is_integerish(x)) { - return(FALSE) - } - if (!allow_infinite && is.infinite(x)) { - return(FALSE) - } - TRUE } check_symbol <- function(x, @@ -291,6 +305,7 @@ check_symbol <- function(x, x, "a symbol", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -315,6 +330,7 @@ check_arg <- function(x, x, "an argument name", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -339,6 +355,7 @@ check_call <- function(x, x, "a defused call", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -363,6 +380,7 @@ check_environment <- function(x, x, "an environment", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -387,6 +405,7 @@ check_function <- function(x, x, "a function", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -411,6 +430,7 @@ check_closure <- function(x, x, "an R function", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -435,6 +455,7 @@ check_formula <- function(x, x, "a formula", ..., + allow_na = FALSE, allow_null = allow_null, arg = arg, call = call @@ -444,15 +465,28 @@ check_formula <- function(x, # Vectors ----------------------------------------------------------------- +# TODO: Figure out what to do with logical `NA` and `allow_na = TRUE` + check_character <- function(x, ..., + allow_na = TRUE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { + if (!missing(x)) { if (is_character(x)) { + if (!allow_na && any(is.na(x))) { + abort( + sprintf("`%s` can't contain NA values.", arg), + arg = arg, + call = call + ) + } + return(invisible(NULL)) } + if (allow_null && is_null(x)) { return(invisible(NULL)) } @@ -468,4 +502,53 @@ check_character <- function(x, ) } +check_logical <- function(x, + ..., + allow_null = FALSE, + arg = caller_arg(x), + call = caller_env()) { + if (!missing(x)) { + if (is_logical(x)) { + return(invisible(NULL)) + } + if (allow_null && is_null(x)) { + return(invisible(NULL)) + } + } + + stop_input_type( + x, + "a logical vector", + ..., + allow_na = FALSE, + allow_null = allow_null, + arg = arg, + call = call + ) +} + +check_data_frame <- function(x, + ..., + allow_null = FALSE, + arg = caller_arg(x), + call = caller_env()) { + if (!missing(x)) { + if (is.data.frame(x)) { + return(invisible(NULL)) + } + if (allow_null && is_null(x)) { + return(invisible(NULL)) + } + } + + stop_input_type( + x, + "a data frame", + ..., + allow_null = allow_null, + arg = arg, + call = call + ) +} + # nocov end From d0661c9c69c2b19c3166c2fb49d1c84e0b4a91ba Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 13:22:56 -0400 Subject: [PATCH 02/10] Recent standalone don't accept integers --- R/append.R | 3 ++- R/separate-longer.R | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/R/append.R b/R/append.R index 6d4e36019..a308372fa 100644 --- a/R/append.R +++ b/R/append.R @@ -38,7 +38,8 @@ df_append <- function(x, y, after = NULL, remove = FALSE) { after <- match(after, x_names) } - check_number_whole(after, min = 0L, max = n, .internal = TRUE) + # r-lib/rlang#1702 + check_number_whole(after, min = 0, max = as.numeric(n), .internal = TRUE) if (remove) { lhs <- seq2(1L, after - 1L) diff --git a/R/separate-longer.R b/R/separate-longer.R index dd5830124..879c6c6b3 100644 --- a/R/separate-longer.R +++ b/R/separate-longer.R @@ -54,7 +54,7 @@ separate_longer_position <- function(data, cols, width, ..., keep_empty = FALSE) check_installed("stringr") check_data_frame(data) check_required(cols) - check_number_whole(width, min = 1L) + check_number_whole(width, min = 1) check_dots_empty() map_unchop( From 6e6beabcbf62f38609819646ca3cb0e32f842d38 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 13:58:14 -0400 Subject: [PATCH 03/10] Use regular snapshot tests. Avoid nesting `expect_error()` --- tests/testthat/_snaps/append.md | 5 +- tests/testthat/_snaps/chop.md | 10 ++-- tests/testthat/_snaps/drop-na.md | 13 ++-- tests/testthat/_snaps/expand.md | 15 ++--- tests/testthat/_snaps/extract.md | 15 ++--- tests/testthat/_snaps/gather.md | 42 +++++++------ tests/testthat/_snaps/hoist.md | 25 ++++---- tests/testthat/_snaps/nest-legacy.md | 15 ++--- tests/testthat/_snaps/unnest-helper.md | 66 ++++++++------------- tests/testthat/_snaps/unnest-longer.md | 51 +++++++--------- tests/testthat/_snaps/unnest-wider.md | 5 +- tests/testthat/_snaps/unnest.md | 20 +++---- tests/testthat/test-append.R | 2 +- tests/testthat/test-chop.R | 6 +- tests/testthat/test-drop-na.R | 8 ++- tests/testthat/test-expand.R | 6 +- tests/testthat/test-extract.R | 16 +++-- tests/testthat/test-gather.R | 30 ++++++---- tests/testthat/test-hoist.R | 36 ++++++----- tests/testthat/test-nest-legacy.R | 8 +-- tests/testthat/test-pivot-long.R | 82 ++++++++++++++------------ tests/testthat/test-unnest-helper.R | 48 ++++++++------- tests/testthat/test-unnest-longer.R | 50 +++++++++------- tests/testthat/test-unnest-wider.R | 8 +-- tests/testthat/test-unnest.R | 8 +-- 25 files changed, 295 insertions(+), 295 deletions(-) diff --git a/tests/testthat/_snaps/append.md b/tests/testthat/_snaps/append.md index c41737a6b..b88a93d03 100644 --- a/tests/testthat/_snaps/append.md +++ b/tests/testthat/_snaps/append.md @@ -1,9 +1,8 @@ # after must be integer or character Code - (expect_error(df_append(df1, df2, after = 1.5))) - Output - + df_append(df1, df2, after = 1.5) + Condition Error in `df_append()`: ! `after` must be a whole number, not the number 1.5. i This is an internal error that was detected in the tidyr package. diff --git a/tests/testthat/_snaps/chop.md b/tests/testthat/_snaps/chop.md index a6d581dad..e8fbffc28 100644 --- a/tests/testthat/_snaps/chop.md +++ b/tests/testthat/_snaps/chop.md @@ -22,18 +22,16 @@ # incompatible sizes are caught Code - (expect_error(unchop(df, c(x, y)))) - Output - + unchop(df, c(x, y)) + Condition Error in `unchop()`: ! In row 1, can't recycle input of size 2 to size 3. # empty typed inputs are considered in common size, but NULLs aren't Code - (expect_error(unchop(df, c(x, y)))) - Output - + unchop(df, c(x, y)) + Condition Error in `unchop()`: ! In row 1, can't recycle input of size 0 to size 2. diff --git a/tests/testthat/_snaps/drop-na.md b/tests/testthat/_snaps/drop-na.md index 3b5302b26..7baa49c93 100644 --- a/tests/testthat/_snaps/drop-na.md +++ b/tests/testthat/_snaps/drop-na.md @@ -1,19 +1,14 @@ # errors are raised Code - (expect_error(drop_na(df, list()))) - Output - + drop_na(df, list()) + Condition Error in `drop_na()`: ! Can't select columns with `list()`. x `list()` must be numeric or character, not an empty list. - ---- - Code - (expect_error(drop_na(df, "z"))) - Output - + drop_na(df, "z") + Condition Error in `drop_na()`: ! Can't select columns that don't exist. x Column `z` doesn't exist. diff --git a/tests/testthat/_snaps/expand.md b/tests/testthat/_snaps/expand.md index 24cf35a1b..e3ac2c4de 100644 --- a/tests/testthat/_snaps/expand.md +++ b/tests/testthat/_snaps/expand.md @@ -1,9 +1,8 @@ # crossing checks for bad inputs Code - (expect_error(crossing(x = 1:10, y = quote(a)))) - Output - + crossing(x = 1:10, y = quote(a)) + Condition Error in `crossing()`: ! `..2` must be a vector, not a symbol. @@ -37,9 +36,8 @@ # expand_grid() can control name_repair Code - (expect_error(expand_grid(x = x, x = x))) - Output - + expand_grid(x = x, x = x) + Condition Error in `expand_grid()`: ! Names must be unique. x These names are duplicated: @@ -66,9 +64,8 @@ # grid_dots() reject non-vector input Code - (expect_error(grid_dots(lm(1 ~ 1)))) - Output - + grid_dots(lm(1 ~ 1)) + Condition Error: ! `..1` must be a vector, not a object. diff --git a/tests/testthat/_snaps/extract.md b/tests/testthat/_snaps/extract.md index bb8f779ed..b582ea478 100644 --- a/tests/testthat/_snaps/extract.md +++ b/tests/testthat/_snaps/extract.md @@ -1,24 +1,21 @@ # informative error message if wrong number of groups Code - (expect_error(extract(df, x, "y", "."))) - Output - + extract(df, x, "y", ".") + Condition Error in `extract()`: ! `regex` should define 1 groups; 0 found. Code - (expect_error(extract(df, x, c("y", "z"), "."))) - Output - + extract(df, x, c("y", "z"), ".") + Condition Error in `extract()`: ! `regex` should define 2 groups; 0 found. # informative error if using stringr modifier functions (#693) Code - (expect_error(extract(df, x, "x", regex = regex))) - Output - + extract(df, x, "x", regex = regex) + Condition Error in `extract()`: ! `regex` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/gather.md b/tests/testthat/_snaps/gather.md index 3322d1115..c14d5b4b4 100644 --- a/tests/testthat/_snaps/gather.md +++ b/tests/testthat/_snaps/gather.md @@ -1,35 +1,41 @@ # gather throws error for POSIXlt Code - (expect_error(gather(df, key, val, -x))) - Output - + gather(df, key, val, -x) + Condition + Error: + ! 'x' is a POSIXlt. Please convert to POSIXct. Code - (expect_error(gather(df, key, val, -y))) - Output - + gather(df, key, val, -y) + Condition + Error: + ! Column 1 is a POSIXlt. Please convert to POSIXct. # gather throws error for weird objects Code - (expect_error(gather(df, key, val, -x))) - Output - + gather(d, key, val, -x) + Condition + Error: + ! object 'd' not found Code - (expect_error(gather(df, key, val, -y))) - Output - + gather(df, key, val, -y) + Condition + Error: + ! All columns be atomic vectors or lists (not expression) --- Code - (expect_error(gather(df, key, val, -x))) - Output - + gather(df, key, val, -x) + Condition + Error: + ! All columns must be atomic vectors or lists. Problem with 'x' Code - (expect_error(gather(df, key, val, -y))) - Output - + gather(df, key, val, -y) + Condition + Error: + ! All columns must be atomic vectors or lists. Problem with column 2. # factors coerced to characters, not integers diff --git a/tests/testthat/_snaps/hoist.md b/tests/testthat/_snaps/hoist.md index 3291a2d91..3f797985a 100644 --- a/tests/testthat/_snaps/hoist.md +++ b/tests/testthat/_snaps/hoist.md @@ -1,39 +1,34 @@ # nested lists generate a cast error if they can't be cast to the ptype Code - (expect_error(hoist(df, x, "b", .ptype = list(b = double())))) - Output - + hoist(df, x, "b", .ptype = list(b = double())) + Condition Error in `hoist()`: ! Can't convert `..1` to . # non-vectors generate a cast error if a ptype is supplied Code - (expect_error(hoist(df, x, "b", .ptype = list(b = integer())))) - Output - + hoist(df, x, "b", .ptype = list(b = integer())) + Condition Error in `hoist()`: ! `..1` must be a vector, not a symbol. # input validation catches problems Code - (expect_error(df %>% hoist(y))) - Output - + df %>% hoist(y) + Condition Error in `hoist()`: ! `.data[[.col]]` must be a list, not the number 1. Code - (expect_error(df %>% hoist(x, 1))) - Output - + df %>% hoist(x, 1) + Condition Error in `hoist()`: ! All elements of `...` must be named. Code - (expect_error(df %>% hoist(x, a = "a", a = "b"))) - Output - + df %>% hoist(x, a = "a", a = "b") + Condition Error in `hoist()`: ! The names of `...` must be unique. diff --git a/tests/testthat/_snaps/nest-legacy.md b/tests/testthat/_snaps/nest-legacy.md index a9694b0c6..c3d896f1a 100644 --- a/tests/testthat/_snaps/nest-legacy.md +++ b/tests/testthat/_snaps/nest-legacy.md @@ -1,9 +1,8 @@ # can't combine vectors and data frames Code - (expect_error(unnest_legacy(df))) - Output - + unnest_legacy(df) + Condition Error in `unnest_legacy()`: ! Each column must either be a list of vectors or a list of data frames. i Problems in: `x` @@ -11,18 +10,16 @@ # multiple columns must be same length Code - (expect_error(unnest_legacy(df))) - Output - + unnest_legacy(df) + Condition Error in `unnest_legacy()`: ! All nested columns must have the same number of elements. --- Code - (expect_error(unnest_legacy(df))) - Output - + unnest_legacy(df) + Condition Error in `unnest_legacy()`: ! All nested columns must have the same number of elements. diff --git a/tests/testthat/_snaps/unnest-helper.md b/tests/testthat/_snaps/unnest-helper.md index 578f23846..ed371b559 100644 --- a/tests/testthat/_snaps/unnest-helper.md +++ b/tests/testthat/_snaps/unnest-helper.md @@ -1,91 +1,77 @@ # `simplify` is validated Code - (expect_error(df_simplify(data.frame(), simplify = 1))) - Output - + df_simplify(data.frame(), simplify = 1) + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code - (expect_error(df_simplify(data.frame(), simplify = NA))) - Output - + df_simplify(data.frame(), simplify = NA) + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code - (expect_error(df_simplify(data.frame(), simplify = c(TRUE, FALSE)))) - Output - + df_simplify(data.frame(), simplify = c(TRUE, FALSE)) + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code - (expect_error(df_simplify(data.frame(), simplify = list(1)))) - Output - + df_simplify(data.frame(), simplify = list(1)) + Condition Error: ! All elements of `simplify` must be named. Code - (expect_error(df_simplify(data.frame(), simplify = list(x = 1, x = 1)))) - Output - + df_simplify(data.frame(), simplify = list(x = 1, x = 1)) + Condition Error: ! The names of `simplify` must be unique. # `ptype` is validated Code - (expect_error(df_simplify(data.frame(), ptype = 1))) - Output - + df_simplify(data.frame(), ptype = 1) + Condition Error: ! `ptype` must be `NULL`, an empty ptype, or a named list of ptypes. Code - (expect_error(df_simplify(data.frame(), ptype = list(1)))) - Output - + df_simplify(data.frame(), ptype = list(1)) + Condition Error: ! All elements of `ptype` must be named. Code - (expect_error(df_simplify(data.frame(), ptype = list(x = 1, x = 1)))) - Output - + df_simplify(data.frame(), ptype = list(x = 1, x = 1)) + Condition Error: ! The names of `ptype` must be unique. # `transform` is validated Code - (expect_error(df_simplify(data.frame(), transform = list(~.x)))) - Output - + df_simplify(data.frame(), transform = list(~.x)) + Condition Error: ! All elements of `transform` must be named. Code - (expect_error(df_simplify(data.frame(x = 1), transform = 1))) - Output - + df_simplify(data.frame(x = 1), transform = 1) + Condition Error: ! `transform` must be `NULL`, a function, or a named list of functions. Code - (expect_error(df_simplify(data.frame(), transform = list(x = 1)))) - Output - + df_simplify(data.frame(), transform = list(x = 1)) + Condition Error: ! Can't convert `transform$x`, a double vector, to a function. Code - (expect_error(df_simplify(data.frame(), transform = list(x = 1, x = 1)))) - Output - + df_simplify(data.frame(), transform = list(x = 1, x = 1)) + Condition Error: ! The names of `transform` must be unique. # ptype is applied after transform Code - (expect_error(col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + - 1.5))) - Output - + col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5) + Condition Error: ! Can't convert from `..1` to due to loss of precision. * Locations: 1 diff --git a/tests/testthat/_snaps/unnest-longer.md b/tests/testthat/_snaps/unnest-longer.md index 6ed330d51..79ad6b77f 100644 --- a/tests/testthat/_snaps/unnest-longer.md +++ b/tests/testthat/_snaps/unnest-longer.md @@ -1,9 +1,8 @@ # unnest_longer - bad inputs generate errors Code - (expect_error(unnest_longer(df, y))) - Output - + unnest_longer(df, y) + Condition Error in `unnest_longer()`: ! List-column `y` must contain only vectors or `NULL`. @@ -18,10 +17,8 @@ # can't mix `indices_to` with `indices_include = FALSE` Code - (expect_error(unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE)) - ) - Output - + unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE) + Condition Error in `unnest_longer()`: ! Can't use `indices_include = FALSE` when `indices_to` is supplied. @@ -56,60 +53,52 @@ # `values_to` is validated Code - (expect_error(unnest_longer(mtcars, mpg, values_to = 1))) - Output - + unnest_longer(mtcars, mpg, values_to = 1) + Condition Error in `unnest_longer()`: ! `values_to` must be a valid name or `NULL`, not the number 1. Code - (expect_error(unnest_longer(mtcars, mpg, values_to = c("x", "y")))) - Output - + unnest_longer(mtcars, mpg, values_to = c("x", "y")) + Condition Error in `unnest_longer()`: ! `values_to` must be a valid name or `NULL`, not a character vector. # `indices_to` is validated Code - (expect_error(unnest_longer(mtcars, mpg, indices_to = 1))) - Output - + unnest_longer(mtcars, mpg, indices_to = 1) + Condition Error in `unnest_longer()`: ! `indices_to` must be a valid name or `NULL`, not the number 1. Code - (expect_error(unnest_longer(mtcars, mpg, indices_to = c("x", "y")))) - Output - + unnest_longer(mtcars, mpg, indices_to = c("x", "y")) + Condition Error in `unnest_longer()`: ! `indices_to` must be a valid name or `NULL`, not a character vector. # `indices_include` is validated Code - (expect_error(unnest_longer(mtcars, mpg, indices_include = 1))) - Output - + unnest_longer(mtcars, mpg, indices_include = 1) + Condition Error in `unnest_longer()`: ! `indices_include` must be `TRUE`, `FALSE`, or `NULL`, not the number 1. Code - (expect_error(unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)))) - Output - + unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)) + Condition Error in `unnest_longer()`: ! `indices_include` must be `TRUE`, `FALSE`, or `NULL`, not a logical vector. # `keep_empty` is validated Code - (expect_error(unnest_longer(mtcars, mpg, keep_empty = 1))) - Output - + unnest_longer(mtcars, mpg, keep_empty = 1) + Condition Error in `unnest_longer()`: ! `keep_empty` must be `TRUE` or `FALSE`, not the number 1. Code - (expect_error(unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)))) - Output - + unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)) + Condition Error in `unnest_longer()`: ! `keep_empty` must be `TRUE` or `FALSE`, not a logical vector. diff --git a/tests/testthat/_snaps/unnest-wider.md b/tests/testthat/_snaps/unnest-wider.md index c516c4fb3..e178d3cd8 100644 --- a/tests/testthat/_snaps/unnest-wider.md +++ b/tests/testthat/_snaps/unnest-wider.md @@ -1,9 +1,8 @@ # unnest_wider - bad inputs generate errors Code - (expect_error(unnest_wider(df, y))) - Output - + unnest_wider(df, y) + Condition Error in `unnest_wider()`: i In column: `y`. i In row: 1. diff --git a/tests/testthat/_snaps/unnest.md b/tests/testthat/_snaps/unnest.md index d470b3867..77c068267 100644 --- a/tests/testthat/_snaps/unnest.md +++ b/tests/testthat/_snaps/unnest.md @@ -1,36 +1,32 @@ # bad inputs generate errors Code - (expect_error(unnest(df, y))) - Output - + unnest(df, y) + Condition Error in `list_sizes()`: ! `x[[1]]` must be a vector, not a function. # multiple columns must be same length Code - (expect_error(unnest(df, c(x, y)))) - Output - + unnest(df, c(x, y)) + Condition Error in `unnest()`: ! In row 1, can't recycle input of size 2 to size 3. --- Code - (expect_error(unnest(df, c(x, y)))) - Output - + unnest(df, c(x, y)) + Condition Error in `unnest()`: ! In row 1, can't recycle input of size 2 to size 3. # unnesting column of mixed vector / data frame input is an error Code - (expect_error(unnest(df, x))) - Output - + unnest(df, x) + Condition Error in `unnest()`: ! Can't combine `x[[1]]` and `x[[2]]` . diff --git a/tests/testthat/test-append.R b/tests/testthat/test-append.R index 7385992dd..87ff70b8f 100644 --- a/tests/testthat/test-append.R +++ b/tests/testthat/test-append.R @@ -31,7 +31,7 @@ test_that("after must be integer or character", { df1 <- data.frame(x = 1) df2 <- data.frame(x = 2) - expect_snapshot((expect_error(df_append(df1, df2, after = 1.5)))) + expect_snapshot(df_append(df1, df2, after = 1.5), error = TRUE, cnd_class = TRUE) }) test_that("always returns a bare data frame", { diff --git a/tests/testthat/test-chop.R b/tests/testthat/test-chop.R index 6490dca6e..ac9ec5411 100644 --- a/tests/testthat/test-chop.R +++ b/tests/testthat/test-chop.R @@ -288,15 +288,15 @@ test_that("unchop works with record columns (treating them like vectors)", { test_that("incompatible sizes are caught", { df <- tibble(x = list(1:2), y = list(1:3)) - expect_snapshot((expect_error(unchop(df, c(x, y))))) + expect_snapshot(unchop(df, c(x, y)), error = TRUE, cnd_class = TRUE) }) test_that("empty typed inputs are considered in common size, but NULLs aren't", { df <- tibble(x = list(NULL), y = list(1:2)) - expect_error(unchop(df, c(x, y)), NA) + expect_no_error(unchop(df, c(x, y))) df <- tibble(x = list(integer()), y = list(1:2)) - expect_snapshot((expect_error(unchop(df, c(x, y))))) + expect_snapshot(unchop(df, c(x, y)), error = TRUE, cnd_class = TRUE) }) test_that("unchopping retains inner names from tibble elements", { diff --git a/tests/testthat/test-drop-na.R b/tests/testthat/test-drop-na.R index 1795cb940..c24e36778 100644 --- a/tests/testthat/test-drop-na.R +++ b/tests/testthat/test-drop-na.R @@ -37,8 +37,12 @@ test_that("groups are preserved", { test_that("errors are raised", { df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) - expect_snapshot((expect_error(drop_na(df, list())))) - expect_snapshot((expect_error(drop_na(df, "z")))) + expect_snapshot(error = TRUE, { + drop_na(df, list()) + drop_na(df, "z") + }, + cnd_class = TRUE + ) }) test_that("single variable data.frame doesn't lose dimension", { diff --git a/tests/testthat/test-expand.R b/tests/testthat/test-expand.R index 0601a53ff..08b8ad99a 100644 --- a/tests/testthat/test-expand.R +++ b/tests/testthat/test-expand.R @@ -174,7 +174,7 @@ test_that("expand() retains `NA` data in factors (#1275)", { # ------------------------------------------------------------------------------ test_that("crossing checks for bad inputs", { - expect_snapshot((expect_error(crossing(x = 1:10, y = quote(a))))) + expect_snapshot(crossing(x = 1:10, y = quote(a)), error = TRUE, cnd_class = TRUE) }) test_that("preserves NAs", { @@ -320,7 +320,7 @@ test_that("crossing() / nesting() retain `NA` data in factors (#1275)", { test_that("expand_grid() can control name_repair", { x <- 1:2 - expect_snapshot((expect_error(expand_grid(x = x, x = x)))) + expect_snapshot(expand_grid(x = x, x = x), error = TRUE, cnd_class = TRUE) expect_snapshot( out <- expand_grid(x = x, x = x, .name_repair = "unique") @@ -460,7 +460,7 @@ test_that("grid_dots() drops `NULL`s", { }) test_that("grid_dots() reject non-vector input", { - expect_snapshot((expect_error(grid_dots(lm(1 ~ 1))))) + expect_snapshot(grid_dots(lm(1 ~ 1)), error = TRUE, cnd_class = TRUE) }) # ------------------------------------------------------------------------------ diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R index ca87632ae..440f55c11 100644 --- a/tests/testthat/test-extract.R +++ b/tests/testthat/test-extract.R @@ -47,17 +47,23 @@ test_that("groups are preserved", { test_that("informative error message if wrong number of groups", { df <- tibble(x = "a") - expect_snapshot({ - (expect_error(extract(df, x, "y", "."))) - (expect_error(extract(df, x, c("y", "z"), "."))) - }) + expect_snapshot(error = TRUE, { + extract(df, x, "y", ".") + extract(df, x, c("y", "z"), ".") + }, + cnd_class = TRUE + ) }) test_that("informative error if using stringr modifier functions (#693)", { df <- tibble(x = "a") regex <- structure("a", class = "pattern") - expect_snapshot((expect_error(extract(df, x, "x", regex = regex)))) + expect_snapshot( + extract(df, x, "x", regex = regex), + error = TRUE, + cnd_class = TRUE + ) }) test_that("str_match_first handles edge cases", { diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index bccba7f2d..9ad415a88 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -124,30 +124,36 @@ test_that("gather throws error for POSIXlt", { df <- data.frame(y = 1) df$x <- as.POSIXlt(Sys.time()) - expect_snapshot({ - (expect_error(gather(df, key, val, -x))) - (expect_error(gather(df, key, val, -y))) - }) + expect_snapshot(error = TRUE, { + gather(df, key, val, -x) + gather(df, key, val, -y) + }, + cnd_class = TRUE + ) }) test_that("gather throws error for weird objects", { df <- data.frame(y = 1) df$x <- expression(x) - expect_snapshot({ - (expect_error(gather(df, key, val, -x))) - (expect_error(gather(df, key, val, -y))) - }) + expect_snapshot(error = TRUE, { + gather(d, key, val, -x) + gather(df, key, val, -y) + }, + cnd_class = TRUE + ) e <- new.env(parent = emptyenv()) e$x <- 1 df <- data.frame(y = 1) df$x <- e - expect_snapshot({ - (expect_error(gather(df, key, val, -x))) - (expect_error(gather(df, key, val, -y))) - }) + expect_snapshot(error = TRUE, { + gather(df, key, val, -x) + gather(df, key, val, -y) + }, + cnd_class = TRUE + ) }) diff --git a/tests/testthat/test-hoist.R b/tests/testthat/test-hoist.R index 7323a1e8f..3f8cde23c 100644 --- a/tests/testthat/test-hoist.R +++ b/tests/testthat/test-hoist.R @@ -33,17 +33,21 @@ test_that("can check check/transform values", { test_that("nested lists generate a cast error if they can't be cast to the ptype", { df <- tibble(x = list(list(b = list(1)))) - expect_snapshot((expect_error( - hoist(df, x, "b", .ptype = list(b = double())) - ))) + expect_snapshot( + hoist(df, x, "b", .ptype = list(b = double())), + error = TRUE, + cnd_class = TRUE + ) }) test_that("non-vectors generate a cast error if a ptype is supplied", { df <- tibble(x = list(list(b = quote(a)))) - expect_snapshot((expect_error( - hoist(df, x, "b", .ptype = list(b = integer())) - ))) + expect_snapshot( + hoist(df, x, "b", .ptype = list(b = integer())), + error = TRUE, + cnd_class = TRUE + ) }) test_that("a ptype generates a list-of if the col can't be simplified (#998)", { @@ -99,11 +103,13 @@ test_that("can hoist out scalars", { test_that("input validation catches problems", { df <- tibble(x = list(list(1, b = "b")), y = 1) - expect_snapshot({ - (expect_error(df %>% hoist(y))) - (expect_error(df %>% hoist(x, 1))) - (expect_error(df %>% hoist(x, a = "a", a = "b"))) - }) + expect_snapshot(error = TRUE, { + df %>% hoist(y) + df %>% hoist(x, 1) + df %>% hoist(x, a = "a", a = "b") + }, + cnd_class = TRUE + ) }) test_that("string pluckers are automatically named", { @@ -114,9 +120,11 @@ test_that("string pluckers are automatically named", { test_that("can't hoist() from a data frame column", { df <- tibble(a = tibble(x = 1)) - expect_snapshot((expect_error( - hoist(df, a, xx = 1) - ))) + expect_snapshot( + hoist(df, a, xx = 1), + error = TRUE, + cnd_class = TRUE + ) }) test_that("can hoist() without any pluckers", { diff --git a/tests/testthat/test-nest-legacy.R b/tests/testthat/test-nest-legacy.R index 3551728bc..6fc9a2ba9 100644 --- a/tests/testthat/test-nest-legacy.R +++ b/tests/testthat/test-nest-legacy.R @@ -143,20 +143,20 @@ test_that("elements must all be of same type", { test_that("can't combine vectors and data frames", { df <- tibble(x = list(1, tibble(1))) - expect_snapshot((expect_error(unnest_legacy(df)))) + expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) }) test_that("multiple columns must be same length", { df <- tibble(x = list(1), y = list(1:2)) - expect_snapshot((expect_error(unnest_legacy(df)))) + expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) df <- tibble(x = list(1), y = list(tibble(x = 1:2))) - expect_snapshot((expect_error(unnest_legacy(df)))) + expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) }) test_that("nested is split as a list (#84)", { df <- tibble(x = 1:3, y = list(1, 2:3, 4), z = list(5, 6:7, 8)) - expect_warning(out <- unnest_legacy(df, y, z), NA) + expect_no_warning(out <- unnest_legacy(df, y, z)) expect_equal(out$x, c(1, 2, 2, 3)) expect_equal(out$y, unlist(df$y)) expect_equal(out$z, unlist(df$z)) diff --git a/tests/testthat/test-pivot-long.R b/tests/testthat/test-pivot-long.R index 8bb7936b0..eb0979161 100644 --- a/tests/testthat/test-pivot-long.R +++ b/tests/testthat/test-pivot-long.R @@ -147,32 +147,32 @@ test_that("type error message use variable names", { test_that("when `values_ptypes` is provided, the type error uses variable names (#1364)", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(pivot_longer(df, x, values_ptypes = character()))) - }) + expect_snapshot(error = TRUE, { + pivot_longer(df, x, values_ptypes = character()) + }, + cnd_class = TRUE + ) }) test_that("when `names_ptypes` is provided, the type error uses `names_to` names (#1364)", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error({ + expect_snapshot(error = TRUE, { pivot_longer( df, cols = x, names_to = "name", names_ptypes = double() ) - })) - }) + }, + cnd_class = TRUE + ) }) test_that("error when overwriting existing column", { df <- tibble(x = 1, y = 2) - expect_snapshot( - (expect_error(pivot_longer(df, y, names_to = "x"))) - ) + expect_snapshot(pivot_longer(df, y, names_to = "x"), error = TRUE, cnd_class = TRUE) expect_snapshot( out <- pivot_longer(df, y, names_to = "x", names_repair = "unique") @@ -267,19 +267,19 @@ test_that("no names doesn't generate names (#1120)", { test_that("multiple names requires names_sep/names_pattern", { df <- tibble(x_y = 1) - expect_snapshot({ - (expect_error(build_longer_spec(df, x_y, names_to = c("a", "b")))) + expect_snapshot(error = TRUE, { + build_longer_spec(df, x_y, names_to = c("a", "b")) - (expect_error( - build_longer_spec( - df, - x_y, - names_to = c("a", "b"), - names_sep = "x", - names_pattern = "x" - ) - )) - }) + build_longer_spec( + df, + x_y, + names_to = c("a", "b"), + names_sep = "x", + names_pattern = "x" + ) + }, + cnd_class = TRUE + ) }) test_that("names_sep generates correct spec", { @@ -293,9 +293,11 @@ test_that("names_sep generates correct spec", { test_that("names_sep fails with single name", { df <- tibble(x_y = 1) - expect_snapshot({ - (expect_error(build_longer_spec(df, x_y, names_to = "x", names_sep = "_"))) - }) + expect_snapshot(error = TRUE, { + build_longer_spec(df, x_y, names_to = "x", names_sep = "_") + }, + cnd_class = TRUE + ) }) test_that("names_pattern generates correct spec", { @@ -435,9 +437,11 @@ test_that("`values_transform` works with single functions (#1284)", { }) test_that("Error if the `col` can't be selected.", { - expect_snapshot({ - (expect_error(pivot_longer(iris, matches("foo")))) - }) + expect_snapshot(error = TRUE, { + pivot_longer(iris, matches("foo")) + }, + cnd_class = TRUE + ) }) test_that("named `cols` gives clear error (#1104)", { @@ -448,20 +452,24 @@ test_that("named `cols` gives clear error (#1104)", { test_that("`names_to` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(build_longer_spec(df, x, names_to = 1))) - (expect_error(build_longer_spec(df, x, names_to = c("x", "y")))) - (expect_error(build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x"))) - }) + expect_snapshot(error = TRUE, { + build_longer_spec(df, x, names_to = 1) + build_longer_spec(df, x, names_to = c("x", "y")) + build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") + }, + cnd_class = TRUE + ) }) test_that("`names_ptypes` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(build_longer_spec(df, x, names_ptypes = 1))) - (expect_error(build_longer_spec(df, x, names_ptypes = list(integer())))) - }) + expect_snapshot(error = TRUE, { + build_longer_spec(df, x, names_ptypes = 1) + build_longer_spec(df, x, names_ptypes = list(integer())) + }, + cnd_class = TRUE + ) }) test_that("`names_transform` is validated", { diff --git a/tests/testthat/test-unnest-helper.R b/tests/testthat/test-unnest-helper.R index b96e79236..38c9386b2 100644 --- a/tests/testthat/test-unnest-helper.R +++ b/tests/testthat/test-unnest-helper.R @@ -1,30 +1,36 @@ # df_simplify ------------------------------------------------------------ test_that("`simplify` is validated", { - expect_snapshot({ - (expect_error(df_simplify(data.frame(), simplify = 1))) - (expect_error(df_simplify(data.frame(), simplify = NA))) - (expect_error(df_simplify(data.frame(), simplify = c(TRUE, FALSE)))) - (expect_error(df_simplify(data.frame(), simplify = list(1)))) - (expect_error(df_simplify(data.frame(), simplify = list(x = 1, x = 1)))) - }) + expect_snapshot(error = TRUE, { + df_simplify(data.frame(), simplify = 1) + df_simplify(data.frame(), simplify = NA) + df_simplify(data.frame(), simplify = c(TRUE, FALSE)) + df_simplify(data.frame(), simplify = list(1)) + df_simplify(data.frame(), simplify = list(x = 1, x = 1)) + }, + cnd_class = TRUE + ) }) test_that("`ptype` is validated", { - expect_snapshot({ - (expect_error(df_simplify(data.frame(), ptype = 1))) - (expect_error(df_simplify(data.frame(), ptype = list(1)))) - (expect_error(df_simplify(data.frame(), ptype = list(x = 1, x = 1)))) - }) + expect_snapshot(error = TRUE, { + df_simplify(data.frame(), ptype = 1) + df_simplify(data.frame(), ptype = list(1)) + df_simplify(data.frame(), ptype = list(x = 1, x = 1)) + }, + cnd_class = TRUE + ) }) test_that("`transform` is validated", { - expect_snapshot({ - (expect_error(df_simplify(data.frame(), transform = list(~.x)))) - (expect_error(df_simplify(data.frame(x = 1), transform = 1))) - (expect_error(df_simplify(data.frame(), transform = list(x = 1)))) - (expect_error(df_simplify(data.frame(), transform = list(x = 1, x = 1)))) - }) + expect_snapshot(error = TRUE, { + df_simplify(data.frame(), transform = list(~.x)) + df_simplify(data.frame(x = 1), transform = 1) + df_simplify(data.frame(), transform = list(x = 1)) + df_simplify(data.frame(), transform = list(x = 1, x = 1)) + }, + cnd_class = TRUE + ) }) test_that("`simplify` can be a named list (#995)", { @@ -140,9 +146,11 @@ test_that("ptype is applied after transform", { c(2L, 3L, 4L) ) - expect_snapshot((expect_error( + expect_snapshot(error = TRUE, { col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5) - ))) + }, + cnd_class = TRUE + ) }) test_that("lists of lists aren't simplified", { diff --git a/tests/testthat/test-unnest-longer.R b/tests/testthat/test-unnest-longer.R index 7ee6a8beb..0e72c7e12 100644 --- a/tests/testthat/test-unnest-longer.R +++ b/tests/testthat/test-unnest-longer.R @@ -46,9 +46,7 @@ test_that("can unnest dates", { test_that("unnest_longer - bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot((expect_error( - unnest_longer(df, y) - ))) + expect_snapshot(unnest_longer(df, y), error = TRUE, cnd_class = TRUE) }) test_that("list_of columns can be unnested", { @@ -378,9 +376,11 @@ test_that("can't currently retain names when simplification isn't done and a pty }) test_that("can't mix `indices_to` with `indices_include = FALSE`", { - expect_snapshot((expect_error( + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE) - ))) + }, + cnd_class = TRUE + ) }) test_that("unnest_longer() validates its inputs", { @@ -402,29 +402,37 @@ test_that("`values_to` and `indices_to` glue can't reach into surrounding env", }) test_that("`values_to` is validated", { - expect_snapshot({ - (expect_error(unnest_longer(mtcars, mpg, values_to = 1))) - (expect_error(unnest_longer(mtcars, mpg, values_to = c("x", "y")))) - }) + expect_snapshot(error = TRUE, { + unnest_longer(mtcars, mpg, values_to = 1) + unnest_longer(mtcars, mpg, values_to = c("x", "y")) + }, + cnd_class = TRUE + ) }) test_that("`indices_to` is validated", { - expect_snapshot({ - (expect_error(unnest_longer(mtcars, mpg, indices_to = 1))) - (expect_error(unnest_longer(mtcars, mpg, indices_to = c("x", "y")))) - }) + expect_snapshot(error = TRUE, { + unnest_longer(mtcars, mpg, indices_to = 1) + unnest_longer(mtcars, mpg, indices_to = c("x", "y")) + }, + cnd_class = TRUE + ) }) test_that("`indices_include` is validated", { - expect_snapshot({ - (expect_error(unnest_longer(mtcars, mpg, indices_include = 1))) - (expect_error(unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)))) - }) + expect_snapshot(error = TRUE, { + unnest_longer(mtcars, mpg, indices_include = 1) + unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)) + }, + cnd_class = TRUE + ) }) test_that("`keep_empty` is validated", { - expect_snapshot({ - (expect_error(unnest_longer(mtcars, mpg, keep_empty = 1))) - (expect_error(unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)))) - }) + expect_snapshot(error = TRUE, { + unnest_longer(mtcars, mpg, keep_empty = 1) + unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)) + }, + cnd_class = TRUE + ) }) diff --git a/tests/testthat/test-unnest-wider.R b/tests/testthat/test-unnest-wider.R index a924bf392..6a8c51eaf 100644 --- a/tests/testthat/test-unnest-wider.R +++ b/tests/testthat/test-unnest-wider.R @@ -53,9 +53,7 @@ test_that("treats data frames like lists where we have type info about each elem test_that("unnest_wider - bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot((expect_error( - unnest_wider(df, y) - ))) + expect_snapshot(unnest_wider(df, y), error = TRUE, cnd_class = TRUE) }) test_that("list of 0-length vectors yields no new columns", { @@ -94,10 +92,10 @@ test_that("names_sep creates unique names", { x = list("a", c("a", "b", "c")), y = list(c(a = 1), c(b = 2, a = 1)) ) - expect_warning(out <- unnest_wider(df, x, names_sep = "_"), NA) + expect_no_warning(out <- unnest_wider(df, x, names_sep = "_")) expect_named(out, c("x_1", "x_2", "x_3", "y")) - expect_warning(out <- unnest_wider(df, y, names_sep = "_"), NA) + expect_no_warning(out <- unnest_wider(df, y, names_sep = "_")) expect_named(out, c("x", "y_a", "y_b")) expect_equal(out$y_a, c(1, 1)) }) diff --git a/tests/testthat/test-unnest.R b/tests/testthat/test-unnest.R index 76a505759..402854836 100644 --- a/tests/testthat/test-unnest.R +++ b/tests/testthat/test-unnest.R @@ -22,7 +22,7 @@ test_that("empty rows still affect output type", { test_that("bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot((expect_error(unnest(df, y)))) + expect_snapshot(unnest(df, y), error = TRUE, cnd_class = TRUE) }) test_that("unnesting combines augmented vectors", { @@ -96,10 +96,10 @@ test_that("vectors become columns", { test_that("multiple columns must be same length", { df <- tibble(x = list(1:2), y = list(1:3)) - expect_snapshot((expect_error(unnest(df, c(x, y))))) + expect_snapshot(unnest(df, c(x, y)), error = TRUE, cnd_class = TRUE) df <- tibble(x = list(1:2), y = list(tibble(y = 1:3))) - expect_snapshot((expect_error(unnest(df, c(x, y))))) + expect_snapshot(unnest(df, c(x, y)), error = TRUE, cnd_class = TRUE) }) test_that("can use non-syntactic names", { @@ -114,7 +114,7 @@ test_that("unpacks df-cols (#1112)", { test_that("unnesting column of mixed vector / data frame input is an error", { df <- tibble(x = list(1, tibble(a = 1))) - expect_snapshot((expect_error(unnest(df, x)))) + expect_snapshot(unnest(df, x), error = TRUE, cnd_class = TRUE) }) test_that("unnest() advises on outer / inner name duplication", { From bd624cd76d23e247c6fcdf8fed22a5d042c09c9f Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 14:39:37 -0400 Subject: [PATCH 04/10] Standardize snapshot tests. and use `cnd_class = TRUE` if `expect_error()` was used. Put cnd_class on the first line to make it easy to remove it as needed. --- tests/testthat/_snaps/hoist.md | 5 +- tests/testthat/_snaps/pivot-long.md | 136 +++++++++++----------------- tests/testthat/_snaps/pivot-wide.md | 119 ++++++++++-------------- tests/testthat/_snaps/pivot.md | 25 ++--- tests/testthat/_snaps/replace_na.md | 15 ++- tests/testthat/_snaps/separate.md | 5 +- tests/testthat/_snaps/seq.md | 10 +- tests/testthat/_snaps/spread.md | 5 +- tests/testthat/test-drop-na.R | 11 +-- tests/testthat/test-extract.R | 14 +-- tests/testthat/test-gather.R | 18 ++-- tests/testthat/test-hoist.R | 6 +- tests/testthat/test-pivot-long.R | 96 +++++++++----------- tests/testthat/test-pivot-wide.R | 103 +++++++++++---------- tests/testthat/test-pivot.R | 12 +-- tests/testthat/test-replace_na.R | 6 +- tests/testthat/test-separate.R | 2 +- tests/testthat/test-seq.R | 6 +- tests/testthat/test-spread.R | 2 +- tests/testthat/test-unnest-helper.R | 24 ++--- tests/testthat/test-unnest-longer.R | 30 ++---- 21 files changed, 267 insertions(+), 383 deletions(-) diff --git a/tests/testthat/_snaps/hoist.md b/tests/testthat/_snaps/hoist.md index 3f797985a..331c73d46 100644 --- a/tests/testthat/_snaps/hoist.md +++ b/tests/testthat/_snaps/hoist.md @@ -35,9 +35,8 @@ # can't hoist() from a data frame column Code - (expect_error(hoist(df, a, xx = 1))) - Output - + hoist(df, a, xx = 1) + Condition Error in `hoist()`: ! `.data[[.col]]` must be a list, not a object. diff --git a/tests/testthat/_snaps/pivot-long.md b/tests/testthat/_snaps/pivot-long.md index 477545174..4d08d978d 100644 --- a/tests/testthat/_snaps/pivot-long.md +++ b/tests/testthat/_snaps/pivot-long.md @@ -1,29 +1,24 @@ # when `values_ptypes` is provided, the type error uses variable names (#1364) Code - (expect_error(pivot_longer(df, x, values_ptypes = character()))) - Output - + pivot_longer(df, x, values_ptypes = character()) + Condition Error in `pivot_longer()`: ! Can't convert `x` to . # when `names_ptypes` is provided, the type error uses `names_to` names (#1364) Code - (expect_error({ - pivot_longer(df, cols = x, names_to = "name", names_ptypes = double()) - })) - Output - + pivot_longer(df, cols = x, names_to = "name", names_ptypes = double()) + Condition Error in `pivot_longer()`: ! Can't convert `name` to . # error when overwriting existing column Code - (expect_error(pivot_longer(df, y, names_to = "x"))) - Output - + pivot_longer(df, y, names_to = "x") + Condition Error in `pivot_longer()`: ! Names must be unique. x These names are duplicated: @@ -42,34 +37,30 @@ # multiple names requires names_sep/names_pattern Code - (expect_error(build_longer_spec(df, x_y, names_to = c("a", "b")))) - Output - + build_longer_spec(df, x_y, names_to = c("a", "b")) + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. Code - (expect_error(build_longer_spec(df, x_y, names_to = c("a", "b"), names_sep = "x", - names_pattern = "x"))) - Output - + build_longer_spec(df, x_y, names_to = c("a", "b"), names_sep = "x", + names_pattern = "x") + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. # names_sep fails with single name Code - (expect_error(build_longer_spec(df, x_y, names_to = "x", names_sep = "_"))) - Output - + build_longer_spec(df, x_y, names_to = "x", names_sep = "_") + Condition Error in `build_longer_spec()`: ! `names_sep` can't be used with a length 1 `names_to`. # Error if the `col` can't be selected. Code - (expect_error(pivot_longer(iris, matches("foo")))) - Output - + pivot_longer(iris, matches("foo")) + Condition Error in `pivot_longer()`: ! `cols` must select at least one column. @@ -84,116 +75,101 @@ # `names_to` is validated Code - (expect_error(build_longer_spec(df, x, names_to = 1))) - Output - + build_longer_spec(df, x, names_to = 1) + Condition Error in `build_longer_spec()`: ! `names_to` must be a character vector or `NULL`, not the number 1. Code - (expect_error(build_longer_spec(df, x, names_to = c("x", "y")))) - Output - + build_longer_spec(df, x, names_to = c("x", "y")) + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. Code - (expect_error(build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", - names_pattern = "x"))) - Output - + build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", + names_pattern = "x") + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. # `names_ptypes` is validated Code - (expect_error(build_longer_spec(df, x, names_ptypes = 1))) - Output - + build_longer_spec(df, x, names_ptypes = 1) + Condition Error in `build_longer_spec()`: ! `names_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code - (expect_error(build_longer_spec(df, x, names_ptypes = list(integer())))) - Output - + build_longer_spec(df, x, names_ptypes = list(integer())) + Condition Error in `build_longer_spec()`: ! All elements of `names_ptypes` must be named. # `names_transform` is validated Code - (expect_error(build_longer_spec(df, x, names_transform = 1))) - Output - + build_longer_spec(df, x, names_transform = 1) + Condition Error in `build_longer_spec()`: ! `names_transform` must be `NULL`, a function, or a named list of functions. Code - (expect_error(build_longer_spec(df, x, names_transform = list(~.x)))) - Output - + build_longer_spec(df, x, names_transform = list(~.x)) + Condition Error in `build_longer_spec()`: ! All elements of `names_transform` must be named. # `values_ptypes` is validated Code - (expect_error(pivot_longer(df, x, values_ptypes = 1))) - Output - + pivot_longer(df, x, values_ptypes = 1) + Condition Error in `pivot_longer()`: ! `values_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code - (expect_error(pivot_longer(df, x, values_ptypes = list(integer())))) - Output - + pivot_longer(df, x, values_ptypes = list(integer())) + Condition Error in `pivot_longer()`: ! All elements of `values_ptypes` must be named. # `values_transform` is validated Code - (expect_error(pivot_longer(df, x, values_transform = 1))) - Output - + pivot_longer(df, x, values_transform = 1) + Condition Error in `pivot_longer()`: ! `values_transform` must be `NULL`, a function, or a named list of functions. Code - (expect_error(pivot_longer(df, x, values_transform = list(~.x)))) - Output - + pivot_longer(df, x, values_transform = list(~.x)) + Condition Error in `pivot_longer()`: ! All elements of `values_transform` must be named. # `cols_vary` is validated Code - (expect_error(pivot_longer(df, x, cols_vary = "fast"))) - Output - + pivot_longer(df, x, cols_vary = "fast") + Condition Error in `pivot_longer()`: ! `cols_vary` must be one of "fastest" or "slowest", not "fast". i Did you mean "fastest"? Code - (expect_error(pivot_longer(df, x, cols_vary = 1))) - Output - + pivot_longer(df, x, cols_vary = 1) + Condition Error in `pivot_longer()`: ! `cols_vary` must be a string or character vector. # `pivot_longer()` catches unused input passed through the dots Code - (expect_error(pivot_longer(df, c(x, y), 1))) - Output - + pivot_longer(df, c(x, y), 1) + Condition Error in `pivot_longer()`: ! Arguments in `...` must be used. x Problematic argument: * ..1 = 1 i Did you misspell an argument name? Code - (expect_error(pivot_longer(df, c(x, y), col_vary = "slowest"))) - Output - + pivot_longer(df, c(x, y), col_vary = "slowest") + Condition Error in `pivot_longer()`: ! Arguments in `...` must be used. x Problematic argument: @@ -203,18 +179,16 @@ # `build_longer_spec()` requires empty dots Code - (expect_error(build_longer_spec(df, c(x, y), 1))) - Output - + build_longer_spec(df, c(x, y), 1) + Condition Error in `build_longer_spec()`: ! `...` must be empty. x Problematic argument: * ..1 = 1 i Did you forget to name an argument? Code - (expect_error(build_longer_spec(df, c(x, y), name_to = "name"))) - Output - + build_longer_spec(df, c(x, y), name_to = "name") + Condition Error in `build_longer_spec()`: ! `...` must be empty. x Problematic argument: @@ -223,18 +197,16 @@ # `pivot_longer_spec()` requires empty dots Code - (expect_error(pivot_longer_spec(df, spec, 1))) - Output - + pivot_longer_spec(df, spec, 1) + Condition Error in `pivot_longer_spec()`: ! `...` must be empty. x Problematic argument: * ..1 = 1 i Did you forget to name an argument? Code - (expect_error(pivot_longer_spec(df, spec, col_vary = "slowest"))) - Output - + pivot_longer_spec(df, spec, col_vary = "slowest") + Condition Error in `pivot_longer_spec()`: ! `...` must be empty. x Problematic argument: diff --git a/tests/testthat/_snaps/pivot-wide.md b/tests/testthat/_snaps/pivot-wide.md index 889a3a45c..bc7e7023c 100644 --- a/tests/testthat/_snaps/pivot-wide.md +++ b/tests/testthat/_snaps/pivot-wide.md @@ -9,9 +9,8 @@ # error when overwriting existing column Code - (expect_error(pivot_wider(df, names_from = key, values_from = val))) - Output - + pivot_wider(df, names_from = key, values_from = val) + Condition Error in `pivot_wider()`: ! Names must be unique. x These names are duplicated: @@ -30,9 +29,8 @@ # `names_from` must be supplied if `name` isn't in `data` (#1240) Code - (expect_error(pivot_wider(df, values_from = val))) - Output - + pivot_wider(df, values_from = val) + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `name` doesn't exist. @@ -40,9 +38,8 @@ # `values_from` must be supplied if `value` isn't in `data` (#1240) Code - (expect_error(pivot_wider(df, names_from = key))) - Output - + pivot_wider(df, names_from = key) + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `value` doesn't exist. @@ -50,29 +47,24 @@ # `names_from` must identify at least 1 column (#1240) Code - (expect_error(pivot_wider(df, names_from = starts_with("foo"), values_from = val)) - ) - Output - + pivot_wider(df, names_from = starts_with("foo"), values_from = val) + Condition Error in `pivot_wider()`: ! Must select at least one item. # `values_from` must identify at least 1 column (#1240) Code - (expect_error(pivot_wider(df, names_from = key, values_from = starts_with("foo"))) - ) - Output - + pivot_wider(df, names_from = key, values_from = starts_with("foo")) + Condition Error in `pivot_wider()`: ! Must select at least one item. # `values_fn` emits an informative error when it doesn't result in unique values (#1238) Code - (expect_error(pivot_wider(df, values_fn = list(value = ~.x)))) - Output - + pivot_wider(df, values_fn = list(value = ~.x)) + Condition Error in `pivot_wider()`: ! Applying `values_fn` to `value` must result in a single summary value per key. i Applying `values_fn` resulted in a vector of length 2. @@ -80,18 +72,16 @@ # `build_wider_spec()` requires empty dots Code - (expect_error(build_wider_spec(df, 1))) - Output - + build_wider_spec(df, 1) + Condition Error in `build_wider_spec()`: ! `...` must be empty. x Problematic argument: * ..1 = 1 i Did you forget to name an argument? Code - (expect_error(build_wider_spec(df, name_prefix = ""))) - Output - + build_wider_spec(df, name_prefix = "") + Condition Error in `build_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -100,18 +90,16 @@ # `pivot_wider_spec()` requires empty dots Code - (expect_error(pivot_wider_spec(df, spec, 1))) - Output - + pivot_wider_spec(df, spec, 1) + Condition Error in `pivot_wider_spec()`: ! `...` must be empty. x Problematic argument: * ..1 = 1 i Did you forget to name an argument? Code - (expect_error(pivot_wider_spec(df, spec, name_repair = "check_unique"))) - Output - + pivot_wider_spec(df, spec, name_repair = "check_unique") + Condition Error in `pivot_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -120,48 +108,40 @@ # `names_vary` is validated Code - (expect_error(build_wider_spec(df, names_vary = 1))) - Output - + build_wider_spec(df, names_vary = 1) + Condition Error in `build_wider_spec()`: ! `names_vary` must be a string or character vector. Code - (expect_error(build_wider_spec(df, names_vary = "x"))) - Output - + build_wider_spec(df, names_vary = "x") + Condition Error in `build_wider_spec()`: ! `names_vary` must be one of "fastest" or "slowest", not "x". # `names_expand` is validated Code - (expect_error(build_wider_spec(df, names_expand = 1))) - Output - + build_wider_spec(df, names_expand = 1) + Condition Error in `build_wider_spec()`: ! `names_expand` must be `TRUE` or `FALSE`, not the number 1. Code - (expect_error(build_wider_spec(df, names_expand = "x"))) - Output - + build_wider_spec(df, names_expand = "x") + Condition Error in `build_wider_spec()`: ! `names_expand` must be `TRUE` or `FALSE`, not the string "x". # `id_cols` can't select columns from `names_from` or `values_from` (#1318) Code - (expect_error(pivot_wider(df, id_cols = name, names_from = name, values_from = value)) - ) - Output - + pivot_wider(df, id_cols = name, names_from = name, values_from = value) + Condition Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `names_from`. i Column `name` has already been selected. Code - (expect_error(pivot_wider(df, id_cols = value, names_from = name, values_from = value)) - ) - Output - + pivot_wider(df, id_cols = value, names_from = name, values_from = value) + Condition Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `values_from`. i Column `value` has already been selected. @@ -169,9 +149,8 @@ # `id_cols` returns a tidyselect error if a column selection is OOB (#1318) Code - (expect_error(pivot_wider(df, id_cols = foo))) - Output - + pivot_wider(df, id_cols = foo) + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `foo` doesn't exist. @@ -187,15 +166,13 @@ # `id_expand` is validated Code - (expect_error(pivot_wider(df, id_expand = 1))) - Output - + pivot_wider(df, id_expand = 1) + Condition Error in `pivot_wider()`: ! `id_expand` must be `TRUE` or `FALSE`, not the number 1. Code - (expect_error(pivot_wider(df, id_expand = "x"))) - Output - + pivot_wider(df, id_expand = "x") + Condition Error in `pivot_wider()`: ! `id_expand` must be `TRUE` or `FALSE`, not the string "x". @@ -268,18 +245,16 @@ # values_fn is validated Code - (expect_error(pivot_wider(df, values_fn = 1))) - Output - + pivot_wider(df, values_fn = 1) + Condition Error in `pivot_wider()`: ! `values_fn` must be `NULL`, a function, or a named list of functions. # `unused_fn` must result in single summary values Code - (expect_error(pivot_wider(df, id_cols = id, unused_fn = identity))) - Output - + pivot_wider(df, id_cols = id, unused_fn = identity) + Condition Error in `pivot_wider()`: ! Applying `unused_fn` to `unused` must result in a single summary value per key. i Applying `unused_fn` resulted in a vector of length 2. @@ -287,18 +262,16 @@ # `values_fill` is validated Code - (expect_error(pivot_wider(df, values_fill = 1:2))) - Output - + pivot_wider(df, values_fill = 1:2) + Condition Error in `pivot_wider()`: ! `values_fill` must be `NULL`, a scalar, or a named list, not an integer vector. # `unused_fn` is validated Code - (expect_error(pivot_wider(df, id_cols = id, unused_fn = 1))) - Output - + pivot_wider(df, id_cols = id, unused_fn = 1) + Condition Error in `pivot_wider()`: ! `unused_fn` must be `NULL`, a function, or a named list of functions. diff --git a/tests/testthat/_snaps/pivot.md b/tests/testthat/_snaps/pivot.md index 86eb8a787..8b5552c7a 100644 --- a/tests/testthat/_snaps/pivot.md +++ b/tests/testthat/_snaps/pivot.md @@ -1,42 +1,37 @@ # basic sanity checks for spec occur Code - (expect_error(check_pivot_spec(1))) - Output - + check_pivot_spec(1) + Condition Error: ! `spec` must be a data frame, not a number. Code - (expect_error(check_pivot_spec(mtcars))) - Output - + check_pivot_spec(mtcars) + Condition Error: ! `spec` must have `.name` and `.value` columns. # `.name` column must be a character vector Code - (expect_error(check_pivot_spec(df))) - Output - + check_pivot_spec(df) + Condition Error: ! `spec$.name` must be a character vector, not an integer vector. # `.value` column must be a character vector Code - (expect_error(check_pivot_spec(df))) - Output - + check_pivot_spec(df) + Condition Error: ! `spec$.value` must be a character vector, not an integer vector. # `.name` column must be unique Code - (expect_error(check_pivot_spec(df))) - Output - + check_pivot_spec(df) + Condition Error: ! `spec$.name` must be unique. diff --git a/tests/testthat/_snaps/replace_na.md b/tests/testthat/_snaps/replace_na.md index 1614e0288..2cabd65cd 100644 --- a/tests/testthat/_snaps/replace_na.md +++ b/tests/testthat/_snaps/replace_na.md @@ -1,18 +1,16 @@ # can only be length 0 Code - (expect_error(replace_na(1, 1:10))) - Output - + replace_na(1, 1:10) + Condition Error in `replace_na()`: ! Replacement for `data` must be length 1, not length 10. # replacement must be castable to `data` Code - (expect_error(replace_na(x, 1.5))) - Output - + replace_na(x, 1.5) + Condition Error in `vec_assign()`: ! Can't convert from `replace` to `data` due to loss of precision. * Locations: 1 @@ -20,9 +18,8 @@ # replacement must be castable to corresponding column Code - (expect_error(replace_na(df, list(a = 1.5)))) - Output - + replace_na(df, list(a = 1.5)) + Condition Error in `vec_assign()`: ! Can't convert from `replace$a` to `data$a` due to loss of precision. * Locations: 1 diff --git a/tests/testthat/_snaps/separate.md b/tests/testthat/_snaps/separate.md index 33c9e861e..c0cc1a773 100644 --- a/tests/testthat/_snaps/separate.md +++ b/tests/testthat/_snaps/separate.md @@ -73,9 +73,8 @@ # informative error if using stringr modifier functions (#693) Code - (expect_error(separate(df, x, "x", sep = sep))) - Output - + separate(df, x, "x", sep = sep) + Condition Error in `separate()`: ! `sep` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/seq.md b/tests/testthat/_snaps/seq.md index 954eb6d91..261aaa1e4 100644 --- a/tests/testthat/_snaps/seq.md +++ b/tests/testthat/_snaps/seq.md @@ -1,15 +1,13 @@ # full_seq errors if sequence isn't regular Code - (expect_error(full_seq(c(1, 3, 4), 2))) - Output - + full_seq(c(1, 3, 4), 2) + Condition Error in `full_seq()`: ! `x` is not a regular sequence. Code - (expect_error(full_seq(c(0, 10, 20), 11, tol = 1.8))) - Output - + full_seq(c(0, 10, 20), 11, tol = 1.8) + Condition Error in `full_seq()`: ! `x` is not a regular sequence. diff --git a/tests/testthat/_snaps/spread.md b/tests/testthat/_snaps/spread.md index 593d5d7a0..8ad3c14d5 100644 --- a/tests/testthat/_snaps/spread.md +++ b/tests/testthat/_snaps/spread.md @@ -1,9 +1,8 @@ # duplicate values for one key is an error Code - (expect_error(spread(df, x, y))) - Output - + spread(df, x, y) + Condition Error in `spread()`: ! Each row of output must be identified by a unique combination of keys. i Keys are shared for 2 rows diff --git a/tests/testthat/test-drop-na.R b/tests/testthat/test-drop-na.R index c24e36778..201e7ab3a 100644 --- a/tests/testthat/test-drop-na.R +++ b/tests/testthat/test-drop-na.R @@ -37,12 +37,10 @@ test_that("groups are preserved", { test_that("errors are raised", { df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { drop_na(df, list()) drop_na(df, "z") - }, - cnd_class = TRUE - ) + }) }) test_that("single variable data.frame doesn't lose dimension", { @@ -78,11 +76,6 @@ test_that("works with df-cols", { }) test_that("works with rcrd cols", { - skip_if( - packageVersion("vctrs") <= "0.3.8", - "vec_detect_complete() treated rcrds differently" - ) - # if any rcrd field contains a missing value, it is incomplete col <- new_rcrd(list(x = c(1, 1, NA, NA), y = c(1, NA, 1, NA))) df <- tibble(col = col) diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R index 440f55c11..6f3bba6db 100644 --- a/tests/testthat/test-extract.R +++ b/tests/testthat/test-extract.R @@ -47,23 +47,19 @@ test_that("groups are preserved", { test_that("informative error message if wrong number of groups", { df <- tibble(x = "a") - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { extract(df, x, "y", ".") extract(df, x, c("y", "z"), ".") - }, - cnd_class = TRUE - ) + }) }) test_that("informative error if using stringr modifier functions (#693)", { df <- tibble(x = "a") regex <- structure("a", class = "pattern") - expect_snapshot( - extract(df, x, "x", regex = regex), - error = TRUE, - cnd_class = TRUE - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + extract(df, x, "x", regex = regex) + }) }) test_that("str_match_first handles edge cases", { diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index 9ad415a88..46f5f14ee 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -124,36 +124,30 @@ test_that("gather throws error for POSIXlt", { df <- data.frame(y = 1) df$x <- as.POSIXlt(Sys.time()) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { gather(df, key, val, -x) gather(df, key, val, -y) - }, - cnd_class = TRUE - ) + }) }) test_that("gather throws error for weird objects", { df <- data.frame(y = 1) df$x <- expression(x) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { gather(d, key, val, -x) gather(df, key, val, -y) - }, - cnd_class = TRUE - ) + }) e <- new.env(parent = emptyenv()) e$x <- 1 df <- data.frame(y = 1) df$x <- e - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { gather(df, key, val, -x) gather(df, key, val, -y) - }, - cnd_class = TRUE - ) + }) }) diff --git a/tests/testthat/test-hoist.R b/tests/testthat/test-hoist.R index 3f8cde23c..cab4b9514 100644 --- a/tests/testthat/test-hoist.R +++ b/tests/testthat/test-hoist.R @@ -103,13 +103,11 @@ test_that("can hoist out scalars", { test_that("input validation catches problems", { df <- tibble(x = list(list(1, b = "b")), y = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { df %>% hoist(y) df %>% hoist(x, 1) df %>% hoist(x, a = "a", a = "b") - }, - cnd_class = TRUE - ) + }) }) test_that("string pluckers are automatically named", { diff --git a/tests/testthat/test-pivot-long.R b/tests/testthat/test-pivot-long.R index eb0979161..bca0f1d5a 100644 --- a/tests/testthat/test-pivot-long.R +++ b/tests/testthat/test-pivot-long.R @@ -147,26 +147,22 @@ test_that("type error message use variable names", { test_that("when `values_ptypes` is provided, the type error uses variable names (#1364)", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { pivot_longer(df, x, values_ptypes = character()) - }, - cnd_class = TRUE - ) + }) }) test_that("when `names_ptypes` is provided, the type error uses `names_to` names (#1364)", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, { - pivot_longer( - df, - cols = x, - names_to = "name", - names_ptypes = double() - ) - }, - cnd_class = TRUE - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer( + df, + cols = x, + names_to = "name", + names_ptypes = double() + ) + }) }) test_that("error when overwriting existing column", { @@ -267,7 +263,7 @@ test_that("no names doesn't generate names (#1120)", { test_that("multiple names requires names_sep/names_pattern", { df <- tibble(x_y = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { build_longer_spec(df, x_y, names_to = c("a", "b")) build_longer_spec( @@ -277,9 +273,7 @@ test_that("multiple names requires names_sep/names_pattern", { names_sep = "x", names_pattern = "x" ) - }, - cnd_class = TRUE - ) + }) }) test_that("names_sep generates correct spec", { @@ -293,11 +287,9 @@ test_that("names_sep generates correct spec", { test_that("names_sep fails with single name", { df <- tibble(x_y = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { build_longer_spec(df, x_y, names_to = "x", names_sep = "_") - }, - cnd_class = TRUE - ) + }) }) test_that("names_pattern generates correct spec", { @@ -437,11 +429,9 @@ test_that("`values_transform` works with single functions (#1284)", { }) test_that("Error if the `col` can't be selected.", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { pivot_longer(iris, matches("foo")) - }, - cnd_class = TRUE - ) + }) }) test_that("named `cols` gives clear error (#1104)", { @@ -452,77 +442,73 @@ test_that("named `cols` gives clear error (#1104)", { test_that("`names_to` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { build_longer_spec(df, x, names_to = 1) build_longer_spec(df, x, names_to = c("x", "y")) build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") - }, - cnd_class = TRUE - ) + }) }) test_that("`names_ptypes` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { build_longer_spec(df, x, names_ptypes = 1) build_longer_spec(df, x, names_ptypes = list(integer())) - }, - cnd_class = TRUE - ) + }) }) test_that("`names_transform` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(build_longer_spec(df, x, names_transform = 1))) - (expect_error(build_longer_spec(df, x, names_transform = list(~.x)))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + build_longer_spec(df, x, names_transform = 1) + build_longer_spec(df, x, names_transform = list(~.x)) }) }) test_that("`values_ptypes` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(pivot_longer(df, x, values_ptypes = 1))) - (expect_error(pivot_longer(df, x, values_ptypes = list(integer())))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer(df, x, values_ptypes = 1) + pivot_longer(df, x, values_ptypes = list(integer())) }) }) test_that("`values_transform` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(pivot_longer(df, x, values_transform = 1))) - (expect_error(pivot_longer(df, x, values_transform = list(~.x)))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer(df, x, values_transform = 1) + pivot_longer(df, x, values_transform = list(~.x)) }) }) test_that("`cols_vary` is validated", { df <- tibble(x = 1) - expect_snapshot({ - (expect_error(pivot_longer(df, x, cols_vary = "fast"))) - (expect_error(pivot_longer(df, x, cols_vary = 1))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer(df, x, cols_vary = "fast") + pivot_longer(df, x, cols_vary = 1) }) }) test_that("`pivot_longer()` catches unused input passed through the dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) - expect_snapshot({ - (expect_error(pivot_longer(df, c(x, y), 1))) - (expect_error(pivot_longer(df, c(x, y), col_vary = "slowest"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer(df, c(x, y), 1) + pivot_longer(df, c(x, y), col_vary = "slowest") }) }) test_that("`build_longer_spec()` requires empty dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) - expect_snapshot({ - (expect_error(build_longer_spec(df, c(x, y), 1))) - (expect_error(build_longer_spec(df, c(x, y), name_to = "name"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + build_longer_spec(df, c(x, y), 1) + build_longer_spec(df, c(x, y), name_to = "name") }) }) @@ -530,8 +516,8 @@ test_that("`pivot_longer_spec()` requires empty dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) spec <- build_longer_spec(df, c(x, y)) - expect_snapshot({ - (expect_error(pivot_longer_spec(df, spec, 1))) - (expect_error(pivot_longer_spec(df, spec, col_vary = "slowest"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_longer_spec(df, spec, 1) + pivot_longer_spec(df, spec, col_vary = "slowest") }) }) diff --git a/tests/testthat/test-pivot-wide.R b/tests/testthat/test-pivot-wide.R index 224a11ffa..e80d42d7f 100644 --- a/tests/testthat/test-pivot-wide.R +++ b/tests/testthat/test-pivot-wide.R @@ -38,9 +38,9 @@ test_that("error when overwriting existing column", { val = c(1, 2) ) - expect_snapshot( - (expect_error(pivot_wider(df, names_from = key, values_from = val))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, names_from = key, values_from = val) + }) expect_snapshot( out <- pivot_wider(df, names_from = key, values_from = val, names_repair = "unique") @@ -115,33 +115,37 @@ test_that("works with data.table and empty key_vars", { test_that("`names_from` must be supplied if `name` isn't in `data` (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot((expect_error(pivot_wider(df, values_from = val)))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, values_from = val) + }) }) test_that("`values_from` must be supplied if `value` isn't in `data` (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot((expect_error(pivot_wider(df, names_from = key)))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, names_from = key) + }) }) test_that("`names_from` must identify at least 1 column (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot( - (expect_error(pivot_wider(df, names_from = starts_with("foo"), values_from = val))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, names_from = starts_with("foo"), values_from = val) + }) }) test_that("`values_from` must identify at least 1 column (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot( - (expect_error(pivot_wider(df, names_from = key, values_from = starts_with("foo")))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, names_from = key, values_from = starts_with("foo")) + }) }) test_that("`values_fn` emits an informative error when it doesn't result in unique values (#1238)", { df <- tibble(name = c("a", "a"), value = c(1, 2)) - expect_snapshot( - (expect_error(pivot_wider(df, values_fn = list(value = ~.x)))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, values_fn = list(value = ~.x)) + }) }) test_that("can pivot a manual spec with spec columns that don't identify any rows (#1250)", { @@ -217,9 +221,9 @@ test_that("expansion with `id_expand` and `names_expand` works with zero row dat test_that("`build_wider_spec()` requires empty dots", { df <- tibble(name = c("x", "y", "z"), value = 1:3) - expect_snapshot({ - (expect_error(build_wider_spec(df, 1))) - (expect_error(build_wider_spec(df, name_prefix = ""))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + build_wider_spec(df, 1) + build_wider_spec(df, name_prefix = "") }) }) @@ -227,9 +231,9 @@ test_that("`pivot_wider_spec()` requires empty dots", { df <- tibble(name = c("x", "y", "z"), value = 1:3) spec <- build_wider_spec(df) - expect_snapshot({ - (expect_error(pivot_wider_spec(df, spec, 1))) - (expect_error(pivot_wider_spec(df, spec, name_repair = "check_unique"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider_spec(df, spec, 1) + pivot_wider_spec(df, spec, name_repair = "check_unique") }) }) @@ -290,9 +294,9 @@ test_that("can vary `names_from` values slowest (#839)", { test_that("`names_vary` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot({ - (expect_error(build_wider_spec(df, names_vary = 1))) - (expect_error(build_wider_spec(df, names_vary = "x"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + build_wider_spec(df, names_vary = 1) + build_wider_spec(df, names_vary = "x") }) }) @@ -318,9 +322,9 @@ test_that("`names_expand` expands all levels of a factor `names_from` column (#7 test_that("`names_expand` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot({ - (expect_error(build_wider_spec(df, names_expand = 1))) - (expect_error(build_wider_spec(df, names_expand = "x"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + build_wider_spec(df, names_expand = 1) + build_wider_spec(df, names_expand = "x") }) }) @@ -358,18 +362,18 @@ test_that("`id_cols` can't select columns from `names_from` or `values_from` (#1 df <- tibble(name = c("x", "y"), value = c(1, 2)) # And gives a nice error message! - expect_snapshot({ - (expect_error(pivot_wider(df, id_cols = name, names_from = name, values_from = value))) - (expect_error(pivot_wider(df, id_cols = value, names_from = name, values_from = value))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, id_cols = name, names_from = name, values_from = value) + pivot_wider(df, id_cols = value, names_from = name, values_from = value) }) }) test_that("`id_cols` returns a tidyselect error if a column selection is OOB (#1318)", { df <- tibble(name = c("x", "y"), value = c(1, 2)) - expect_snapshot( - (expect_error(pivot_wider(df, id_cols = foo))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, id_cols = foo) + }) }) test_that("named `id_cols` gives clear error (#1104)", { @@ -470,9 +474,9 @@ test_that("`id_expand` with `values_fill` can't accidentally fill missings in `i test_that("`id_expand` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot({ - (expect_error(pivot_wider(df, id_expand = 1))) - (expect_error(pivot_wider(df, id_expand = "x"))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, id_expand = 1) + pivot_wider(df, id_expand = "x") }) }) @@ -526,13 +530,12 @@ test_that("duplicated key warning backticks non-syntactic names", { test_that("warning suppressed by supplying values_fn", { df <- tibble(a = c(1, 1, 2), key = c("x", "x", "x"), val = 1:3) - expect_warning( + expect_no_warning( pv <- pivot_wider(df, names_from = key, values_from = val, values_fn = list(val = list) - ), - NA + ) ) expect_equal(pv$a, c(1, 2)) expect_equal(as.list(pv$x), list(c(1L, 2L), 3L)) @@ -564,9 +567,9 @@ test_that("values_fn applied even when no-duplicates", { test_that("values_fn is validated", { df <- tibble(name = "x", value = 1L) - expect_snapshot( - (expect_error(pivot_wider(df, values_fn = 1))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, values_fn = 1) + }) }) # can fill missing cells -------------------------------------------------- @@ -687,9 +690,9 @@ test_that("`unused_fn` must result in single summary values", { value = c(1, 2, 3, 4) ) - expect_snapshot( - (expect_error(pivot_wider(df, id_cols = id, unused_fn = identity))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, id_cols = id, unused_fn = identity) + }) }) test_that("`unused_fn` works with expanded key from `id_expand`", { @@ -745,17 +748,17 @@ test_that("can't fill implicit missings in unused column with `values_fill`", { test_that("`values_fill` is validated", { df <- tibble(name = "a", value = 1) - expect_snapshot( - (expect_error(pivot_wider(df, values_fill = 1:2))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, values_fill = 1:2) + }) }) test_that("`unused_fn` is validated", { df <- tibble(id = 1, unused = 1, name = "a", value = 1) - expect_snapshot( - (expect_error(pivot_wider(df, id_cols = id, unused_fn = 1))) - ) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + pivot_wider(df, id_cols = id, unused_fn = 1) + }) }) # deprecated --------------------------------------------------------------- diff --git a/tests/testthat/test-pivot.R b/tests/testthat/test-pivot.R index 790afef75..f02bd72e1 100644 --- a/tests/testthat/test-pivot.R +++ b/tests/testthat/test-pivot.R @@ -1,21 +1,21 @@ test_that("basic sanity checks for spec occur", { - expect_snapshot({ - (expect_error(check_pivot_spec(1))) - (expect_error(check_pivot_spec(mtcars))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + check_pivot_spec(1) + check_pivot_spec(mtcars) }) }) test_that("`.name` column must be a character vector", { df <- tibble(.name = 1:2, .value = c("a", "b")) - expect_snapshot((expect_error(check_pivot_spec(df)))) + expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) }) test_that("`.value` column must be a character vector", { df <- tibble(.name = c("x", "y"), .value = 1:2) - expect_snapshot((expect_error(check_pivot_spec(df)))) + expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) }) test_that("`.name` column must be unique", { df <- tibble(.name = c("x", "x"), .value = c("a", "b")) - expect_snapshot((expect_error(check_pivot_spec(df)))) + expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) }) diff --git a/tests/testthat/test-replace_na.R b/tests/testthat/test-replace_na.R index 9254f41ac..152c64561 100644 --- a/tests/testthat/test-replace_na.R +++ b/tests/testthat/test-replace_na.R @@ -11,7 +11,7 @@ test_that("missing values are replaced", { }) test_that("can only be length 0", { - expect_snapshot((expect_error(replace_na(1, 1:10)))) + expect_snapshot(replace_na(1, 1:10), error = TRUE, cnd_class = TRUE) }) test_that("can replace missing rows in arrays", { @@ -34,7 +34,7 @@ test_that("can replace missing values in rcrds", { test_that("replacement must be castable to `data`", { x <- c(1L, NA) - expect_snapshot((expect_error(replace_na(x, 1.5)))) + expect_snapshot(replace_na(x, 1.5), error = TRUE, cnd_class = TRUE) }) test_that("empty atomic elements are not replaced in lists (#1168)", { @@ -95,7 +95,7 @@ test_that("df-col rows must be completely missing to be replaceable", { test_that("replacement must be castable to corresponding column", { df <- tibble(a = c(1L, NA)) - expect_snapshot((expect_error(replace_na(df, list(a = 1.5))))) + expect_snapshot(replace_na(df, list(a = 1.5)), error = TRUE, cnd_class = TRUE) }) test_that("validates its inputs", { diff --git a/tests/testthat/test-separate.R b/tests/testthat/test-separate.R index 660a7d2c3..7943fee26 100644 --- a/tests/testthat/test-separate.R +++ b/tests/testthat/test-separate.R @@ -121,7 +121,7 @@ test_that("informative error if using stringr modifier functions (#693)", { df <- tibble(x = "a") sep <- structure("a", class = "pattern") - expect_snapshot((expect_error(separate(df, x, "x", sep = sep)))) + expect_snapshot(separate(df, x, "x", sep = sep), error = TRUE, cnd_class = TRUE) }) # helpers ----------------------------------------------------------------- diff --git a/tests/testthat/test-seq.R b/tests/testthat/test-seq.R index 10e0f0123..591d7c54d 100644 --- a/tests/testthat/test-seq.R +++ b/tests/testthat/test-seq.R @@ -23,9 +23,9 @@ test_that("preserves attributes", { }) test_that("full_seq errors if sequence isn't regular", { - expect_snapshot({ - (expect_error(full_seq(c(1, 3, 4), 2))) - (expect_error(full_seq(c(0, 10, 20), 11, tol = 1.8))) + expect_snapshot(error = TRUE, cnd_class = TRUE, { + full_seq(c(1, 3, 4), 2) + full_seq(c(0, 10, 20), 11, tol = 1.8) }) }) diff --git a/tests/testthat/test-spread.R b/tests/testthat/test-spread.R index 503e65fae..266b27639 100644 --- a/tests/testthat/test-spread.R +++ b/tests/testthat/test-spread.R @@ -22,7 +22,7 @@ test_that("convert turns strings into integers", { test_that("duplicate values for one key is an error", { df <- tibble(x = factor(c("a", "b", "b")), y = c(1, 2, 2), z = c(1, 2, 2)) - expect_snapshot((expect_error(spread(df, x, y)))) + expect_snapshot(spread(df, x, y), error = TRUE, cnd_class = TRUE) }) test_that("factors are spread into columns (#35)", { diff --git a/tests/testthat/test-unnest-helper.R b/tests/testthat/test-unnest-helper.R index 38c9386b2..83b2d899f 100644 --- a/tests/testthat/test-unnest-helper.R +++ b/tests/testthat/test-unnest-helper.R @@ -1,36 +1,30 @@ # df_simplify ------------------------------------------------------------ test_that("`simplify` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { df_simplify(data.frame(), simplify = 1) df_simplify(data.frame(), simplify = NA) df_simplify(data.frame(), simplify = c(TRUE, FALSE)) df_simplify(data.frame(), simplify = list(1)) df_simplify(data.frame(), simplify = list(x = 1, x = 1)) - }, - cnd_class = TRUE - ) + }) }) test_that("`ptype` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { df_simplify(data.frame(), ptype = 1) df_simplify(data.frame(), ptype = list(1)) df_simplify(data.frame(), ptype = list(x = 1, x = 1)) - }, - cnd_class = TRUE - ) + }) }) test_that("`transform` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { df_simplify(data.frame(), transform = list(~.x)) df_simplify(data.frame(x = 1), transform = 1) df_simplify(data.frame(), transform = list(x = 1)) df_simplify(data.frame(), transform = list(x = 1, x = 1)) - }, - cnd_class = TRUE - ) + }) }) test_that("`simplify` can be a named list (#995)", { @@ -146,11 +140,9 @@ test_that("ptype is applied after transform", { c(2L, 3L, 4L) ) - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5) - }, - cnd_class = TRUE - ) + }) }) test_that("lists of lists aren't simplified", { diff --git a/tests/testthat/test-unnest-longer.R b/tests/testthat/test-unnest-longer.R index 0e72c7e12..b65d69a82 100644 --- a/tests/testthat/test-unnest-longer.R +++ b/tests/testthat/test-unnest-longer.R @@ -376,11 +376,9 @@ test_that("can't currently retain names when simplification isn't done and a pty }) test_that("can't mix `indices_to` with `indices_include = FALSE`", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE) - }, - cnd_class = TRUE - ) + }) }) test_that("unnest_longer() validates its inputs", { @@ -402,37 +400,29 @@ test_that("`values_to` and `indices_to` glue can't reach into surrounding env", }) test_that("`values_to` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { unnest_longer(mtcars, mpg, values_to = 1) unnest_longer(mtcars, mpg, values_to = c("x", "y")) - }, - cnd_class = TRUE - ) + }) }) test_that("`indices_to` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { unnest_longer(mtcars, mpg, indices_to = 1) unnest_longer(mtcars, mpg, indices_to = c("x", "y")) - }, - cnd_class = TRUE - ) + }) }) test_that("`indices_include` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { unnest_longer(mtcars, mpg, indices_include = 1) unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)) - }, - cnd_class = TRUE - ) + }) }) test_that("`keep_empty` is validated", { - expect_snapshot(error = TRUE, { + expect_snapshot(error = TRUE, cnd_class = TRUE, { unnest_longer(mtcars, mpg, keep_empty = 1) unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)) - }, - cnd_class = TRUE - ) + }) }) From 414ae42f5061091e48cb515179b610fb87862bc9 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 14:46:50 -0400 Subject: [PATCH 05/10] tidyselect 1.2.1 --- tests/testthat/_snaps/pivot-wide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/pivot-wide.md b/tests/testthat/_snaps/pivot-wide.md index bc7e7023c..68615af76 100644 --- a/tests/testthat/_snaps/pivot-wide.md +++ b/tests/testthat/_snaps/pivot-wide.md @@ -48,7 +48,7 @@ Code pivot_wider(df, names_from = starts_with("foo"), values_from = val) - Condition + Condition Error in `pivot_wider()`: ! Must select at least one item. @@ -56,7 +56,7 @@ Code pivot_wider(df, names_from = key, values_from = starts_with("foo")) - Condition + Condition Error in `pivot_wider()`: ! Must select at least one item. From bdd5a9fee27c77364e5ab5e29ef16930a4b86128 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 14:56:50 -0400 Subject: [PATCH 06/10] Add workaround for old R snapshot failure --- tests/testthat/test-gather.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index 46f5f14ee..aea3fc5a0 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -137,7 +137,10 @@ test_that("gather throws error for weird objects", { expect_snapshot(error = TRUE, cnd_class = TRUE, { gather(d, key, val, -x) gather(df, key, val, -y) - }) + }, + # Failing for old versions of R. (<4.3) + transform = function(x) gsub(" in `gather()`", "", x) + ) e <- new.env(parent = emptyenv()) e$x <- 1 From c2f994cb31914598606e87cd74f74c6018b5c521 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 23 Oct 2024 15:11:55 -0400 Subject: [PATCH 07/10] avoid snapshot for this test since it changes slightly across R versions --- tests/testthat/_snaps/gather.md | 7 +------ tests/testthat/test-gather.R | 10 ++++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/testthat/_snaps/gather.md b/tests/testthat/_snaps/gather.md index c14d5b4b4..0e394b281 100644 --- a/tests/testthat/_snaps/gather.md +++ b/tests/testthat/_snaps/gather.md @@ -13,14 +13,9 @@ # gather throws error for weird objects - Code - gather(d, key, val, -x) - Condition - Error: - ! object 'd' not found Code gather(df, key, val, -y) - Condition + Condition Error: ! All columns be atomic vectors or lists (not expression) diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index aea3fc5a0..dc5e8d36d 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -134,13 +134,11 @@ test_that("gather throws error for weird objects", { df <- data.frame(y = 1) df$x <- expression(x) - expect_snapshot(error = TRUE, cnd_class = TRUE, { - gather(d, key, val, -x) + # Can't use snapshot, it changes between versions of R + expect_error(gather(d, key, val, -x), "not found") + expect_snapshot(error = TRUE, { gather(df, key, val, -y) - }, - # Failing for old versions of R. (<4.3) - transform = function(x) gsub(" in `gather()`", "", x) - ) + }) e <- new.env(parent = emptyenv()) e$x <- 1 From b49c272d93b43b90564f8303af7624077973e0bc Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 24 Oct 2024 15:26:21 -0400 Subject: [PATCH 08/10] remove cnd_class = TRUE --- tests/testthat/_snaps/append.md | 2 +- tests/testthat/_snaps/chop.md | 4 +- tests/testthat/_snaps/drop-na.md | 4 +- tests/testthat/_snaps/expand.md | 6 +-- tests/testthat/_snaps/extract.md | 6 +-- tests/testthat/_snaps/gather.md | 8 ++-- tests/testthat/_snaps/hoist.md | 12 +++--- tests/testthat/_snaps/nest-legacy.md | 6 +-- tests/testthat/_snaps/pivot-long.md | 52 +++++++++++++------------- tests/testthat/_snaps/pivot-wide.md | 46 +++++++++++------------ tests/testthat/_snaps/pivot.md | 10 ++--- tests/testthat/_snaps/replace_na.md | 6 +-- tests/testthat/_snaps/separate.md | 2 +- tests/testthat/_snaps/seq.md | 4 +- tests/testthat/_snaps/spread.md | 2 +- tests/testthat/_snaps/unnest-helper.md | 26 ++++++------- tests/testthat/_snaps/unnest-longer.md | 20 +++++----- tests/testthat/_snaps/unnest-wider.md | 2 +- tests/testthat/_snaps/unnest.md | 8 ++-- tests/testthat/test-append.R | 2 +- tests/testthat/test-chop.R | 4 +- tests/testthat/test-drop-na.R | 2 +- tests/testthat/test-expand.R | 6 +-- tests/testthat/test-extract.R | 4 +- tests/testthat/test-gather.R | 6 +-- tests/testthat/test-hoist.R | 11 ++---- tests/testthat/test-nest-legacy.R | 6 +-- tests/testthat/test-pivot-long.R | 30 +++++++-------- tests/testthat/test-pivot-wide.R | 34 ++++++++--------- tests/testthat/test-pivot.R | 8 ++-- tests/testthat/test-replace_na.R | 6 +-- tests/testthat/test-separate.R | 2 +- tests/testthat/test-seq.R | 2 +- tests/testthat/test-spread.R | 2 +- tests/testthat/test-unnest-helper.R | 8 ++-- tests/testthat/test-unnest-longer.R | 12 +++--- tests/testthat/test-unnest-wider.R | 2 +- tests/testthat/test-unnest.R | 8 ++-- 38 files changed, 189 insertions(+), 192 deletions(-) diff --git a/tests/testthat/_snaps/append.md b/tests/testthat/_snaps/append.md index b88a93d03..553b27950 100644 --- a/tests/testthat/_snaps/append.md +++ b/tests/testthat/_snaps/append.md @@ -2,7 +2,7 @@ Code df_append(df1, df2, after = 1.5) - Condition + Condition Error in `df_append()`: ! `after` must be a whole number, not the number 1.5. i This is an internal error that was detected in the tidyr package. diff --git a/tests/testthat/_snaps/chop.md b/tests/testthat/_snaps/chop.md index e8fbffc28..45e5a5b6f 100644 --- a/tests/testthat/_snaps/chop.md +++ b/tests/testthat/_snaps/chop.md @@ -23,7 +23,7 @@ Code unchop(df, c(x, y)) - Condition + Condition Error in `unchop()`: ! In row 1, can't recycle input of size 2 to size 3. @@ -31,7 +31,7 @@ Code unchop(df, c(x, y)) - Condition + Condition Error in `unchop()`: ! In row 1, can't recycle input of size 0 to size 2. diff --git a/tests/testthat/_snaps/drop-na.md b/tests/testthat/_snaps/drop-na.md index 7baa49c93..56b86e9af 100644 --- a/tests/testthat/_snaps/drop-na.md +++ b/tests/testthat/_snaps/drop-na.md @@ -2,13 +2,13 @@ Code drop_na(df, list()) - Condition + Condition Error in `drop_na()`: ! Can't select columns with `list()`. x `list()` must be numeric or character, not an empty list. Code drop_na(df, "z") - Condition + Condition Error in `drop_na()`: ! Can't select columns that don't exist. x Column `z` doesn't exist. diff --git a/tests/testthat/_snaps/expand.md b/tests/testthat/_snaps/expand.md index e3ac2c4de..7af571108 100644 --- a/tests/testthat/_snaps/expand.md +++ b/tests/testthat/_snaps/expand.md @@ -2,7 +2,7 @@ Code crossing(x = 1:10, y = quote(a)) - Condition + Condition Error in `crossing()`: ! `..2` must be a vector, not a symbol. @@ -37,7 +37,7 @@ Code expand_grid(x = x, x = x) - Condition + Condition Error in `expand_grid()`: ! Names must be unique. x These names are duplicated: @@ -65,7 +65,7 @@ Code grid_dots(lm(1 ~ 1)) - Condition + Condition Error: ! `..1` must be a vector, not a object. diff --git a/tests/testthat/_snaps/extract.md b/tests/testthat/_snaps/extract.md index b582ea478..298910403 100644 --- a/tests/testthat/_snaps/extract.md +++ b/tests/testthat/_snaps/extract.md @@ -2,12 +2,12 @@ Code extract(df, x, "y", ".") - Condition + Condition Error in `extract()`: ! `regex` should define 1 groups; 0 found. Code extract(df, x, c("y", "z"), ".") - Condition + Condition Error in `extract()`: ! `regex` should define 2 groups; 0 found. @@ -15,7 +15,7 @@ Code extract(df, x, "x", regex = regex) - Condition + Condition Error in `extract()`: ! `regex` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/gather.md b/tests/testthat/_snaps/gather.md index 0e394b281..7ca9df233 100644 --- a/tests/testthat/_snaps/gather.md +++ b/tests/testthat/_snaps/gather.md @@ -2,12 +2,12 @@ Code gather(df, key, val, -x) - Condition + Condition Error: ! 'x' is a POSIXlt. Please convert to POSIXct. Code gather(df, key, val, -y) - Condition + Condition Error: ! Column 1 is a POSIXlt. Please convert to POSIXct. @@ -23,12 +23,12 @@ Code gather(df, key, val, -x) - Condition + Condition Error: ! All columns must be atomic vectors or lists. Problem with 'x' Code gather(df, key, val, -y) - Condition + Condition Error: ! All columns must be atomic vectors or lists. Problem with column 2. diff --git a/tests/testthat/_snaps/hoist.md b/tests/testthat/_snaps/hoist.md index 331c73d46..e6947dcdb 100644 --- a/tests/testthat/_snaps/hoist.md +++ b/tests/testthat/_snaps/hoist.md @@ -2,7 +2,7 @@ Code hoist(df, x, "b", .ptype = list(b = double())) - Condition + Condition Error in `hoist()`: ! Can't convert `..1` to . @@ -10,7 +10,7 @@ Code hoist(df, x, "b", .ptype = list(b = integer())) - Condition + Condition Error in `hoist()`: ! `..1` must be a vector, not a symbol. @@ -18,17 +18,17 @@ Code df %>% hoist(y) - Condition + Condition Error in `hoist()`: ! `.data[[.col]]` must be a list, not the number 1. Code df %>% hoist(x, 1) - Condition + Condition Error in `hoist()`: ! All elements of `...` must be named. Code df %>% hoist(x, a = "a", a = "b") - Condition + Condition Error in `hoist()`: ! The names of `...` must be unique. @@ -36,7 +36,7 @@ Code hoist(df, a, xx = 1) - Condition + Condition Error in `hoist()`: ! `.data[[.col]]` must be a list, not a object. diff --git a/tests/testthat/_snaps/nest-legacy.md b/tests/testthat/_snaps/nest-legacy.md index c3d896f1a..4f2dfa813 100644 --- a/tests/testthat/_snaps/nest-legacy.md +++ b/tests/testthat/_snaps/nest-legacy.md @@ -2,7 +2,7 @@ Code unnest_legacy(df) - Condition + Condition Error in `unnest_legacy()`: ! Each column must either be a list of vectors or a list of data frames. i Problems in: `x` @@ -11,7 +11,7 @@ Code unnest_legacy(df) - Condition + Condition Error in `unnest_legacy()`: ! All nested columns must have the same number of elements. @@ -19,7 +19,7 @@ Code unnest_legacy(df) - Condition + Condition Error in `unnest_legacy()`: ! All nested columns must have the same number of elements. diff --git a/tests/testthat/_snaps/pivot-long.md b/tests/testthat/_snaps/pivot-long.md index 4d08d978d..97715bbe6 100644 --- a/tests/testthat/_snaps/pivot-long.md +++ b/tests/testthat/_snaps/pivot-long.md @@ -2,7 +2,7 @@ Code pivot_longer(df, x, values_ptypes = character()) - Condition + Condition Error in `pivot_longer()`: ! Can't convert `x` to . @@ -10,7 +10,7 @@ Code pivot_longer(df, cols = x, names_to = "name", names_ptypes = double()) - Condition + Condition Error in `pivot_longer()`: ! Can't convert `name` to . @@ -18,7 +18,7 @@ Code pivot_longer(df, y, names_to = "x") - Condition + Condition Error in `pivot_longer()`: ! Names must be unique. x These names are duplicated: @@ -38,13 +38,13 @@ Code build_longer_spec(df, x_y, names_to = c("a", "b")) - Condition + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. Code build_longer_spec(df, x_y, names_to = c("a", "b"), names_sep = "x", names_pattern = "x") - Condition + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. @@ -52,7 +52,7 @@ Code build_longer_spec(df, x_y, names_to = "x", names_sep = "_") - Condition + Condition Error in `build_longer_spec()`: ! `names_sep` can't be used with a length 1 `names_to`. @@ -60,7 +60,7 @@ Code pivot_longer(iris, matches("foo")) - Condition + Condition Error in `pivot_longer()`: ! `cols` must select at least one column. @@ -76,18 +76,18 @@ Code build_longer_spec(df, x, names_to = 1) - Condition + Condition Error in `build_longer_spec()`: ! `names_to` must be a character vector or `NULL`, not the number 1. Code build_longer_spec(df, x, names_to = c("x", "y")) - Condition + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. Code build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") - Condition + Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. @@ -95,12 +95,12 @@ Code build_longer_spec(df, x, names_ptypes = 1) - Condition + Condition Error in `build_longer_spec()`: ! `names_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code build_longer_spec(df, x, names_ptypes = list(integer())) - Condition + Condition Error in `build_longer_spec()`: ! All elements of `names_ptypes` must be named. @@ -108,12 +108,12 @@ Code build_longer_spec(df, x, names_transform = 1) - Condition + Condition Error in `build_longer_spec()`: ! `names_transform` must be `NULL`, a function, or a named list of functions. Code build_longer_spec(df, x, names_transform = list(~.x)) - Condition + Condition Error in `build_longer_spec()`: ! All elements of `names_transform` must be named. @@ -121,12 +121,12 @@ Code pivot_longer(df, x, values_ptypes = 1) - Condition + Condition Error in `pivot_longer()`: ! `values_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. Code pivot_longer(df, x, values_ptypes = list(integer())) - Condition + Condition Error in `pivot_longer()`: ! All elements of `values_ptypes` must be named. @@ -134,12 +134,12 @@ Code pivot_longer(df, x, values_transform = 1) - Condition + Condition Error in `pivot_longer()`: ! `values_transform` must be `NULL`, a function, or a named list of functions. Code pivot_longer(df, x, values_transform = list(~.x)) - Condition + Condition Error in `pivot_longer()`: ! All elements of `values_transform` must be named. @@ -147,13 +147,13 @@ Code pivot_longer(df, x, cols_vary = "fast") - Condition + Condition Error in `pivot_longer()`: ! `cols_vary` must be one of "fastest" or "slowest", not "fast". i Did you mean "fastest"? Code pivot_longer(df, x, cols_vary = 1) - Condition + Condition Error in `pivot_longer()`: ! `cols_vary` must be a string or character vector. @@ -161,7 +161,7 @@ Code pivot_longer(df, c(x, y), 1) - Condition + Condition Error in `pivot_longer()`: ! Arguments in `...` must be used. x Problematic argument: @@ -169,7 +169,7 @@ i Did you misspell an argument name? Code pivot_longer(df, c(x, y), col_vary = "slowest") - Condition + Condition Error in `pivot_longer()`: ! Arguments in `...` must be used. x Problematic argument: @@ -180,7 +180,7 @@ Code build_longer_spec(df, c(x, y), 1) - Condition + Condition Error in `build_longer_spec()`: ! `...` must be empty. x Problematic argument: @@ -188,7 +188,7 @@ i Did you forget to name an argument? Code build_longer_spec(df, c(x, y), name_to = "name") - Condition + Condition Error in `build_longer_spec()`: ! `...` must be empty. x Problematic argument: @@ -198,7 +198,7 @@ Code pivot_longer_spec(df, spec, 1) - Condition + Condition Error in `pivot_longer_spec()`: ! `...` must be empty. x Problematic argument: @@ -206,7 +206,7 @@ i Did you forget to name an argument? Code pivot_longer_spec(df, spec, col_vary = "slowest") - Condition + Condition Error in `pivot_longer_spec()`: ! `...` must be empty. x Problematic argument: diff --git a/tests/testthat/_snaps/pivot-wide.md b/tests/testthat/_snaps/pivot-wide.md index 68615af76..284001ad2 100644 --- a/tests/testthat/_snaps/pivot-wide.md +++ b/tests/testthat/_snaps/pivot-wide.md @@ -10,7 +10,7 @@ Code pivot_wider(df, names_from = key, values_from = val) - Condition + Condition Error in `pivot_wider()`: ! Names must be unique. x These names are duplicated: @@ -30,7 +30,7 @@ Code pivot_wider(df, values_from = val) - Condition + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `name` doesn't exist. @@ -39,7 +39,7 @@ Code pivot_wider(df, names_from = key) - Condition + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `value` doesn't exist. @@ -48,7 +48,7 @@ Code pivot_wider(df, names_from = starts_with("foo"), values_from = val) - Condition + Condition Error in `pivot_wider()`: ! Must select at least one item. @@ -56,7 +56,7 @@ Code pivot_wider(df, names_from = key, values_from = starts_with("foo")) - Condition + Condition Error in `pivot_wider()`: ! Must select at least one item. @@ -64,7 +64,7 @@ Code pivot_wider(df, values_fn = list(value = ~.x)) - Condition + Condition Error in `pivot_wider()`: ! Applying `values_fn` to `value` must result in a single summary value per key. i Applying `values_fn` resulted in a vector of length 2. @@ -73,7 +73,7 @@ Code build_wider_spec(df, 1) - Condition + Condition Error in `build_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -81,7 +81,7 @@ i Did you forget to name an argument? Code build_wider_spec(df, name_prefix = "") - Condition + Condition Error in `build_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -91,7 +91,7 @@ Code pivot_wider_spec(df, spec, 1) - Condition + Condition Error in `pivot_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -99,7 +99,7 @@ i Did you forget to name an argument? Code pivot_wider_spec(df, spec, name_repair = "check_unique") - Condition + Condition Error in `pivot_wider_spec()`: ! `...` must be empty. x Problematic argument: @@ -109,12 +109,12 @@ Code build_wider_spec(df, names_vary = 1) - Condition + Condition Error in `build_wider_spec()`: ! `names_vary` must be a string or character vector. Code build_wider_spec(df, names_vary = "x") - Condition + Condition Error in `build_wider_spec()`: ! `names_vary` must be one of "fastest" or "slowest", not "x". @@ -122,12 +122,12 @@ Code build_wider_spec(df, names_expand = 1) - Condition + Condition Error in `build_wider_spec()`: ! `names_expand` must be `TRUE` or `FALSE`, not the number 1. Code build_wider_spec(df, names_expand = "x") - Condition + Condition Error in `build_wider_spec()`: ! `names_expand` must be `TRUE` or `FALSE`, not the string "x". @@ -135,13 +135,13 @@ Code pivot_wider(df, id_cols = name, names_from = name, values_from = value) - Condition + Condition Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `names_from`. i Column `name` has already been selected. Code pivot_wider(df, id_cols = value, names_from = name, values_from = value) - Condition + Condition Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `values_from`. i Column `value` has already been selected. @@ -150,7 +150,7 @@ Code pivot_wider(df, id_cols = foo) - Condition + Condition Error in `pivot_wider()`: ! Can't select columns that don't exist. x Column `foo` doesn't exist. @@ -167,12 +167,12 @@ Code pivot_wider(df, id_expand = 1) - Condition + Condition Error in `pivot_wider()`: ! `id_expand` must be `TRUE` or `FALSE`, not the number 1. Code pivot_wider(df, id_expand = "x") - Condition + Condition Error in `pivot_wider()`: ! `id_expand` must be `TRUE` or `FALSE`, not the string "x". @@ -246,7 +246,7 @@ Code pivot_wider(df, values_fn = 1) - Condition + Condition Error in `pivot_wider()`: ! `values_fn` must be `NULL`, a function, or a named list of functions. @@ -254,7 +254,7 @@ Code pivot_wider(df, id_cols = id, unused_fn = identity) - Condition + Condition Error in `pivot_wider()`: ! Applying `unused_fn` to `unused` must result in a single summary value per key. i Applying `unused_fn` resulted in a vector of length 2. @@ -263,7 +263,7 @@ Code pivot_wider(df, values_fill = 1:2) - Condition + Condition Error in `pivot_wider()`: ! `values_fill` must be `NULL`, a scalar, or a named list, not an integer vector. @@ -271,7 +271,7 @@ Code pivot_wider(df, id_cols = id, unused_fn = 1) - Condition + Condition Error in `pivot_wider()`: ! `unused_fn` must be `NULL`, a function, or a named list of functions. diff --git a/tests/testthat/_snaps/pivot.md b/tests/testthat/_snaps/pivot.md index 8b5552c7a..d861c3e3a 100644 --- a/tests/testthat/_snaps/pivot.md +++ b/tests/testthat/_snaps/pivot.md @@ -2,12 +2,12 @@ Code check_pivot_spec(1) - Condition + Condition Error: ! `spec` must be a data frame, not a number. Code check_pivot_spec(mtcars) - Condition + Condition Error: ! `spec` must have `.name` and `.value` columns. @@ -15,7 +15,7 @@ Code check_pivot_spec(df) - Condition + Condition Error: ! `spec$.name` must be a character vector, not an integer vector. @@ -23,7 +23,7 @@ Code check_pivot_spec(df) - Condition + Condition Error: ! `spec$.value` must be a character vector, not an integer vector. @@ -31,7 +31,7 @@ Code check_pivot_spec(df) - Condition + Condition Error: ! `spec$.name` must be unique. diff --git a/tests/testthat/_snaps/replace_na.md b/tests/testthat/_snaps/replace_na.md index 2cabd65cd..f25e4f42a 100644 --- a/tests/testthat/_snaps/replace_na.md +++ b/tests/testthat/_snaps/replace_na.md @@ -2,7 +2,7 @@ Code replace_na(1, 1:10) - Condition + Condition Error in `replace_na()`: ! Replacement for `data` must be length 1, not length 10. @@ -10,7 +10,7 @@ Code replace_na(x, 1.5) - Condition + Condition Error in `vec_assign()`: ! Can't convert from `replace` to `data` due to loss of precision. * Locations: 1 @@ -19,7 +19,7 @@ Code replace_na(df, list(a = 1.5)) - Condition + Condition Error in `vec_assign()`: ! Can't convert from `replace$a` to `data$a` due to loss of precision. * Locations: 1 diff --git a/tests/testthat/_snaps/separate.md b/tests/testthat/_snaps/separate.md index c0cc1a773..61e955e2a 100644 --- a/tests/testthat/_snaps/separate.md +++ b/tests/testthat/_snaps/separate.md @@ -74,7 +74,7 @@ Code separate(df, x, "x", sep = sep) - Condition + Condition Error in `separate()`: ! `sep` can't use modifiers from stringr. diff --git a/tests/testthat/_snaps/seq.md b/tests/testthat/_snaps/seq.md index 261aaa1e4..c9ff7a27c 100644 --- a/tests/testthat/_snaps/seq.md +++ b/tests/testthat/_snaps/seq.md @@ -2,12 +2,12 @@ Code full_seq(c(1, 3, 4), 2) - Condition + Condition Error in `full_seq()`: ! `x` is not a regular sequence. Code full_seq(c(0, 10, 20), 11, tol = 1.8) - Condition + Condition Error in `full_seq()`: ! `x` is not a regular sequence. diff --git a/tests/testthat/_snaps/spread.md b/tests/testthat/_snaps/spread.md index 8ad3c14d5..470ed45cd 100644 --- a/tests/testthat/_snaps/spread.md +++ b/tests/testthat/_snaps/spread.md @@ -2,7 +2,7 @@ Code spread(df, x, y) - Condition + Condition Error in `spread()`: ! Each row of output must be identified by a unique combination of keys. i Keys are shared for 2 rows diff --git a/tests/testthat/_snaps/unnest-helper.md b/tests/testthat/_snaps/unnest-helper.md index ed371b559..f100a45d7 100644 --- a/tests/testthat/_snaps/unnest-helper.md +++ b/tests/testthat/_snaps/unnest-helper.md @@ -2,27 +2,27 @@ Code df_simplify(data.frame(), simplify = 1) - Condition + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code df_simplify(data.frame(), simplify = NA) - Condition + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code df_simplify(data.frame(), simplify = c(TRUE, FALSE)) - Condition + Condition Error: ! `simplify` must be a list or a single `TRUE` or `FALSE`. Code df_simplify(data.frame(), simplify = list(1)) - Condition + Condition Error: ! All elements of `simplify` must be named. Code df_simplify(data.frame(), simplify = list(x = 1, x = 1)) - Condition + Condition Error: ! The names of `simplify` must be unique. @@ -30,17 +30,17 @@ Code df_simplify(data.frame(), ptype = 1) - Condition + Condition Error: ! `ptype` must be `NULL`, an empty ptype, or a named list of ptypes. Code df_simplify(data.frame(), ptype = list(1)) - Condition + Condition Error: ! All elements of `ptype` must be named. Code df_simplify(data.frame(), ptype = list(x = 1, x = 1)) - Condition + Condition Error: ! The names of `ptype` must be unique. @@ -48,22 +48,22 @@ Code df_simplify(data.frame(), transform = list(~.x)) - Condition + Condition Error: ! All elements of `transform` must be named. Code df_simplify(data.frame(x = 1), transform = 1) - Condition + Condition Error: ! `transform` must be `NULL`, a function, or a named list of functions. Code df_simplify(data.frame(), transform = list(x = 1)) - Condition + Condition Error: ! Can't convert `transform$x`, a double vector, to a function. Code df_simplify(data.frame(), transform = list(x = 1, x = 1)) - Condition + Condition Error: ! The names of `transform` must be unique. @@ -71,7 +71,7 @@ Code col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5) - Condition + Condition Error: ! Can't convert from `..1` to due to loss of precision. * Locations: 1 diff --git a/tests/testthat/_snaps/unnest-longer.md b/tests/testthat/_snaps/unnest-longer.md index 79ad6b77f..7b0aab833 100644 --- a/tests/testthat/_snaps/unnest-longer.md +++ b/tests/testthat/_snaps/unnest-longer.md @@ -2,7 +2,7 @@ Code unnest_longer(df, y) - Condition + Condition Error in `unnest_longer()`: ! List-column `y` must contain only vectors or `NULL`. @@ -18,7 +18,7 @@ Code unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE) - Condition + Condition Error in `unnest_longer()`: ! Can't use `indices_include = FALSE` when `indices_to` is supplied. @@ -54,12 +54,12 @@ Code unnest_longer(mtcars, mpg, values_to = 1) - Condition + Condition Error in `unnest_longer()`: ! `values_to` must be a valid name or `NULL`, not the number 1. Code unnest_longer(mtcars, mpg, values_to = c("x", "y")) - Condition + Condition Error in `unnest_longer()`: ! `values_to` must be a valid name or `NULL`, not a character vector. @@ -67,12 +67,12 @@ Code unnest_longer(mtcars, mpg, indices_to = 1) - Condition + Condition Error in `unnest_longer()`: ! `indices_to` must be a valid name or `NULL`, not the number 1. Code unnest_longer(mtcars, mpg, indices_to = c("x", "y")) - Condition + Condition Error in `unnest_longer()`: ! `indices_to` must be a valid name or `NULL`, not a character vector. @@ -80,12 +80,12 @@ Code unnest_longer(mtcars, mpg, indices_include = 1) - Condition + Condition Error in `unnest_longer()`: ! `indices_include` must be `TRUE`, `FALSE`, or `NULL`, not the number 1. Code unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)) - Condition + Condition Error in `unnest_longer()`: ! `indices_include` must be `TRUE`, `FALSE`, or `NULL`, not a logical vector. @@ -93,12 +93,12 @@ Code unnest_longer(mtcars, mpg, keep_empty = 1) - Condition + Condition Error in `unnest_longer()`: ! `keep_empty` must be `TRUE` or `FALSE`, not the number 1. Code unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)) - Condition + Condition Error in `unnest_longer()`: ! `keep_empty` must be `TRUE` or `FALSE`, not a logical vector. diff --git a/tests/testthat/_snaps/unnest-wider.md b/tests/testthat/_snaps/unnest-wider.md index e178d3cd8..546cbf3c3 100644 --- a/tests/testthat/_snaps/unnest-wider.md +++ b/tests/testthat/_snaps/unnest-wider.md @@ -2,7 +2,7 @@ Code unnest_wider(df, y) - Condition + Condition Error in `unnest_wider()`: i In column: `y`. i In row: 1. diff --git a/tests/testthat/_snaps/unnest.md b/tests/testthat/_snaps/unnest.md index 77c068267..cbeb77acc 100644 --- a/tests/testthat/_snaps/unnest.md +++ b/tests/testthat/_snaps/unnest.md @@ -2,7 +2,7 @@ Code unnest(df, y) - Condition + Condition Error in `list_sizes()`: ! `x[[1]]` must be a vector, not a function. @@ -10,7 +10,7 @@ Code unnest(df, c(x, y)) - Condition + Condition Error in `unnest()`: ! In row 1, can't recycle input of size 2 to size 3. @@ -18,7 +18,7 @@ Code unnest(df, c(x, y)) - Condition + Condition Error in `unnest()`: ! In row 1, can't recycle input of size 2 to size 3. @@ -26,7 +26,7 @@ Code unnest(df, x) - Condition + Condition Error in `unnest()`: ! Can't combine `x[[1]]` and `x[[2]]` . diff --git a/tests/testthat/test-append.R b/tests/testthat/test-append.R index 87ff70b8f..88b32c81c 100644 --- a/tests/testthat/test-append.R +++ b/tests/testthat/test-append.R @@ -31,7 +31,7 @@ test_that("after must be integer or character", { df1 <- data.frame(x = 1) df2 <- data.frame(x = 2) - expect_snapshot(df_append(df1, df2, after = 1.5), error = TRUE, cnd_class = TRUE) + expect_snapshot(df_append(df1, df2, after = 1.5), error = TRUE) }) test_that("always returns a bare data frame", { diff --git a/tests/testthat/test-chop.R b/tests/testthat/test-chop.R index ac9ec5411..96bb630a1 100644 --- a/tests/testthat/test-chop.R +++ b/tests/testthat/test-chop.R @@ -288,7 +288,7 @@ test_that("unchop works with record columns (treating them like vectors)", { test_that("incompatible sizes are caught", { df <- tibble(x = list(1:2), y = list(1:3)) - expect_snapshot(unchop(df, c(x, y)), error = TRUE, cnd_class = TRUE) + expect_snapshot(unchop(df, c(x, y)), error = TRUE) }) test_that("empty typed inputs are considered in common size, but NULLs aren't", { @@ -296,7 +296,7 @@ test_that("empty typed inputs are considered in common size, but NULLs aren't", expect_no_error(unchop(df, c(x, y))) df <- tibble(x = list(integer()), y = list(1:2)) - expect_snapshot(unchop(df, c(x, y)), error = TRUE, cnd_class = TRUE) + expect_snapshot(unchop(df, c(x, y)), error = TRUE) }) test_that("unchopping retains inner names from tibble elements", { diff --git a/tests/testthat/test-drop-na.R b/tests/testthat/test-drop-na.R index 201e7ab3a..8ca86a7b5 100644 --- a/tests/testthat/test-drop-na.R +++ b/tests/testthat/test-drop-na.R @@ -37,7 +37,7 @@ test_that("groups are preserved", { test_that("errors are raised", { df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { drop_na(df, list()) drop_na(df, "z") }) diff --git a/tests/testthat/test-expand.R b/tests/testthat/test-expand.R index 08b8ad99a..bf4caf70d 100644 --- a/tests/testthat/test-expand.R +++ b/tests/testthat/test-expand.R @@ -174,7 +174,7 @@ test_that("expand() retains `NA` data in factors (#1275)", { # ------------------------------------------------------------------------------ test_that("crossing checks for bad inputs", { - expect_snapshot(crossing(x = 1:10, y = quote(a)), error = TRUE, cnd_class = TRUE) + expect_snapshot(crossing(x = 1:10, y = quote(a)), error = TRUE) }) test_that("preserves NAs", { @@ -320,7 +320,7 @@ test_that("crossing() / nesting() retain `NA` data in factors (#1275)", { test_that("expand_grid() can control name_repair", { x <- 1:2 - expect_snapshot(expand_grid(x = x, x = x), error = TRUE, cnd_class = TRUE) + expect_snapshot(expand_grid(x = x, x = x), error = TRUE) expect_snapshot( out <- expand_grid(x = x, x = x, .name_repair = "unique") @@ -460,7 +460,7 @@ test_that("grid_dots() drops `NULL`s", { }) test_that("grid_dots() reject non-vector input", { - expect_snapshot(grid_dots(lm(1 ~ 1)), error = TRUE, cnd_class = TRUE) + expect_snapshot(grid_dots(lm(1 ~ 1)), error = TRUE) }) # ------------------------------------------------------------------------------ diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R index 6f3bba6db..09e8145b4 100644 --- a/tests/testthat/test-extract.R +++ b/tests/testthat/test-extract.R @@ -47,7 +47,7 @@ test_that("groups are preserved", { test_that("informative error message if wrong number of groups", { df <- tibble(x = "a") - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { extract(df, x, "y", ".") extract(df, x, c("y", "z"), ".") }) @@ -57,7 +57,7 @@ test_that("informative error if using stringr modifier functions (#693)", { df <- tibble(x = "a") regex <- structure("a", class = "pattern") - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { extract(df, x, "x", regex = regex) }) }) diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index dc5e8d36d..3d95936db 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -124,7 +124,7 @@ test_that("gather throws error for POSIXlt", { df <- data.frame(y = 1) df$x <- as.POSIXlt(Sys.time()) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { gather(df, key, val, -x) gather(df, key, val, -y) }) @@ -135,7 +135,7 @@ test_that("gather throws error for weird objects", { df$x <- expression(x) # Can't use snapshot, it changes between versions of R - expect_error(gather(d, key, val, -x), "not found") + expect_error(gather(d, key, val, -x)) expect_snapshot(error = TRUE, { gather(df, key, val, -y) }) @@ -145,7 +145,7 @@ test_that("gather throws error for weird objects", { df <- data.frame(y = 1) df$x <- e - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { gather(df, key, val, -x) gather(df, key, val, -y) }) diff --git a/tests/testthat/test-hoist.R b/tests/testthat/test-hoist.R index cab4b9514..34490872d 100644 --- a/tests/testthat/test-hoist.R +++ b/tests/testthat/test-hoist.R @@ -35,8 +35,7 @@ test_that("nested lists generate a cast error if they can't be cast to the ptype expect_snapshot( hoist(df, x, "b", .ptype = list(b = double())), - error = TRUE, - cnd_class = TRUE + error = TRUE ) }) @@ -45,8 +44,7 @@ test_that("non-vectors generate a cast error if a ptype is supplied", { expect_snapshot( hoist(df, x, "b", .ptype = list(b = integer())), - error = TRUE, - cnd_class = TRUE + error = TRUE ) }) @@ -103,7 +101,7 @@ test_that("can hoist out scalars", { test_that("input validation catches problems", { df <- tibble(x = list(list(1, b = "b")), y = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { df %>% hoist(y) df %>% hoist(x, 1) df %>% hoist(x, a = "a", a = "b") @@ -120,8 +118,7 @@ test_that("can't hoist() from a data frame column", { expect_snapshot( hoist(df, a, xx = 1), - error = TRUE, - cnd_class = TRUE + error = TRUE ) }) diff --git a/tests/testthat/test-nest-legacy.R b/tests/testthat/test-nest-legacy.R index 6fc9a2ba9..a865945eb 100644 --- a/tests/testthat/test-nest-legacy.R +++ b/tests/testthat/test-nest-legacy.R @@ -143,15 +143,15 @@ test_that("elements must all be of same type", { test_that("can't combine vectors and data frames", { df <- tibble(x = list(1, tibble(1))) - expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest_legacy(df), error = TRUE) }) test_that("multiple columns must be same length", { df <- tibble(x = list(1), y = list(1:2)) - expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest_legacy(df), error = TRUE) df <- tibble(x = list(1), y = list(tibble(x = 1:2))) - expect_snapshot(unnest_legacy(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest_legacy(df), error = TRUE) }) test_that("nested is split as a list (#84)", { diff --git a/tests/testthat/test-pivot-long.R b/tests/testthat/test-pivot-long.R index bca0f1d5a..b2d146cb5 100644 --- a/tests/testthat/test-pivot-long.R +++ b/tests/testthat/test-pivot-long.R @@ -147,7 +147,7 @@ test_that("type error message use variable names", { test_that("when `values_ptypes` is provided, the type error uses variable names (#1364)", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(df, x, values_ptypes = character()) }) }) @@ -155,7 +155,7 @@ test_that("when `values_ptypes` is provided, the type error uses variable names test_that("when `names_ptypes` is provided, the type error uses `names_to` names (#1364)", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer( df, cols = x, @@ -168,7 +168,7 @@ test_that("when `names_ptypes` is provided, the type error uses `names_to` names test_that("error when overwriting existing column", { df <- tibble(x = 1, y = 2) - expect_snapshot(pivot_longer(df, y, names_to = "x"), error = TRUE, cnd_class = TRUE) + expect_snapshot(pivot_longer(df, y, names_to = "x"), error = TRUE) expect_snapshot( out <- pivot_longer(df, y, names_to = "x", names_repair = "unique") @@ -263,7 +263,7 @@ test_that("no names doesn't generate names (#1120)", { test_that("multiple names requires names_sep/names_pattern", { df <- tibble(x_y = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, x_y, names_to = c("a", "b")) build_longer_spec( @@ -287,7 +287,7 @@ test_that("names_sep generates correct spec", { test_that("names_sep fails with single name", { df <- tibble(x_y = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, x_y, names_to = "x", names_sep = "_") }) }) @@ -429,7 +429,7 @@ test_that("`values_transform` works with single functions (#1284)", { }) test_that("Error if the `col` can't be selected.", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(iris, matches("foo")) }) }) @@ -442,7 +442,7 @@ test_that("named `cols` gives clear error (#1104)", { test_that("`names_to` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_to = 1) build_longer_spec(df, x, names_to = c("x", "y")) build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") @@ -452,7 +452,7 @@ test_that("`names_to` is validated", { test_that("`names_ptypes` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_ptypes = 1) build_longer_spec(df, x, names_ptypes = list(integer())) }) @@ -461,7 +461,7 @@ test_that("`names_ptypes` is validated", { test_that("`names_transform` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_transform = 1) build_longer_spec(df, x, names_transform = list(~.x)) }) @@ -470,7 +470,7 @@ test_that("`names_transform` is validated", { test_that("`values_ptypes` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(df, x, values_ptypes = 1) pivot_longer(df, x, values_ptypes = list(integer())) }) @@ -479,7 +479,7 @@ test_that("`values_ptypes` is validated", { test_that("`values_transform` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(df, x, values_transform = 1) pivot_longer(df, x, values_transform = list(~.x)) }) @@ -488,7 +488,7 @@ test_that("`values_transform` is validated", { test_that("`cols_vary` is validated", { df <- tibble(x = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(df, x, cols_vary = "fast") pivot_longer(df, x, cols_vary = 1) }) @@ -497,7 +497,7 @@ test_that("`cols_vary` is validated", { test_that("`pivot_longer()` catches unused input passed through the dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer(df, c(x, y), 1) pivot_longer(df, c(x, y), col_vary = "slowest") }) @@ -506,7 +506,7 @@ test_that("`pivot_longer()` catches unused input passed through the dots", { test_that("`build_longer_spec()` requires empty dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_longer_spec(df, c(x, y), 1) build_longer_spec(df, c(x, y), name_to = "name") }) @@ -516,7 +516,7 @@ test_that("`pivot_longer_spec()` requires empty dots", { df <- tibble(id = c("a", "b"), x = c(1, 2), y = c(3, 4)) spec <- build_longer_spec(df, c(x, y)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_longer_spec(df, spec, 1) pivot_longer_spec(df, spec, col_vary = "slowest") }) diff --git a/tests/testthat/test-pivot-wide.R b/tests/testthat/test-pivot-wide.R index e80d42d7f..2b17a5bc5 100644 --- a/tests/testthat/test-pivot-wide.R +++ b/tests/testthat/test-pivot-wide.R @@ -38,7 +38,7 @@ test_that("error when overwriting existing column", { val = c(1, 2) ) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, names_from = key, values_from = val) }) @@ -115,35 +115,35 @@ test_that("works with data.table and empty key_vars", { test_that("`names_from` must be supplied if `name` isn't in `data` (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, values_from = val) }) }) test_that("`values_from` must be supplied if `value` isn't in `data` (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, names_from = key) }) }) test_that("`names_from` must identify at least 1 column (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, names_from = starts_with("foo"), values_from = val) }) }) test_that("`values_from` must identify at least 1 column (#1240)", { df <- tibble(key = "x", val = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, names_from = key, values_from = starts_with("foo")) }) }) test_that("`values_fn` emits an informative error when it doesn't result in unique values (#1238)", { df <- tibble(name = c("a", "a"), value = c(1, 2)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, values_fn = list(value = ~.x)) }) }) @@ -221,7 +221,7 @@ test_that("expansion with `id_expand` and `names_expand` works with zero row dat test_that("`build_wider_spec()` requires empty dots", { df <- tibble(name = c("x", "y", "z"), value = 1:3) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_wider_spec(df, 1) build_wider_spec(df, name_prefix = "") }) @@ -231,7 +231,7 @@ test_that("`pivot_wider_spec()` requires empty dots", { df <- tibble(name = c("x", "y", "z"), value = 1:3) spec <- build_wider_spec(df) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider_spec(df, spec, 1) pivot_wider_spec(df, spec, name_repair = "check_unique") }) @@ -294,7 +294,7 @@ test_that("can vary `names_from` values slowest (#839)", { test_that("`names_vary` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_wider_spec(df, names_vary = 1) build_wider_spec(df, names_vary = "x") }) @@ -322,7 +322,7 @@ test_that("`names_expand` expands all levels of a factor `names_from` column (#7 test_that("`names_expand` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { build_wider_spec(df, names_expand = 1) build_wider_spec(df, names_expand = "x") }) @@ -362,7 +362,7 @@ test_that("`id_cols` can't select columns from `names_from` or `values_from` (#1 df <- tibble(name = c("x", "y"), value = c(1, 2)) # And gives a nice error message! - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = name, names_from = name, values_from = value) pivot_wider(df, id_cols = value, names_from = name, values_from = value) }) @@ -371,7 +371,7 @@ test_that("`id_cols` can't select columns from `names_from` or `values_from` (#1 test_that("`id_cols` returns a tidyselect error if a column selection is OOB (#1318)", { df <- tibble(name = c("x", "y"), value = c(1, 2)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = foo) }) }) @@ -474,7 +474,7 @@ test_that("`id_expand` with `values_fill` can't accidentally fill missings in `i test_that("`id_expand` is validated", { df <- tibble(name = c("a", "b"), value = c(1, 2)) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, id_expand = 1) pivot_wider(df, id_expand = "x") }) @@ -567,7 +567,7 @@ test_that("values_fn applied even when no-duplicates", { test_that("values_fn is validated", { df <- tibble(name = "x", value = 1L) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, values_fn = 1) }) }) @@ -690,7 +690,7 @@ test_that("`unused_fn` must result in single summary values", { value = c(1, 2, 3, 4) ) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = id, unused_fn = identity) }) }) @@ -748,7 +748,7 @@ test_that("can't fill implicit missings in unused column with `values_fill`", { test_that("`values_fill` is validated", { df <- tibble(name = "a", value = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, values_fill = 1:2) }) }) @@ -756,7 +756,7 @@ test_that("`values_fill` is validated", { test_that("`unused_fn` is validated", { df <- tibble(id = 1, unused = 1, name = "a", value = 1) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = id, unused_fn = 1) }) }) diff --git a/tests/testthat/test-pivot.R b/tests/testthat/test-pivot.R index f02bd72e1..b7528d9d3 100644 --- a/tests/testthat/test-pivot.R +++ b/tests/testthat/test-pivot.R @@ -1,5 +1,5 @@ test_that("basic sanity checks for spec occur", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { check_pivot_spec(1) check_pivot_spec(mtcars) }) @@ -7,15 +7,15 @@ test_that("basic sanity checks for spec occur", { test_that("`.name` column must be a character vector", { df <- tibble(.name = 1:2, .value = c("a", "b")) - expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(check_pivot_spec(df), error = TRUE) }) test_that("`.value` column must be a character vector", { df <- tibble(.name = c("x", "y"), .value = 1:2) - expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(check_pivot_spec(df), error = TRUE) }) test_that("`.name` column must be unique", { df <- tibble(.name = c("x", "x"), .value = c("a", "b")) - expect_snapshot(check_pivot_spec(df), error = TRUE, cnd_class = TRUE) + expect_snapshot(check_pivot_spec(df), error = TRUE) }) diff --git a/tests/testthat/test-replace_na.R b/tests/testthat/test-replace_na.R index 152c64561..58a80e939 100644 --- a/tests/testthat/test-replace_na.R +++ b/tests/testthat/test-replace_na.R @@ -11,7 +11,7 @@ test_that("missing values are replaced", { }) test_that("can only be length 0", { - expect_snapshot(replace_na(1, 1:10), error = TRUE, cnd_class = TRUE) + expect_snapshot(replace_na(1, 1:10), error = TRUE) }) test_that("can replace missing rows in arrays", { @@ -34,7 +34,7 @@ test_that("can replace missing values in rcrds", { test_that("replacement must be castable to `data`", { x <- c(1L, NA) - expect_snapshot(replace_na(x, 1.5), error = TRUE, cnd_class = TRUE) + expect_snapshot(replace_na(x, 1.5), error = TRUE) }) test_that("empty atomic elements are not replaced in lists (#1168)", { @@ -95,7 +95,7 @@ test_that("df-col rows must be completely missing to be replaceable", { test_that("replacement must be castable to corresponding column", { df <- tibble(a = c(1L, NA)) - expect_snapshot(replace_na(df, list(a = 1.5)), error = TRUE, cnd_class = TRUE) + expect_snapshot(replace_na(df, list(a = 1.5)), error = TRUE) }) test_that("validates its inputs", { diff --git a/tests/testthat/test-separate.R b/tests/testthat/test-separate.R index 7943fee26..6a36bb451 100644 --- a/tests/testthat/test-separate.R +++ b/tests/testthat/test-separate.R @@ -121,7 +121,7 @@ test_that("informative error if using stringr modifier functions (#693)", { df <- tibble(x = "a") sep <- structure("a", class = "pattern") - expect_snapshot(separate(df, x, "x", sep = sep), error = TRUE, cnd_class = TRUE) + expect_snapshot(separate(df, x, "x", sep = sep), error = TRUE) }) # helpers ----------------------------------------------------------------- diff --git a/tests/testthat/test-seq.R b/tests/testthat/test-seq.R index 591d7c54d..c58ed3616 100644 --- a/tests/testthat/test-seq.R +++ b/tests/testthat/test-seq.R @@ -23,7 +23,7 @@ test_that("preserves attributes", { }) test_that("full_seq errors if sequence isn't regular", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { full_seq(c(1, 3, 4), 2) full_seq(c(0, 10, 20), 11, tol = 1.8) }) diff --git a/tests/testthat/test-spread.R b/tests/testthat/test-spread.R index 266b27639..bfab97c5f 100644 --- a/tests/testthat/test-spread.R +++ b/tests/testthat/test-spread.R @@ -22,7 +22,7 @@ test_that("convert turns strings into integers", { test_that("duplicate values for one key is an error", { df <- tibble(x = factor(c("a", "b", "b")), y = c(1, 2, 2), z = c(1, 2, 2)) - expect_snapshot(spread(df, x, y), error = TRUE, cnd_class = TRUE) + expect_snapshot(spread(df, x, y), error = TRUE) }) test_that("factors are spread into columns (#35)", { diff --git a/tests/testthat/test-unnest-helper.R b/tests/testthat/test-unnest-helper.R index 83b2d899f..07b81df37 100644 --- a/tests/testthat/test-unnest-helper.R +++ b/tests/testthat/test-unnest-helper.R @@ -1,7 +1,7 @@ # df_simplify ------------------------------------------------------------ test_that("`simplify` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { df_simplify(data.frame(), simplify = 1) df_simplify(data.frame(), simplify = NA) df_simplify(data.frame(), simplify = c(TRUE, FALSE)) @@ -11,7 +11,7 @@ test_that("`simplify` is validated", { }) test_that("`ptype` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { df_simplify(data.frame(), ptype = 1) df_simplify(data.frame(), ptype = list(1)) df_simplify(data.frame(), ptype = list(x = 1, x = 1)) @@ -19,7 +19,7 @@ test_that("`ptype` is validated", { }) test_that("`transform` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { df_simplify(data.frame(), transform = list(~.x)) df_simplify(data.frame(x = 1), transform = 1) df_simplify(data.frame(), transform = list(x = 1)) @@ -140,7 +140,7 @@ test_that("ptype is applied after transform", { c(2L, 3L, 4L) ) - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { col_simplify(list(1, 2, 3), ptype = integer(), transform = ~ .x + 1.5) }) }) diff --git a/tests/testthat/test-unnest-longer.R b/tests/testthat/test-unnest-longer.R index b65d69a82..ae052dac1 100644 --- a/tests/testthat/test-unnest-longer.R +++ b/tests/testthat/test-unnest-longer.R @@ -46,7 +46,7 @@ test_that("can unnest dates", { test_that("unnest_longer - bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot(unnest_longer(df, y), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest_longer(df, y), error = TRUE) }) test_that("list_of columns can be unnested", { @@ -376,7 +376,7 @@ test_that("can't currently retain names when simplification isn't done and a pty }) test_that("can't mix `indices_to` with `indices_include = FALSE`", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, indices_to = "x", indices_include = FALSE) }) }) @@ -400,28 +400,28 @@ test_that("`values_to` and `indices_to` glue can't reach into surrounding env", }) test_that("`values_to` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, values_to = 1) unnest_longer(mtcars, mpg, values_to = c("x", "y")) }) }) test_that("`indices_to` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, indices_to = 1) unnest_longer(mtcars, mpg, indices_to = c("x", "y")) }) }) test_that("`indices_include` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, indices_include = 1) unnest_longer(mtcars, mpg, indices_include = c(TRUE, FALSE)) }) }) test_that("`keep_empty` is validated", { - expect_snapshot(error = TRUE, cnd_class = TRUE, { + expect_snapshot(error = TRUE, { unnest_longer(mtcars, mpg, keep_empty = 1) unnest_longer(mtcars, mpg, keep_empty = c(TRUE, FALSE)) }) diff --git a/tests/testthat/test-unnest-wider.R b/tests/testthat/test-unnest-wider.R index 6a8c51eaf..dd3726de0 100644 --- a/tests/testthat/test-unnest-wider.R +++ b/tests/testthat/test-unnest-wider.R @@ -53,7 +53,7 @@ test_that("treats data frames like lists where we have type info about each elem test_that("unnest_wider - bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot(unnest_wider(df, y), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest_wider(df, y), error = TRUE) }) test_that("list of 0-length vectors yields no new columns", { diff --git a/tests/testthat/test-unnest.R b/tests/testthat/test-unnest.R index 402854836..3ee670ef4 100644 --- a/tests/testthat/test-unnest.R +++ b/tests/testthat/test-unnest.R @@ -22,7 +22,7 @@ test_that("empty rows still affect output type", { test_that("bad inputs generate errors", { df <- tibble(x = 1, y = list(mean)) - expect_snapshot(unnest(df, y), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest(df, y), error = TRUE) }) test_that("unnesting combines augmented vectors", { @@ -96,10 +96,10 @@ test_that("vectors become columns", { test_that("multiple columns must be same length", { df <- tibble(x = list(1:2), y = list(1:3)) - expect_snapshot(unnest(df, c(x, y)), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest(df, c(x, y)), error = TRUE) df <- tibble(x = list(1:2), y = list(tibble(y = 1:3))) - expect_snapshot(unnest(df, c(x, y)), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest(df, c(x, y)), error = TRUE) }) test_that("can use non-syntactic names", { @@ -114,7 +114,7 @@ test_that("unpacks df-cols (#1112)", { test_that("unnesting column of mixed vector / data frame input is an error", { df <- tibble(x = list(1, tibble(a = 1))) - expect_snapshot(unnest(df, x), error = TRUE, cnd_class = TRUE) + expect_snapshot(unnest(df, x), error = TRUE) }) test_that("unnest() advises on outer / inner name duplication", { From 632045a92573cb9b67bc57cb8dc3cb75f7d25be9 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 24 Oct 2024 16:05:36 -0400 Subject: [PATCH 09/10] Separate snapshot tests for errors. --- tests/testthat/test-chop.R | 8 ++++++++ tests/testthat/test-drop-na.R | 2 ++ tests/testthat/test-extract.R | 8 ++++++++ tests/testthat/test-gather.R | 4 ++++ tests/testthat/test-hoist.R | 14 ++++++++++++++ tests/testthat/test-pack.R | 4 ++++ tests/testthat/test-pivot-long.R | 23 +++++++++++++++++++++- tests/testthat/test-pivot-wide.R | 12 ++++++++++++ tests/testthat/test-separate-longer.R | 6 ++++++ tests/testthat/test-separate-rows.R | 2 ++ tests/testthat/test-separate-wider.R | 28 +++++++++++++++++++++++++++ tests/testthat/test-separate.R | 8 ++++++++ tests/testthat/test-unnest-wider.R | 6 ++++++ 13 files changed, 124 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-chop.R b/tests/testthat/test-chop.R index 96bb630a1..95017c86d 100644 --- a/tests/testthat/test-chop.R +++ b/tests/testthat/test-chop.R @@ -24,6 +24,8 @@ test_that("chop() validates its input `cols` (#1205)", { df <- tibble(x = 1:2) expect_snapshot(error = TRUE, { chop(df$x) + }) + expect_snapshot(error = TRUE, { chop(df) }) }) @@ -357,8 +359,14 @@ test_that("unchop validates its inputs", { expect_snapshot(error = TRUE, { unchop(1:10) + }) + expect_snapshot(error = TRUE, { unchop(df) + }) + expect_snapshot(error = TRUE, { unchop(df, col, keep_empty = 1) + }) + expect_snapshot(error = TRUE, { unchop(df, col, ptype = 1) }) }) diff --git a/tests/testthat/test-drop-na.R b/tests/testthat/test-drop-na.R index 8ca86a7b5..d0c04cb8b 100644 --- a/tests/testthat/test-drop-na.R +++ b/tests/testthat/test-drop-na.R @@ -39,6 +39,8 @@ test_that("errors are raised", { df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b")) expect_snapshot(error = TRUE, { drop_na(df, list()) + }) + expect_snapshot(error = TRUE, { drop_na(df, "z") }) }) diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R index 09e8145b4..6618d7282 100644 --- a/tests/testthat/test-extract.R +++ b/tests/testthat/test-extract.R @@ -49,6 +49,8 @@ test_that("informative error message if wrong number of groups", { df <- tibble(x = "a") expect_snapshot(error = TRUE, { extract(df, x, "y", ".") + }) + expect_snapshot(error = TRUE, { extract(df, x, c("y", "z"), ".") }) }) @@ -90,8 +92,14 @@ test_that("validates its inputs", { expect_snapshot(error = TRUE, { df %>% extract() + }) + expect_snapshot(error = TRUE, { df %>% extract(x, regex = 1) + }) + expect_snapshot(error = TRUE, { df %>% extract(x, into = 1:3) + }) + expect_snapshot(error = TRUE, { df %>% extract(x, into = "x", convert = 1) }) }) diff --git a/tests/testthat/test-gather.R b/tests/testthat/test-gather.R index 3d95936db..158f433ab 100644 --- a/tests/testthat/test-gather.R +++ b/tests/testthat/test-gather.R @@ -126,6 +126,8 @@ test_that("gather throws error for POSIXlt", { expect_snapshot(error = TRUE, { gather(df, key, val, -x) + }) + expect_snapshot(error = TRUE, { gather(df, key, val, -y) }) }) @@ -147,6 +149,8 @@ test_that("gather throws error for weird objects", { expect_snapshot(error = TRUE, { gather(df, key, val, -x) + }) + expect_snapshot(error = TRUE, { gather(df, key, val, -y) }) }) diff --git a/tests/testthat/test-hoist.R b/tests/testthat/test-hoist.R index 34490872d..dc5fd3a22 100644 --- a/tests/testthat/test-hoist.R +++ b/tests/testthat/test-hoist.R @@ -103,7 +103,11 @@ test_that("input validation catches problems", { expect_snapshot(error = TRUE, { df %>% hoist(y) + }) + expect_snapshot(error = TRUE, { df %>% hoist(x, 1) + }) + expect_snapshot(error = TRUE, { df %>% hoist(x, a = "a", a = "b") }) }) @@ -166,10 +170,20 @@ test_that("hoist() validates its inputs (#1224)", { expect_snapshot(error = TRUE, { hoist(1) + }) + expect_snapshot(error = TRUE, { hoist(df) + }) + expect_snapshot(error = TRUE, { hoist(df, a, .remove = 1) + }) + expect_snapshot(error = TRUE, { hoist(df, a, .ptype = 1) + }) + expect_snapshot(error = TRUE, { hoist(df, a, .transform = 1) + }) + expect_snapshot(error = TRUE, { hoist(df, a, .simplify = 1) }) }) diff --git a/tests/testthat/test-pack.R b/tests/testthat/test-pack.R index fce41a553..35d3b5377 100644 --- a/tests/testthat/test-pack.R +++ b/tests/testthat/test-pack.R @@ -184,7 +184,11 @@ test_that("unpack() validates its inputs", { expect_snapshot(error = TRUE, { unpack(1) + }) + expect_snapshot(error = TRUE, { unpack(df) + }) + expect_snapshot(error = TRUE, { unpack(df, y, names_sep = 1) }) }) diff --git a/tests/testthat/test-pivot-long.R b/tests/testthat/test-pivot-long.R index b2d146cb5..04131344c 100644 --- a/tests/testthat/test-pivot-long.R +++ b/tests/testthat/test-pivot-long.R @@ -265,7 +265,8 @@ test_that("multiple names requires names_sep/names_pattern", { expect_snapshot(error = TRUE, { build_longer_spec(df, x_y, names_to = c("a", "b")) - + }) + expect_snapshot(error = TRUE, { build_longer_spec( df, x_y, @@ -444,7 +445,11 @@ test_that("`names_to` is validated", { expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_to = 1) + }) + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_to = c("x", "y")) + }) + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") }) }) @@ -454,6 +459,8 @@ test_that("`names_ptypes` is validated", { expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_ptypes = 1) + }) + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_ptypes = list(integer())) }) }) @@ -463,6 +470,8 @@ test_that("`names_transform` is validated", { expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_transform = 1) + }) + expect_snapshot(error = TRUE, { build_longer_spec(df, x, names_transform = list(~.x)) }) }) @@ -472,6 +481,8 @@ test_that("`values_ptypes` is validated", { expect_snapshot(error = TRUE, { pivot_longer(df, x, values_ptypes = 1) + }) + expect_snapshot(error = TRUE, { pivot_longer(df, x, values_ptypes = list(integer())) }) }) @@ -481,6 +492,8 @@ test_that("`values_transform` is validated", { expect_snapshot(error = TRUE, { pivot_longer(df, x, values_transform = 1) + }) + expect_snapshot(error = TRUE, { pivot_longer(df, x, values_transform = list(~.x)) }) }) @@ -490,6 +503,8 @@ test_that("`cols_vary` is validated", { expect_snapshot(error = TRUE, { pivot_longer(df, x, cols_vary = "fast") + }) + expect_snapshot(error = TRUE, { pivot_longer(df, x, cols_vary = 1) }) }) @@ -499,6 +514,8 @@ test_that("`pivot_longer()` catches unused input passed through the dots", { expect_snapshot(error = TRUE, { pivot_longer(df, c(x, y), 1) + }) + expect_snapshot(error = TRUE, { pivot_longer(df, c(x, y), col_vary = "slowest") }) }) @@ -508,6 +525,8 @@ test_that("`build_longer_spec()` requires empty dots", { expect_snapshot(error = TRUE, { build_longer_spec(df, c(x, y), 1) + }) + expect_snapshot(error = TRUE, { build_longer_spec(df, c(x, y), name_to = "name") }) }) @@ -518,6 +537,8 @@ test_that("`pivot_longer_spec()` requires empty dots", { expect_snapshot(error = TRUE, { pivot_longer_spec(df, spec, 1) + }) + expect_snapshot(error = TRUE, { pivot_longer_spec(df, spec, col_vary = "slowest") }) }) diff --git a/tests/testthat/test-pivot-wide.R b/tests/testthat/test-pivot-wide.R index 2b17a5bc5..1b8c8cd6c 100644 --- a/tests/testthat/test-pivot-wide.R +++ b/tests/testthat/test-pivot-wide.R @@ -223,6 +223,8 @@ test_that("`build_wider_spec()` requires empty dots", { expect_snapshot(error = TRUE, { build_wider_spec(df, 1) + }) + expect_snapshot(error = TRUE, { build_wider_spec(df, name_prefix = "") }) }) @@ -233,6 +235,8 @@ test_that("`pivot_wider_spec()` requires empty dots", { expect_snapshot(error = TRUE, { pivot_wider_spec(df, spec, 1) + }) + expect_snapshot(error = TRUE, { pivot_wider_spec(df, spec, name_repair = "check_unique") }) }) @@ -296,6 +300,8 @@ test_that("`names_vary` is validated", { expect_snapshot(error = TRUE, { build_wider_spec(df, names_vary = 1) + }) + expect_snapshot(error = TRUE, { build_wider_spec(df, names_vary = "x") }) }) @@ -324,6 +330,8 @@ test_that("`names_expand` is validated", { expect_snapshot(error = TRUE, { build_wider_spec(df, names_expand = 1) + }) + expect_snapshot(error = TRUE, { build_wider_spec(df, names_expand = "x") }) }) @@ -364,6 +372,8 @@ test_that("`id_cols` can't select columns from `names_from` or `values_from` (#1 # And gives a nice error message! expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = name, names_from = name, values_from = value) + }) + expect_snapshot(error = TRUE, { pivot_wider(df, id_cols = value, names_from = name, values_from = value) }) }) @@ -476,6 +486,8 @@ test_that("`id_expand` is validated", { expect_snapshot(error = TRUE, { pivot_wider(df, id_expand = 1) + }) + expect_snapshot(error = TRUE, { pivot_wider(df, id_expand = "x") }) }) diff --git a/tests/testthat/test-separate-longer.R b/tests/testthat/test-separate-longer.R index cd96b2377..0683b02c4 100644 --- a/tests/testthat/test-separate-longer.R +++ b/tests/testthat/test-separate-longer.R @@ -9,6 +9,8 @@ test_that("separate_longer_delim() validates its inputs", { df <- tibble(x = "x") expect_snapshot(error = TRUE, { df %>% separate_longer_delim() + }) + expect_snapshot(error = TRUE, { df %>% separate_longer_delim(x, sep = 1) }) }) @@ -41,7 +43,11 @@ test_that("separate_longer_position() validates its inputs", { df <- tibble(x = "x") expect_snapshot(error = TRUE, { df %>% separate_longer_position() + }) + expect_snapshot(error = TRUE, { df %>% separate_longer_position(y, width = 1) + }) + expect_snapshot(error = TRUE, { df %>% separate_longer_position(x, width = 1.5) }) }) diff --git a/tests/testthat/test-separate-rows.R b/tests/testthat/test-separate-rows.R index 8a096fbca..69123e0c8 100644 --- a/tests/testthat/test-separate-rows.R +++ b/tests/testthat/test-separate-rows.R @@ -75,6 +75,8 @@ test_that("it validates its inputs", { expect_snapshot(error = TRUE, { separate_rows(df, x, sep = 1) + }) + expect_snapshot(error = TRUE, { separate_rows(df, x, convert = 1) }) }) diff --git a/tests/testthat/test-separate-wider.R b/tests/testthat/test-separate-wider.R index 41cb20f9f..ed02a603e 100644 --- a/tests/testthat/test-separate-wider.R +++ b/tests/testthat/test-separate-wider.R @@ -79,12 +79,26 @@ test_that("separate_wider_delim() validates its inputs", { df <- tibble(x = "x") expect_snapshot(error = TRUE, { df %>% separate_wider_delim() + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, 1) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, "") + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, "-") + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, "-", names = 1) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, "-", names = c(x = "x")) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_delim(x, "-", names_sep = "_", too_many = "merge") }) }) @@ -153,9 +167,17 @@ test_that("separate_wider_position() validates its inputs", { df <- tibble(x = "x") expect_snapshot(error = TRUE, { df %>% separate_wider_position() + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_position(x) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_position(x, widths = 1.5) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_position(x, widths = 1L) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_position(x, widths = c(x = 0)) }) }) @@ -254,8 +276,14 @@ test_that("separate_wider_regex() validates its inputs", { df <- tibble(x = "x") expect_snapshot(error = TRUE, { df %>% separate_wider_regex() + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_regex(x) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_regex(y, patterns = c(x = "-")) + }) + expect_snapshot(error = TRUE, { df %>% separate_wider_regex(x, patterns = ".") }) }) diff --git a/tests/testthat/test-separate.R b/tests/testthat/test-separate.R index 6a36bb451..7be7076eb 100644 --- a/tests/testthat/test-separate.R +++ b/tests/testthat/test-separate.R @@ -110,9 +110,17 @@ test_that("validates inputs", { expect_snapshot(error = TRUE, { separate(df) + }) + expect_snapshot(error = TRUE, { separate(df, x, into = 1) + }) + expect_snapshot(error = TRUE, { separate(df, x, into = "x", sep = c("a", "b")) + }) + expect_snapshot(error = TRUE, { separate(df, x, into = "x", remove = 1) + }) + expect_snapshot(error = TRUE, { separate(df, x, into = "x", convert = 1) }) }) diff --git a/tests/testthat/test-unnest-wider.R b/tests/testthat/test-unnest-wider.R index dd3726de0..41fe6c4ec 100644 --- a/tests/testthat/test-unnest-wider.R +++ b/tests/testthat/test-unnest-wider.R @@ -309,8 +309,14 @@ test_that("unnest_wider() validates its inputs", { df <- tibble(x = list(a = 1:2, b = 3:4)) expect_snapshot(error = TRUE, { unnest_wider(1) + }) + expect_snapshot(error = TRUE, { unnest_wider(df) + }) + expect_snapshot(error = TRUE, { unnest_wider(df, x, names_sep = 1) + }) + expect_snapshot(error = TRUE, { unnest_wider(df, x, strict = 1) }) }) From 9e3c8a096307a722294428a9cec15deec3cf4396 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 24 Oct 2024 16:06:59 -0400 Subject: [PATCH 10/10] Update corresponding snapshots --- tests/testthat/_snaps/chop.md | 12 +++++++ tests/testthat/_snaps/drop-na.md | 3 ++ tests/testthat/_snaps/extract.md | 12 +++++++ tests/testthat/_snaps/gather.md | 6 ++++ tests/testthat/_snaps/hoist.md | 21 ++++++++++++ tests/testthat/_snaps/pack.md | 6 ++++ tests/testthat/_snaps/pivot-long.md | 33 +++++++++++++++++++ tests/testthat/_snaps/pivot-wide.md | 18 ++++++++++ tests/testthat/_snaps/separate-longer.md | 9 +++++ tests/testthat/_snaps/separate-rows.md | 3 ++ tests/testthat/_snaps/separate-wider.md | 42 ++++++++++++++++++++++++ tests/testthat/_snaps/separate.md | 12 +++++++ tests/testthat/_snaps/unnest-wider.md | 9 +++++ 13 files changed, 186 insertions(+) diff --git a/tests/testthat/_snaps/chop.md b/tests/testthat/_snaps/chop.md index 45e5a5b6f..9292d4532 100644 --- a/tests/testthat/_snaps/chop.md +++ b/tests/testthat/_snaps/chop.md @@ -5,6 +5,9 @@ Condition Error in `chop()`: ! `data` must be a data frame, not an integer vector. + +--- + Code chop(df) Condition @@ -50,16 +53,25 @@ Condition Error in `unchop()`: ! `data` must be a data frame, not an integer vector. + +--- + Code unchop(df) Condition Error in `unchop()`: ! `cols` is absent but must be supplied. + +--- + Code unchop(df, col, keep_empty = 1) Condition Error in `unchop()`: ! `keep_empty` must be `TRUE` or `FALSE`, not the number 1. + +--- + Code unchop(df, col, ptype = 1) Condition diff --git a/tests/testthat/_snaps/drop-na.md b/tests/testthat/_snaps/drop-na.md index 56b86e9af..72405450c 100644 --- a/tests/testthat/_snaps/drop-na.md +++ b/tests/testthat/_snaps/drop-na.md @@ -6,6 +6,9 @@ Error in `drop_na()`: ! Can't select columns with `list()`. x `list()` must be numeric or character, not an empty list. + +--- + Code drop_na(df, "z") Condition diff --git a/tests/testthat/_snaps/extract.md b/tests/testthat/_snaps/extract.md index 298910403..2c33e1746 100644 --- a/tests/testthat/_snaps/extract.md +++ b/tests/testthat/_snaps/extract.md @@ -5,6 +5,9 @@ Condition Error in `extract()`: ! `regex` should define 1 groups; 0 found. + +--- + Code extract(df, x, c("y", "z"), ".") Condition @@ -26,16 +29,25 @@ Condition Error in `extract()`: ! `col` is absent but must be supplied. + +--- + Code df %>% extract(x, regex = 1) Condition Error in `extract()`: ! `regex` must be a single string, not the number 1. + +--- + Code df %>% extract(x, into = 1:3) Condition Error in `extract()`: ! `into` must be a character vector, not an integer vector. + +--- + Code df %>% extract(x, into = "x", convert = 1) Condition diff --git a/tests/testthat/_snaps/gather.md b/tests/testthat/_snaps/gather.md index 7ca9df233..ff77d31be 100644 --- a/tests/testthat/_snaps/gather.md +++ b/tests/testthat/_snaps/gather.md @@ -5,6 +5,9 @@ Condition Error: ! 'x' is a POSIXlt. Please convert to POSIXct. + +--- + Code gather(df, key, val, -y) Condition @@ -26,6 +29,9 @@ Condition Error: ! All columns must be atomic vectors or lists. Problem with 'x' + +--- + Code gather(df, key, val, -y) Condition diff --git a/tests/testthat/_snaps/hoist.md b/tests/testthat/_snaps/hoist.md index e6947dcdb..942c69fb3 100644 --- a/tests/testthat/_snaps/hoist.md +++ b/tests/testthat/_snaps/hoist.md @@ -21,11 +21,17 @@ Condition Error in `hoist()`: ! `.data[[.col]]` must be a list, not the number 1. + +--- + Code df %>% hoist(x, 1) Condition Error in `hoist()`: ! All elements of `...` must be named. + +--- + Code df %>% hoist(x, a = "a", a = "b") Condition @@ -47,26 +53,41 @@ Condition Error in `hoist()`: ! `.data` must be a data frame, not a number. + +--- + Code hoist(df) Condition Error in `hoist()`: ! `.col` is absent but must be supplied. + +--- + Code hoist(df, a, .remove = 1) Condition Error in `hoist()`: ! `.remove` must be `TRUE` or `FALSE`, not the number 1. + +--- + Code hoist(df, a, .ptype = 1) Condition Error in `hoist()`: ! `.ptype` must be `NULL`, an empty ptype, or a named list of ptypes. + +--- + Code hoist(df, a, .transform = 1) Condition Error in `hoist()`: ! `.transform` must be `NULL`, a function, or a named list of functions. + +--- + Code hoist(df, a, .simplify = 1) Condition diff --git a/tests/testthat/_snaps/pack.md b/tests/testthat/_snaps/pack.md index 2f304f7fc..846a6e5cc 100644 --- a/tests/testthat/_snaps/pack.md +++ b/tests/testthat/_snaps/pack.md @@ -117,11 +117,17 @@ Condition Error in `unpack()`: ! `data` must be a data frame, not a number. + +--- + Code unpack(df) Condition Error in `unpack()`: ! `cols` is absent but must be supplied. + +--- + Code unpack(df, y, names_sep = 1) Condition diff --git a/tests/testthat/_snaps/pivot-long.md b/tests/testthat/_snaps/pivot-long.md index 97715bbe6..0f9081fbc 100644 --- a/tests/testthat/_snaps/pivot-long.md +++ b/tests/testthat/_snaps/pivot-long.md @@ -41,6 +41,9 @@ Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. + +--- + Code build_longer_spec(df, x_y, names_to = c("a", "b"), names_sep = "x", names_pattern = "x") @@ -79,11 +82,17 @@ Condition Error in `build_longer_spec()`: ! `names_to` must be a character vector or `NULL`, not the number 1. + +--- + Code build_longer_spec(df, x, names_to = c("x", "y")) Condition Error in `build_longer_spec()`: ! If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`. + +--- + Code build_longer_spec(df, x, names_to = c("x", "y"), names_sep = "_", names_pattern = "x") @@ -98,6 +107,9 @@ Condition Error in `build_longer_spec()`: ! `names_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. + +--- + Code build_longer_spec(df, x, names_ptypes = list(integer())) Condition @@ -111,6 +123,9 @@ Condition Error in `build_longer_spec()`: ! `names_transform` must be `NULL`, a function, or a named list of functions. + +--- + Code build_longer_spec(df, x, names_transform = list(~.x)) Condition @@ -124,6 +139,9 @@ Condition Error in `pivot_longer()`: ! `values_ptypes` must be `NULL`, an empty ptype, or a named list of ptypes. + +--- + Code pivot_longer(df, x, values_ptypes = list(integer())) Condition @@ -137,6 +155,9 @@ Condition Error in `pivot_longer()`: ! `values_transform` must be `NULL`, a function, or a named list of functions. + +--- + Code pivot_longer(df, x, values_transform = list(~.x)) Condition @@ -151,6 +172,9 @@ Error in `pivot_longer()`: ! `cols_vary` must be one of "fastest" or "slowest", not "fast". i Did you mean "fastest"? + +--- + Code pivot_longer(df, x, cols_vary = 1) Condition @@ -167,6 +191,9 @@ x Problematic argument: * ..1 = 1 i Did you misspell an argument name? + +--- + Code pivot_longer(df, c(x, y), col_vary = "slowest") Condition @@ -186,6 +213,9 @@ x Problematic argument: * ..1 = 1 i Did you forget to name an argument? + +--- + Code build_longer_spec(df, c(x, y), name_to = "name") Condition @@ -204,6 +234,9 @@ x Problematic argument: * ..1 = 1 i Did you forget to name an argument? + +--- + Code pivot_longer_spec(df, spec, col_vary = "slowest") Condition diff --git a/tests/testthat/_snaps/pivot-wide.md b/tests/testthat/_snaps/pivot-wide.md index 284001ad2..2658004c1 100644 --- a/tests/testthat/_snaps/pivot-wide.md +++ b/tests/testthat/_snaps/pivot-wide.md @@ -79,6 +79,9 @@ x Problematic argument: * ..1 = 1 i Did you forget to name an argument? + +--- + Code build_wider_spec(df, name_prefix = "") Condition @@ -97,6 +100,9 @@ x Problematic argument: * ..1 = 1 i Did you forget to name an argument? + +--- + Code pivot_wider_spec(df, spec, name_repair = "check_unique") Condition @@ -112,6 +118,9 @@ Condition Error in `build_wider_spec()`: ! `names_vary` must be a string or character vector. + +--- + Code build_wider_spec(df, names_vary = "x") Condition @@ -125,6 +134,9 @@ Condition Error in `build_wider_spec()`: ! `names_expand` must be `TRUE` or `FALSE`, not the number 1. + +--- + Code build_wider_spec(df, names_expand = "x") Condition @@ -139,6 +151,9 @@ Error in `pivot_wider()`: ! `id_cols` can't select a column already selected by `names_from`. i Column `name` has already been selected. + +--- + Code pivot_wider(df, id_cols = value, names_from = name, values_from = value) Condition @@ -170,6 +185,9 @@ Condition Error in `pivot_wider()`: ! `id_expand` must be `TRUE` or `FALSE`, not the number 1. + +--- + Code pivot_wider(df, id_expand = "x") Condition diff --git a/tests/testthat/_snaps/separate-longer.md b/tests/testthat/_snaps/separate-longer.md index 53911b282..63d6d13f3 100644 --- a/tests/testthat/_snaps/separate-longer.md +++ b/tests/testthat/_snaps/separate-longer.md @@ -5,6 +5,9 @@ Condition Error in `separate_longer_delim()`: ! `cols` is absent but must be supplied. + +--- + Code df %>% separate_longer_delim(x, sep = 1) Condition @@ -18,12 +21,18 @@ Condition Error in `separate_longer_position()`: ! `cols` is absent but must be supplied. + +--- + Code df %>% separate_longer_position(y, width = 1) Condition Error in `separate_longer_position()`: ! Can't select columns that don't exist. x Column `y` doesn't exist. + +--- + Code df %>% separate_longer_position(x, width = 1.5) Condition diff --git a/tests/testthat/_snaps/separate-rows.md b/tests/testthat/_snaps/separate-rows.md index 568a67680..6079566df 100644 --- a/tests/testthat/_snaps/separate-rows.md +++ b/tests/testthat/_snaps/separate-rows.md @@ -5,6 +5,9 @@ Condition Error in `separate_rows()`: ! `sep` must be a single string, not the number 1. + +--- + Code separate_rows(df, x, convert = 1) Condition diff --git a/tests/testthat/_snaps/separate-wider.md b/tests/testthat/_snaps/separate-wider.md index bf9dcf537..daad98e8f 100644 --- a/tests/testthat/_snaps/separate-wider.md +++ b/tests/testthat/_snaps/separate-wider.md @@ -28,36 +28,57 @@ Condition Error in `separate_wider_delim()`: ! `cols` is absent but must be supplied. + +--- + Code df %>% separate_wider_delim(x) Condition Error in `separate_wider_delim()`: ! `delim` must be a single string, not absent. + +--- + Code df %>% separate_wider_delim(x, 1) Condition Error in `separate_wider_delim()`: ! `delim` must be a single string, not the number 1. + +--- + Code df %>% separate_wider_delim(x, "") Condition Error in `separate_wider_delim()`: ! `delim` must be a single string, not the empty string "". + +--- + Code df %>% separate_wider_delim(x, "-") Condition Error in `separate_wider_delim()`: ! Must specify at least one of `names` or `names_sep`. + +--- + Code df %>% separate_wider_delim(x, "-", names = 1) Condition Error in `separate_wider_delim()`: ! `names` must be a character vector or `NULL`, not the number 1. + +--- + Code df %>% separate_wider_delim(x, "-", names = c(x = "x")) Condition Error in `separate_wider_delim()`: ! `names` must be an unnamed character vector. + +--- + Code df %>% separate_wider_delim(x, "-", names_sep = "_", too_many = "merge") Condition @@ -94,21 +115,33 @@ Condition Error in `separate_wider_position()`: ! `cols` is absent but must be supplied. + +--- + Code df %>% separate_wider_position(x) Condition Error in `separate_wider_position()`: ! `widths` is absent but must be supplied. + +--- + Code df %>% separate_wider_position(x, widths = 1.5) Condition Error in `separate_wider_position()`: ! `widths` must be a (partially) named integer vector. + +--- + Code df %>% separate_wider_position(x, widths = 1L) Condition Error in `separate_wider_position()`: ! `widths` must be a (partially) named integer vector. + +--- + Code df %>% separate_wider_position(x, widths = c(x = 0)) Condition @@ -175,17 +208,26 @@ Condition Error in `separate_wider_regex()`: ! `cols` is absent but must be supplied. + +--- + Code df %>% separate_wider_regex(x) Condition Error in `separate_wider_regex()`: ! `patterns` must be a character vector, not absent. + +--- + Code df %>% separate_wider_regex(y, patterns = c(x = "-")) Condition Error in `separate_wider_regex()`: ! Can't select columns that don't exist. x Column `y` doesn't exist. + +--- + Code df %>% separate_wider_regex(x, patterns = ".") Condition diff --git a/tests/testthat/_snaps/separate.md b/tests/testthat/_snaps/separate.md index 61e955e2a..7037b2ed5 100644 --- a/tests/testthat/_snaps/separate.md +++ b/tests/testthat/_snaps/separate.md @@ -49,21 +49,33 @@ Condition Error in `separate()`: ! `col` is absent but must be supplied. + +--- + Code separate(df, x, into = 1) Condition Error in `separate()`: ! `into` must be a character vector, not the number 1. + +--- + Code separate(df, x, into = "x", sep = c("a", "b")) Condition Error in `separate()`: ! `sep` must be a string or numeric vector, not a character vector + +--- + Code separate(df, x, into = "x", remove = 1) Condition Error in `separate()`: ! `remove` must be `TRUE` or `FALSE`, not the number 1. + +--- + Code separate(df, x, into = "x", convert = 1) Condition diff --git a/tests/testthat/_snaps/unnest-wider.md b/tests/testthat/_snaps/unnest-wider.md index 546cbf3c3..7e2f6f37a 100644 --- a/tests/testthat/_snaps/unnest-wider.md +++ b/tests/testthat/_snaps/unnest-wider.md @@ -108,16 +108,25 @@ Condition Error in `unnest_wider()`: ! `data` must be a data frame, not a number. + +--- + Code unnest_wider(df) Condition Error in `unnest_wider()`: ! `col` is absent but must be supplied. + +--- + Code unnest_wider(df, x, names_sep = 1) Condition Error in `unnest_wider()`: ! `names_sep` must be a single string or `NULL`, not the number 1. + +--- + Code unnest_wider(df, x, strict = 1) Condition