From 0f5f2dfa85caad1afeffc6820592c2f367e23387 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 20 Sep 2024 10:52:07 -0700 Subject: [PATCH] pass calls and test aborts in grids.R --- R/grids.R | 6 +++--- R/space_filling.R | 2 +- tests/testthat/_snaps/grids.md | 8 ++++++++ tests/testthat/test-grids.R | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/R/grids.R b/R/grids.R index e2f05619..9f9a28ea 100644 --- a/R/grids.R +++ b/R/grids.R @@ -157,7 +157,7 @@ make_regular_grid <- function(..., parameters <- dplyr::filter(parameters, !!filter_quo) } - new_param_grid(parameters) + new_param_grid(parameters, call = call) } # ------------------------------------------------------------------------------ @@ -246,12 +246,12 @@ make_random_grid <- function(..., parameters <- dplyr::filter(parameters, !!filter_quo) } - new_param_grid(parameters) + new_param_grid(parameters, call = call) } # ------------------------------------------------------------------------------ -new_param_grid <- function(x = new_data_frame()) { +new_param_grid <- function(x = new_data_frame(), call = caller_env()) { if (!is.data.frame(x)) { cli::cli_abort( "{.arg x} must be a data frame to construct a new grid from." diff --git a/R/space_filling.R b/R/space_filling.R index 79c46e0a..85f2105e 100644 --- a/R/space_filling.R +++ b/R/space_filling.R @@ -235,7 +235,7 @@ make_sfd <- function(..., ) } - new_param_grid(grid) + new_param_grid(grid, call = call) } base_recycle <- function(x, size) { diff --git a/tests/testthat/_snaps/grids.md b/tests/testthat/_snaps/grids.md index 8ea2410e..5ee72bf9 100644 --- a/tests/testthat/_snaps/grids.md +++ b/tests/testthat/_snaps/grids.md @@ -16,6 +16,14 @@ Error in `parameters()`: ! The objects should all be objects. +--- + + Code + grid_regular(mixture(), trees(), levels = c(2, trees = 4)) + Condition + Error in `grid_regular()`: + ! Elements of `levels` should either be all named or unnamed, not mixed. + # wrong argument name Code diff --git a/tests/testthat/test-grids.R b/tests/testthat/test-grids.R index 31b232bd..63a332d1 100644 --- a/tests/testthat/test-grids.R +++ b/tests/testthat/test-grids.R @@ -44,6 +44,11 @@ test_that("regular grid", { grid_regular(list(mixture(), trees()), levels = 3), grid_regular(mixture(), trees(), levels = 3) ) + + expect_snapshot( + error = TRUE, + grid_regular(mixture(), trees(), levels = c(2, trees = 4)) + ) }) test_that("random grid", {