R Under development (unstable) (2024-05-17 r86565 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > source(file.path("_helper", "init.R")) > source(file.path("aammrtf", "ref.R")); make_ref_obj_funs("refobjs") > > test.file.dir <- file.path("_helper", "ref-objs", "translate") > test.file <- file.path(test.file.dir, "testthat", "test-translate2.R") > test.file.min <- file.path(test.file.dir, "testthat2", "test-translate-min.R") > target.dir.base <- file.path(TMP.DIR, basename(tempfile())) > target.dir <- file.path(target.dir.base, "helper", "translate", "unitizer") > > # - "Prompt to create dir" ----------------------------------------------------- > > try( + testthat_translate_file( + test.file, target.dir, prompt = "always", interactive.mode = FALSE + ) ) Error in testthat_transcribe_file(file.name, target.dir, keep.testthat.call, : Unable to proceed without creating target directory > # translations have to be outside of `testthat`; second translation should fail > # except we allow manual input > > # - "translate a file" --------------------------------------------------------- > > unitizer:::capture_output({ + unitizer:::read_line_set_vals(c("Y")) + res1 <- testthat_translate_file(test.file, target.dir, prompt = "always", + interactive.mode = TRUE) + res1.txt <- readLines(res1) + unitizer:::read_line_set_vals(c("Y")) + res2 <- testthat_translate_file(test.file, target.dir, prompt = "overwrite", + interactive.mode = TRUE) + res2.txt <- readLines(res2) + unitizer:::read_line_set_vals(NULL) + }) > dummy <- new("unitizerDummy") > > all.equal(res1.txt, rds("translate_res1")) [1] TRUE > all.equal(res1.txt, res2.txt) [1] TRUE > > # Can't do this twice in a row without prompting in non-interactive mode > # note test above does work because we use interactive mode to accept prompt > > any( + grepl( + "already exists", + capture.output( + try( + testthat_translate_file( + test.file, target.dir, prompt = "always", interactive.mode = FALSE + ) ), + type='message' + ) ) ) [1] TRUE > untz <- get_unitizer(file.path(target.dir, "translate2.unitizer")) > all.equal(untz@items.ref.calls.deparse, rds("translate_res2")) [1] TRUE > > lapply(unitizer:::as.list(untz@items.ref), function(x) x@data@value[[1L]]) [[1]] [[2]] [1] 1 2 3 4 5 6 7 8 9 10 [[3]] NULL [[4]] NULL [[5]] NULL [[6]] NULL [[7]] [1] "yoyo" [[8]] NULL > unlink(target.dir, recursive = TRUE) > > target.dir.base <- file.path(TMP.DIR, basename(tempfile())) > target.dir <- file.path(target.dir.base, "_helper", "translate", "unitizer") > > test.dir <- file.path("_helper", "ref-objs", "translate", "testthat") > > # - "translate a dir" ---------------------------------------------------------- > > unitizer:::capture_output(res2 <- testthat_translate_dir(test.dir, target.dir)) > all.equal(lapply(res2, readLines), rds("translate_res3")) [1] TRUE > untz <- get_unitizer(file.path(target.dir, "translate2.unitizer")) > all.equal(untz@items.ref.calls.deparse, rds("translate_res4")) [1] TRUE > > # Note not the same as when we did just the single file because the helper > # file is loaded so `fun0` and `fun1` are actually defined > lapply(unitizer:::as.list(untz@items.ref), function(x) x@data@value[[1L]]) [[1]] [[2]] [1] 1 2 3 4 5 6 7 8 9 10 [[3]] [1] 42 [[4]] [1] 24 [[5]] [1] 24 [[6]] NULL [[7]] [1] "yoyo" [[8]] NULL > > # Can't do it again since there are files there > any( + grepl( + "safety feature to ensure files are not accidentally overwritten", + capture.output( + try(testthat_translate_dir(test.dir, target.dir)), type='message' + ) ) ) [1] TRUE > > # - minimal -------------------------------------------------------------------- > > # to test parameters > > writeLines( + readLines( + testthat_translate_file( + test.file.min, target.dir, prompt = "never", interactive.mode = TRUE, + unitize = FALSE + ) ) ) # Minimal translation # test_that("simple tests", { # expect_equal(fun0(a), 1:10) # }) unitizer_sect("simple tests", { # expect_equal(fun0(a), 1:10) fun0(a) }) > writeLines( + readLines( + testthat_translate_file( + test.file.min, target.dir, prompt = "never", interactive.mode = TRUE, + use.sects = FALSE, unitize = FALSE + ) ) ) # Minimal translation # test_that("simple tests", { # expect_equal(fun0(a), 1:10) # }) # - "simple tests" ------------------------------------------------------------- # expect_equal(fun0(a), 1:10) fun0(a) > writeLines( + readLines( + testthat_translate_file( + test.file.min, target.dir, prompt = "never", interactive.mode = TRUE, + use.sects = FALSE, keep.testthat.call = FALSE, unitize = FALSE + ) ) ) # Minimal translation # - "simple tests" ------------------------------------------------------------- fun0(a) > > > > proc.time() user system elapsed 1.70 0.10 1.79