R Under development (unstable) (2026-01-23 r89325 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 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. > library(mfdb) > library(unittest, quietly = TRUE) > helpers <- c('utils/helpers.R', 'tests/utils/helpers.R') ; source(helpers[file.exists(helpers)]) > > ok_group("Will create a directory when creating gadget_directories", { + dir <- tempfile() + ok(!file.exists(dir)) + gd <- gadget_directory(dir) + ok(file.exists(dir) && file_test("-d", dir)) + }) # Will create a directory when creating gadget_directories ok - !file.exists(dir) ok - file.exists(dir) && file_test("-d", dir) > > ok_group("Can write files", { + # Create a temporary directory, starts off empty + dir <- tempfile() + gd <- gadget_directory(dir) + expect_equal(list.files(dir), character(0)) + + # Write out files, come back the same + gf_animals <- gadget_file("animals", components = list(list(cow = "Daisy", pig = "George"))) + gadget_dir_write(gd, gf_animals) + expect_equal(gadget_dir_read(gd, "animals"), gf_animals) + expect_equal(list.files(dir), c("animals")) + + gf_plants <- gadget_file("plants", components = list(list(tree = "The larch", tree = "The pine"))) + gadget_dir_write(gd, gf_plants) + expect_equal(gadget_dir_read(gd, "plants"), gf_plants) + expect_equal(list.files(dir), c("animals", "plants")) + }) # Can write files ok - list.files(dir) == character(0) ok - gadget_dir_read(gd, "animals") == gf_animals ok - list.files(dir) == c("animals") ok - gadget_dir_read(gd, "plants") == gf_plants ok - list.files(dir) == c("animals", "plants") > > ok_group("Can write files into model subdirectories", { + dir <- tempfile() + gd <- gadget_directory(dir) + ok(cmp(list.files(dir, recursive = TRUE), character(0)), "Directory currently empty") + + gf <- gadget_file("field/animals", components = list( + list(), + cows = list("daisy" = 4, "freda" = 2), + pigs = list("george" = 3, "arnold" = 8))) + gadget_dir_write(gd, gf) + ok(cmp(list.files(dir, recursive = TRUE), c( + "field/animals", + NULL)), "Wrote our animals file into the field directory") + + gf2 <- gadget_dir_read(gd, "field/animals") + ok(cmp(gf, gf2), "File read back is identical") + + gf2$components$pigs$george = 99 + gadget_dir_write(gd, gf2) + ok(cmp(list.files(dir, recursive = TRUE), c( + "field/animals", + NULL)), "Altered animals, wrote back in right place") + + gf3 <- gadget_dir_read(gd, "field/animals") + ok(cmp(gf2, gf3), "Content is correct") + }) # Can write files into model subdirectories ok - Directory currently empty ok - Wrote our animals file into the field directory ok - File read back is identical ok - Altered animals, wrote back in right place ok - Content is correct > > ok_group("Can create files in model subdirectories", { + dir <- tempfile() + gd <- gadget_directory(dir) + ok(cmp(list.files(dir, recursive = TRUE), character(0)), "Directory currently empty") + + ok(cmp_error(gadget_dir_read(gd, "farmhouse/kitchen", missing_okay = FALSE), "farmhouse"), + "Can complain about missing files if we want to") + gf <- gadget_dir_read(gd, "farmhouse/kitchen") + ok(cmp(gf$components, list()), "No components yet") + + ok(cmp(list.files(dir, recursive = TRUE), character(0)), "Directory still empty") + gadget_dir_write(gd, gf) + ok(cmp(list.files(dir, recursive = TRUE), c("farmhouse/kitchen")), "Wrote file, created directory") + }) # Can create files in model subdirectories ok - Directory currently empty ok - Can complain about missing files if we want to ok - No components yet ok - Directory still empty ok - Wrote file, created directory > > proc.time() user system elapsed 0.60 0.20 0.79 1..17 # Looks like you passed all 17 tests.