tests/testthat/test-ask.R

# Globals -----------------------------------------------------------------

path <- test_path() %>% fs::path("data") %>%
    fs::dir_create(recurse = TRUE)

# Create directory --------------------------------------------------------

test_that("Ask: create directory: exists = false", {
    if (path %>% fs::dir_exists()) {
        path %>% fs::dir_delete()
    }

    result <- ask_dir_create(dir = path %>% fs::path("a/b/c"))
    expect_true(path %>% fs::dir_exists())
})

test_that("Ask: create directory: exists = false (pipe)", {
    if (path %>% fs::dir_exists()) {
        path %>% fs::dir_delete()
    }

    result <- path %>% fs::path("a/b/c") %>% ask_dir_create()
    expect_true(path %>% fs::dir_exists())
})

test_that("Ask: create directory: exists = true", {
    if (!(path %>% fs::dir_exists())) {
        path %>% fs::dir_create(recurse = TRUE)
    }

    result <- ask_dir_create(dir = path %>% fs::path("a/b/c"))
    result <- ask_dir_create(dir = path %>% fs::path("a"))
    expect_true(path %>% fs::dir_exists())
})

test_that("Ask: create directory: exists = true: interactive = false", {
    if (!(path %>% fs::dir_exists())) {
        path %>% fs::dir_create(recurse = TRUE)
    }

    result <- ask_dir_create(dir = path %>% fs::path("a"), is_interactive = FALSE)
    expect_true(path %>% fs::path("a") %>% fs::dir_exists())
    expect_false(path %>% fs::path("a/b") %>% fs::dir_exists())
})
rappster/clix documentation built on Aug. 16, 2022, 9:54 p.m.