Skip to content

Commit

Permalink
Add tests of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Oct 21, 2024
1 parent 1089f4d commit ec67a5c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
6 changes: 0 additions & 6 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ orderly_query <- function(expr, name = NULL, scope = NULL, subquery = NULL) {
}


dots_is_literal_id <- function(...) {
...length() == 1 && is.null(...names()) && is.character(..1) &&
all(grepl(re_id, ..1))
}


expr_is_literal_id <- function(expr, ...) {
all(vlapply(list(...), is.null)) &&
is.character(expr) &&
Expand Down
5 changes: 3 additions & 2 deletions R/query_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ orderly_search_options <- function(location = NULL,
"that previously accepted 'options'")),
.frequency = "regularly",
.frequency_id = "orderly_search_options")
build_search_options(location, allow_remote, pull_metadata)
}


Expand All @@ -101,8 +102,8 @@ compatibility_fix_options <- function(options, name,
"'allow_remote' and 'pull_metadata') directly to '{name}'"),
"!" = paste("If you have {.strong also} passed these options in",
"to your function I am about to silently overwrite them")),
.frequency = "frequently",
.frequency_id = paste0("use_options:", name),
.frequency = "regularly",
.frequency_id = paste0("orderly_use_options:", name),
call = env)
list2env(options, env)
}
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-query-search.R
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,41 @@ test_that("&& takes precedence over ||", {
root = root),
c(x1, y1))
})


test_that("Warn on use of search options", {
rlang::reset_warning_verbosity("orderly_search_options")
expect_warning(
orderly_search_options(),
"Use of 'orderly_search_options' is deprecated")
expect_no_warning(
orderly_search_options())
})


test_that("Warn, but honour, on use of search options to search", {
rlang::reset_warning_verbosity("orderly_use_options:orderly_search")
root <- list()
root$a <- create_temporary_root(use_file_store = TRUE)
root$b <- create_temporary_root(use_file_store = TRUE)
orderly_location_add_path("b", path = root$b$path, root = root$a)

ids <- vcapply(1:3, function(i) {
create_random_packet(root$b, "data", list(p = i))
})
orderly_location_pull_metadata(root = root$a)

expect_equal(orderly_search(NULL, root = root$a),
character())
options <- suppressWarnings(orderly_search_options(location = "b"))

expect_warning(
res <- orderly_search(NULL, root = root$a, options = options),
"Use of 'options' in 'orderly_search()' is deprecated",
fixed = TRUE)
expect_equal(res, ids)

expect_no_warning(
res2 <- orderly_search(NULL, root = root$a, options = options))
expect_equal(res2, res)
})

0 comments on commit ec67a5c

Please sign in to comment.