R Under development (unstable) (2026-02-16 r89426 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(testit) > library(tinyimg) > > # Create a simple test PNG file > # Reuses last created plot by default; use new = TRUE to create a new plot > test_png = NULL > create_test_png = function(new = FALSE) { + if (!new && !is.null(test_png) && file.exists(test_png)) { + return(test_png) + } + tmp = tempfile(fileext = ".png") + png(tmp, width = 400, height = 400) + plot(1:10) + dev.off() + test_png <<- tmp + tmp + } > > create_test_png() [1] "D:\\temp\\2026_02_18_07_00_16_28264\\Rtmpghr2dO\\file9b7c5bb23.png" > > # Test that optim_png works with default parameters > assert("optim_png ran successfully", { + (optim_png(test_png) %==% test_png) + (file.exists(test_png)) + }) file9b7c5bb23.png | 2.0 KB -> 1.6 KB (-16.4%) > > # Test that optim_png works with output parameter > assert("optim_png created output file", { + test_png_out = tempfile(fileext = ".png") + (optim_png(test_png, test_png_out) %==% test_png_out) + (file.exists(test_png_out)) + }) file9b7c5bb23.png -> file9b7c3314245a.png | 1.6 KB -> 1.6 KB (+0.0%) > > # Test that optim_png works with different optimization levels > assert("optim_png works with level = 0", { + optim_png(test_png, level = 0) + (file.exists(test_png)) + }) file9b7c5bb23.png | 1.6 KB -> 1.6 KB (+0.0%) > > assert("optim_png works with level = 6", { + optim_png(test_png, level = 6) + (file.exists(test_png)) + }) file9b7c5bb23.png | 1.6 KB -> 1.4 KB (-13.2%) > > # Test that optim_png fails with non-existent file > assert("optim_png fails with non-existent file", { + (has_error(optim_png(tempfile()))) + }) thread '' (53808) panicked at D:\temp\2026_02_18_07_00_16_28264\RtmpOwTKyy\R.INSTALLd350256ddff\tinyimg\src\rust\vendor\extendr-api\src\robj\into_robj.rs:71:13: called `Result::unwrap()` on an `Err` value: Other("Input file does not exist: D:\\temp\\2026_02_18_07_00_16_28264\\Rtmpghr2dO\\file9b7cf6d62f1") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread '' (53808) panicked at src\lib.rs:14:1: explicit panic > > # Test alpha parameter > assert("optim_png works with alpha = TRUE", { + test_png4_out = tempfile(fileext = ".png") + optim_png(test_png, test_png4_out, alpha = TRUE) + (file.exists(test_png4_out)) + }) file9b7c5bb23.png -> file9b7c75d971b9.png | 1.4 KB -> 1.4 KB (+0.0%) > > # Test verbose parameter > assert("optim_png works with verbose = FALSE", { + test_png5_out = tempfile(fileext = ".png") + optim_png(test_png, test_png5_out, verbose = FALSE) + (file.exists(test_png5_out)) + }) > > # Test directory optimization > assert("optim_png works with directory input", { + test_dir = tempfile() + dir.create(test_dir) + for (i in 1:3) { + file.copy(test_png, file.path(test_dir, paste0("test", i, ".png"))) + } + result = optim_png(test_dir) + (length(result) %==% 3L) + (file.exists(result)) + }) test1.png | 1.4 KB -> 1.4 KB (+0.0%) test2.png | 1.4 KB -> 1.4 KB (+0.0%) test3.png | 1.4 KB -> 1.4 KB (+0.0%) > > # Test recursive directory optimization > assert("optim_png works with recursive directory optimization", { + test_dir2 = tempfile() + dir.create(test_dir2) + subdir = file.path(test_dir2, "subdir") + dir.create(subdir) + file.copy(test_png, file.path(test_dir2, "test1.png")) + file.copy(test_png, file.path(subdir, "test2.png")) + result2 = optim_png(test_dir2, recursive = TRUE) + (length(result2) %==% 2L) + (file.exists(result2)) + }) subdir/test2.png | 1.4 KB -> 1.4 KB (+0.0%) test1.png | 1.4 KB -> 1.4 KB (+0.0%) > > # Test directory to directory optimization > assert("optim_png works with directory to directory optimization", { + test_dir3 = tempfile() + dir.create(test_dir3) + file.copy(test_png, file.path(test_dir3, "test1.png")) + output_dir = tempfile() + result3 = optim_png(test_dir3, output_dir) + (dir.exists(output_dir)) + (length(list.files(output_dir, pattern = "\\.png$")) %==% 1L) + }) test1.png -> test1.png | 1.4 KB -> 1.4 KB (+0.0%) > > # Test verbose output with common parent directory > test_verbose_dir = tempfile() > dir.create(test_verbose_dir) > test_files = file.path(test_verbose_dir, paste0("test", 1:3, ".png")) > file.copy(test_png, test_files) [1] TRUE TRUE TRUE > > # Capture verbose output > verbose_output = capture.output({ + optim_png(test_files, verbose = TRUE) + }) > > assert("verbose output contains truncated paths", { + # Verbose output should not contain the full temp directory path + # It should show truncated paths like "test1.png", "test2.png", etc. + (length(verbose_output) %==% 3L) + (grepl("test[1-3]\\.png", verbose_output)) + # Make sure full paths are NOT in the output + (!any(grepl(test_verbose_dir, verbose_output, fixed = TRUE))) + }) > > # Test verbose output with single file (should show basename) > single_output = capture.output({ + optim_png(test_png, verbose = TRUE) + }) > > assert("verbose output shows basename for single file", { + (length(single_output) %==% 1L) + # Should show just the filename, not the full path + (grepl(basename(test_png), single_output)) + # Make sure full path is NOT in the output + (!grepl(test_png, single_output, fixed = TRUE)) + }) > > # Test verbose output with different input/output paths > test_diff_out = tempfile(fileext = ".png") > diff_output = capture.output({ + optim_png(test_png, test_diff_out, verbose = TRUE) + }) > > assert("verbose output shows both paths when different", { + (length(diff_output) %==% 1L) + # Should show "input -> output" format + (grepl(" -> ", diff_output)) + }) > > proc.time() user system elapsed 1.78 0.14 1.89