R Under development (unstable) (2024-01-07 r85787 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. > library(unittest, quietly = TRUE) > > expect_equal <- function (expr, expected) { + actual <- capture.output(expr) + if (!identical(all.equal(actual, expected), TRUE)) { + stop("ok_group output didn't match: ", actual) + } + } > > # Expression printed > expect_equal(ok_group("camels", TRUE), c( + "# camels")) > > # Can have multiple lines in a vector > expect_equal(ok_group(c("camels", "ostriches"), TRUE), c( + "# camels", + "# ostriches")) > > # Can divide lines with newlines too > expect_equal(ok_group(c("camels\nbadgers\r\nhoney badgers", "ostriches"), FALSE), c( + "# camels", + "# badgers", + "# honey badgers", + "# ostriches")) > > # Expression evaluated after printing section message > expect_equal(ok_group("camels", print("moo")), c( + "# camels", + '[1] "moo"')) > > # Return NULL > expect_equal({ + if (!is.null(ok_group("camels", 6))) stop("Didn't return NULL") + }, c("# camels")) > > proc.time() user system elapsed 0.25 0.07 0.26