Skip to content

Commit

Permalink
Expand testing
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Jul 20, 2023
1 parent 0f81a9b commit a3145f6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
4 changes: 3 additions & 1 deletion R/cleanup.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ orderly_cleanup_status <- function(name = NULL, root = NULL, locate = TRUE) {
p <- get_active_packet()
is_active <- !is.null(p)
if (is_active) {
stop("Don't call this with an acive packet...")
cli::cli_abort(
"Don't call 'orderly2::orderly_cleanup_status()' from a running packet",
i = "The orderly_cleanup* functions are for interactive use only")
}

if (is.null(name)) {
Expand Down
7 changes: 1 addition & 6 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@ copy_global <- function(path_root, path_dest, config, files) {


static_orderly_global_resource <- function(args) {
files <- lapply(args, static_character_vector, TRUE)
if (length(files) == 0 || !all(lengths(files) == 1)) {
NULL
} else {
list_to_character(files)
}
unlist(lapply(args, static_character_vector, TRUE), FALSE, TRUE)
}


Expand Down
3 changes: 0 additions & 3 deletions R/root.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ orderly_init <- function(path, ...) {
## * database - lower priority, as only VIMC and everything else must work first
## * minimum_orderly_version - the required version
orderly_root <- function(root, locate) {
if (inherits(root, "orderly_root")) {
return(root)
}
root <- outpack_root_open(root, locate)
## NOTE: it's can't be changed yet, but core.path_archive cannot be
## "draft" for this to work well.
Expand Down
10 changes: 5 additions & 5 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ check_symbol_from_str <- function(str, name) {
}



## Currently supported in gert 1.9000 (which is the 2.0
## prerelease). Rather than depend on that version directly, requiring
## people to install it from source or r-universe, just sniff for the
## function we need, for now:
gert_git_ignore_path_is_ignored <- function() {
not_supported <- function(path, repo) {
rep_len(NA, length(path))
}
tryCatch(getExportedValue("gert", "git_ignore_path_is_ignored"),
error = function(e) not_supported)
error = function(e) NULL)
}


Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-interactive-cleanup.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,15 @@ test_that("can clean up directories", {
dir(path_src, recursive = TRUE, include.dirs = TRUE),
c("data", "data/a.csv", "data/b.csv", "orderly.R"))
})


test_that("Don't call cleanup on an active packet", {
path <- test_prepare_orderly_example("data")
path_src <- file.path(path, "src", "data")
append_lines(file.path(path_src, "orderly.R"),
"orderly2::orderly_cleanup_status()")
expect_error(
orderly_run("data", root = path),
"Don't call 'orderly2::orderly_cleanup_status()' from a running packet",
fixed = TRUE)
})
8 changes: 8 additions & 0 deletions tests/testthat/test-util.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,11 @@ test_that("can check two vars are of same type", {
expect_false(is_same_type(1, "TRUE"))
expect_false(is_same_type(TRUE, "TRUE"))
})


test_that("fall back if gert does not support ignored files", {
mock_ns <- mockery::mock(identity, stop("not found"))
mockery::stub(gert_git_ignore_path_is_ignored, "getExportedValue", mock_ns)
expect_equal(gert_git_ignore_path_is_ignored(), identity)
expect_null(gert_git_ignore_path_is_ignored())
})

0 comments on commit a3145f6

Please sign in to comment.