|
| 1 | +if(!nzchar(Sys.getenv('NOT_CRAN'))) q() |
| 2 | + |
| 3 | +source(file.path("_helper", "init.R")) |
| 4 | + |
| 5 | +# - "test file / store manip" ------------------------------------------------ |
| 6 | + |
| 7 | +as.character.custstore <- function(x, ...) x |
| 8 | +stopifnot( |
| 9 | + all.equal(unitizer:::as.store_id_chr(file.path(getwd(), "hello")), "hello"), |
| 10 | + grepl( |
| 11 | + "Unable to convert store id to character", |
| 12 | + try(unitizer:::as.store_id_chr(structure("hello", class = "untz_stochrerr"))), |
| 13 | + ), |
| 14 | + all.equal( |
| 15 | + unitizer:::best_store_name( |
| 16 | + structure(list("hello", class = "custstore")), "hello" |
| 17 | + ), |
| 18 | + "unitizer for test file 'hello'" |
| 19 | + ), |
| 20 | + all.equal( |
| 21 | + unitizer:::best_store_name( |
| 22 | + structure(list("hello", class = "custstore")), NA_character_ |
| 23 | + ), |
| 24 | + "<untranslateable-unitizer-id>" |
| 25 | + ), |
| 26 | + all.equal( |
| 27 | + unitizer:::best_file_name( |
| 28 | + structure(list("hello", class = "custstore")), NA_character_ |
| 29 | + ), |
| 30 | + "<unknown-test-file>" |
| 31 | + ) |
| 32 | +) |
| 33 | + |
| 34 | +# - read only ------------------------------------------------------------------ |
| 35 | + |
| 36 | +# try to write to read only |
| 37 | +# seems to be case that root can always write so defeats this test |
| 38 | +if (identical(.Platform$OS.type, "unix")) { |
| 39 | + toy.path <- file.path("_helper", "unitizers", "misc.unitizer") |
| 40 | + toy.stor <- readRDS(file.path(toy.path, "data.rds")) |
| 41 | + |
| 42 | + ro.dir <- tempfile() |
| 43 | + on.exit(unlink(ro.dir)) |
| 44 | + dir.create(ro.dir, mode = "0500") |
| 45 | + if (!identical(try(system("whoami", intern = TRUE), silent = TRUE), "root")) { |
| 46 | + err <- try( |
| 47 | + capture.output(set_unitizer(ro.dir, toy.stor), type = "message"), |
| 48 | + ) |
| 49 | + stopifnot( |
| 50 | + grepl("Failed setting unitizer", conditionMessage(attr(err, 'condition'))) |
| 51 | + ) |
| 52 | + } |
| 53 | +} |
| 54 | +# - "as.state" ----------------------------------------------------------------- |
| 55 | + |
| 56 | +# This fails on winbuilder machines? Not entirely clear why it would given that |
| 57 | +# the only obvious difference in the dir structure is that the test dirs are |
| 58 | +# tests_x64, etc., instead of just tests, but the code doesn't care about that. |
| 59 | +# A bit of a red herring is that the winbuilder artifact dir is not actually |
| 60 | +# the directory the tests are run in (we know because we ran a pwd() in one of |
| 61 | +# our tests). |
| 62 | + |
| 63 | +in.pkg.state <- unitizer:::as.state( |
| 64 | + unitizer:::unitizerStateRaw(par.env = in_pkg()), test.files = getwd() |
| 65 | +) |
| 66 | +stopifnot( |
| 67 | + identical( |
| 68 | + in.pkg.state, |
| 69 | + unitizer:::unitizerStateProcessed(par.env = getNamespace("unitizer")) |
| 70 | + ) |
| 71 | +) |
0 commit comments