"get_paths() returns NULL for non-existent file"
"get_paths() hash changes when file content changes"
"write_code() creates human-readable .code.R file when debug_cache is TRUE"
"load_code() returns NULL for non-existent cache"
"load_code() returns NULL for version mismatch"
"load_code() returns NULL for coverage mismatch"
"load_code() returns NULL for missing coverage field (pre-upgrade cache)"
"load_code() returns NULL for hash mismatch"
"cache hit path excludes _-prefixed names from export-all exports"
"  (define _private-helper (lambda () 2))"
"cache hit path must exclude _-prefixed names"
"cache hit path must exclude .__-prefixed names"
"write_code() stores compiler_flags in cache data"
"load_code() rejects cache with mismatched compiler_flags"
"load_code() rejects cache with NULL compiler_flags (pre-upgrade)"
"load_code() rejects cache with NULL default_packages (pre-upgrade)"
"write_code() cleans up old cache files for same source"
"write_code() uses provided cache_paths instead of recomputing"
"cache file should be at V1 path (provided cache_paths)"
"code cache is written for loaded modules"
"expr cache (.code.rds) should be written"
"code cache reused across engine instances"
"get_paths() always uses R_user_dir for cache"
"(module tmp-test (export x) (define x 1))"
"cache_dir should contain /modules/ subdirectory"

<arl_error/error/condition>
Error: cannot open the connection

# Comprehensive I/O operation tests: file I/O, directories, parsing, system operations
test_that("read-file and write-file work with strings", {
import_stdlib_modules(engine, c("io"), env = env)
engine$read(sprintf('(write-file "%s" "hello world")', tmp))[[1]], env = env)
engine$read(sprintf('(read-file "%s")', tmp))[[1]], env = env)
test_that("read-lines and write-lines work with lists", {
engine$read(sprintf('(write-lines "%s" (list "line1" "line2" "line3"))', tmp))[[1]], env = env)
engine$read(sprintf('(read-lines "%s")', tmp))[[1]], env = env)
test_that("write-file works with lists converted to lines", {
# Write list as lines with newline separator
engine$read(sprintf('(write-file "%s" (list "line1" "line2"))', tmp))[[1]], env = env)
test_that("append-file adds content to existing file", {
engine$read(sprintf('(write-file "%s" "first")', tmp))[[1]], env = env)
engine$read(sprintf('(append-file "%s" "second")', tmp))[[1]], env = env)
test_that("file-exists? checks file existence", {
engine$read(sprintf('(file-exists? "%s")', tmp))[[1]], env = env)
test_that("file-size returns file size in bytes", {
engine$read(sprintf('(file-size "%s")', tmp))[[1]], env = env)
test_that("file-size errors on non-existent file", {
engine$read(sprintf('(file-size "%s")', tmp))[[1]], env = env),
test_that("file-modified-time returns modification timestamp", {
engine$read(sprintf('(file-modified-time "%s")', tmp))[[1]], env = env)
# Should be numeric timestamp close to now
engine$read(sprintf('(file-delete "%s")', tmp))[[1]], env = env)
test_that("file-delete errors on non-existent file", {
engine$read(sprintf('(file-delete "%s")', tmp))[[1]], env = env),
test_that("directory-exists? checks directory existence", {
engine$read(sprintf('(directory-exists? "%s")', tmp))[[1]], env = env)
test_that("directory-list returns list of filenames", {
engine$read(sprintf('(directory-list "%s")', tmp))[[1]], env = env)
test_that("directory-list with full.names returns full paths", {
engine$read(sprintf('(directory-list "%s" #t)', tmp))[[1]], env = env)
expect_match(result[[1]], "^(/|[A-Za-z]:)")  # Full path starts with / or drive letter
test_that("directory-list errors on non-existent directory", {
engine$read(sprintf('(directory-list "%s")', tmp))[[1]], env = env),
engine$read(sprintf('(directory-delete "%s")', tmp))[[1]], env = env)
test_that("directory-delete errors on non-existent directory", {
engine$read(sprintf('(directory-delete "%s")', tmp))[[1]], env = env),
test_that("read parses Arl expressions from strings", {
engine$read('(read "foo")')[[1]], env = env)
engine$read('(read "42")')[[1]], env = env)
test_that("read-from-string is alias for read", {
engine$read('(read-from-string "(+ 1 2)")')[[1]], env = env)
test_that("setenv and getenv work with environment variables", {
engine$read('(setenv "ARL_TEST_VAR" "test_value")')[[1]], env = env)
engine$read('(getenv "ARL_TEST_VAR")')[[1]], env = env)
test_that("getenv returns #nil for unset variable", {
engine$read('(getenv "ARL_NONEXISTENT_VAR")')[[1]], env = env)
test_that("system executes commands and returns exit code", {
engine$read('(system "true")')[[1]], env = env)
engine$read('(system "false")')[[1]], env = env)
test_that("system-output captures command output", {
engine$read('(system-output "echo hello")')[[1]], env = env)
# Coverage: Output functions (write-string, newline, print)
result <- engine$eval(engine$read('(write-string "hello")')[[1]], env = env))
expect_null(result)  # write-string returns #nil
test_that("newline outputs a newline", {
result <- engine$eval(engine$read("(newline)")[[1]], env = env))
expect_null(result)  # newline returns #nil
test_that("print outputs value and returns it", {
result <- engine$eval(engine$read("(print 42)")[[1]], env = env))