tests/testthat/test-extract_make.R

## 'extract_make' -----------------------------------------------------------------

test_that("'extract_make' works with no dir_make", {
  dir_tmp <- tempfile(tmpdir = getwd())
  if (file.exists(dir_tmp))
    unlink(dir_tmp, recursive = TRUE)
  dir.create(dir_tmp)
  path_file <- fs::path_rel(path = file.path(dir_tmp, "script.R"),
                            start = getwd())
  writeLines("cmd_assign(.data = 'data/mydata.csv', use_log = FALSE, .out = 'out/cleaned.rds')",
             con = path_file)
  capture.output(ans_obtained <- extract_make(path_file = path_file))
  path_file_comb <- fs::path(getwd(), path_file)
  ans_expected <- paste0("out/cleaned.rds: ", path_file_comb, " \\\n",
                         "  data/mydata.csv\n",
                         "\t", "Rscript $^ $@ --use_log=FALSE\n")
  expect_identical(ans_obtained, ans_expected)
  unlink(dir_tmp, recursive = TRUE)
})

test_that("'extract_make' works with dir_make", {
  dir_tmp <- tempfile(tmpdir = getwd())
  if (file.exists(dir_tmp))
    unlink(dir_tmp, recursive = TRUE)
  dir.create(dir_tmp)
  path_file <- "script.R"
  writeLines("cmd_assign(.data = 'data/mydata.csv', use_log = FALSE, .out = 'out/cleaned.rds')",
             con = fs::path(dir_tmp, path_file))
  capture.output(ans_obtained <- extract_make(path_file = path_file,
                                          dir_make = dir_tmp))
  path_file_comb <- fs::path(dir_tmp, path_file)
  ans_expected <- paste0("out/cleaned.rds: ", path_file_comb, " \\\n",
                         "  data/mydata.csv\n",
                         "\t", "Rscript $^ $@ --use_log=FALSE\n")
  expect_identical(ans_obtained, ans_expected)
  unlink(dir_tmp, recursive = TRUE)
})

Try the command package in your browser

Any scripts or data that you put into this service are public.

command documentation built on Nov. 5, 2025, 7 p.m.