Skip to content

Commit

Permalink
add options for strict testing (#1102)
Browse files Browse the repository at this point in the history
- part of
insightsengineering/coredev-tasks#478
- please read this for more info about the implementation:
insightsengineering/coredev-tasks#478 (comment)
- fixes discovered partial argument matches

---------

Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
pawelru and dependabot-preview[bot] committed Feb 26, 2024
1 parent 5cacedc commit 9d02a55
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
10 changes: 7 additions & 3 deletions R/validate_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@
#' # set up input validation
#' iv <- InputValidator$new()
#' iv$add_rule("letter", sv_in_set(LETTERS, "choose a capital letter"))
#' iv$add_rule("number", ~ if (as.integer(.) %% 2L == 1L) "choose an even number")
#' iv$add_rule("number", function(x) {
#' if (as.integer(x) %% 2L == 1L) "choose an even number"
#' })
#' iv$enable()
#' # more input validation
#' iv_par <- InputValidator$new()
#' iv_par$add_rule("color", sv_required(message = "choose a color"))
#' iv_par$add_rule("color", ~ if (length(.) > 1L) "choose only one color")
#' iv_par$add_rule("color", function(x) {
#' if (length(x) > 1L) "choose only one color"
#' })
#' iv_par$add_rule(
#' "size",
#' sv_between(
Expand All @@ -87,7 +91,7 @@
#' ))
#' )
#'
#' plot(eruptions ~ waiting, faithful,
#' plot(faithful$eruptions ~ faithful$waiting,
#' las = 1, pch = 16,
#' col = input[["color"]], cex = input[["size"]]
#' )
Expand Down
10 changes: 7 additions & 3 deletions man/validate_inputs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/setup-options.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `opts_partial_match_old` is left for exclusions due to partial matching in dependent packages (i.e. not fixable here)
# it might happen that it is not used right now, but it is left for possible future use
# use with: `withr::with_options(opts_partial_match_old, { ... })` inside the test
opts_partial_match_old <- list(
warnPartialMatchDollar = getOption("warnPartialMatchDollar"),
warnPartialMatchArgs = getOption("warnPartialMatchArgs"),
warnPartialMatchAttr = getOption("warnPartialMatchAttr")
)
opts_partial_match_new <- list(
warnPartialMatchDollar = TRUE,
warnPartialMatchArgs = TRUE,
warnPartialMatchAttr = TRUE
)

if (isFALSE(getFromNamespace("on_cran", "testthat")()) && requireNamespace("withr", quietly = TRUE)) {
withr::local_options(
opts_partial_match_new,
.local_envir = testthat::teardown_env()
)
}

0 comments on commit 9d02a55

Please sign in to comment.