Skip to content

Commit

Permalink
Migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Dec 13, 2024
1 parent e8fb7ef commit 8272863
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions R/utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ file_info_runtime <- function(x) {
if_any(
!is.null(file_info) &&
!is.null(file_info_exist) &&
(length(x) > 0L) &&
all(counter_exist_names(file_info_exist, x)),
.subset2(file_info, x), # nolint
file_info(x)
Expand Down
22 changes: 17 additions & 5 deletions tests/testthat/test-utils_callr.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,22 @@ tar_test("file path caches are correct", {
)
info <- tar_read(file_info)
expect_true(is.list(info))
expect_true(all(c("size", "mtime_numeric") %in% names(info)))
names <- sort(path_objects(path_store_default(), c("x", "y")))
for (field in c("size", "mtime_numeric")) {
expect_equal(sort(names(info[[field]])), names)
expect_false(anyNA(info[[field]]))
expect_equal(
sort(names(info)),
sort(file.path(path_objects_dir(path_store_default()), c("x", "y")))
)
for (item in info) {
expect_equal(
sort(names(item)),
sort(c("size", "mtime_numeric", "trust_timestamps"))
)
for (field in c("size", "mtime_numeric")) {
expect_false(anyNA(item[[field]]))
expect_true(is.numeric(item[[field]]))
expect_equal(length(item[[field]]), 1L)
}
expect_true(
isTRUE(item$trust_timestamps) || isFALSE(item$trust_timestamps)
)
}
})
16 changes: 0 additions & 16 deletions tests/testthat/test-utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,6 @@ tar_test("file_info_runtime() with no files registered", {
expect_true(is.data.frame(out))
})

tar_test("file_info_runtime_select()", {
files <- unlist(replicate(6, tempfile()))
file.create(files)
on.exit(unlink(files))
info <- list(
mtime_numeric = seq_along(files),
size = file.size(files) + seq_along(files)
)
names(info$mtime_numeric) <- files
names(info$size) <- files
index <- c(2L, 3L, 5L)
out <- file_info_runtime_select(info, files[index])
expect_equal(out$mtime_numeric, info$mtime_numeric[index])
expect_equal(out$size, info$size[index])
})

tar_test("file_move() on files", {
file.create("x")
dir.create("z")
Expand Down

0 comments on commit 8272863

Please sign in to comment.