test_pkg() now sources global helper files (helper*.R) from the parent directory of the test directory before sourcing helpers in the test subdirectory itself. This allows sharing common test utilities across multiple test subdirectories (e.g., tests/testit/, tests/test-cran/).test_pkg() now checks commandArgs(TRUE) for --filter=PATTERN and --update when the filter and update arguments are not explicitly provided. This allows you to run Rscript tests/*.R --filter=PATTERN --update without modifying individual test_pkg() calls.
The fact argument of assert() now works with any character value, not just string literals. For example, assert(paste('test', name), { ... }) and assert(msg, { ... }) now work correctly.
() test conditions inside assert('fact', { ... }) now work inside if, for, while, and repeat bodies. Previously only top-level () expressions in {} were checked. Only statement-level () is treated as a test; parentheses used for grouping within expressions (e.g., (a + b) * c) are not affected. The entire {} block is now evaluated in a single frame, so on.exit() works as expected inside assert().
Error messages from assert() and test_pkg() are no longer truncated by R’s warning.length option (default 1000 characters). Previously, when many test failures accumulated, the combined error message could exceed the limit and lose trailing failures (thanks, @jdblischak, #24).
test_pkg() gained a filter argument that takes a regular expression to selectively run a subset of test files (e.g., test_pkg(filter = 'parse') runs only files with “parse” in their names).
test_pkg() now runs all test files instead of stopping at the first failure. Errors are collected and reported together at the end, including multiple errors within a single file (thanks, @jdblischak, #19). The relative filename of each test is printed before execution.
assert() now includes the actual value of the failed expression in the error message, making it easier to diagnose assertion failures (e.g., (x %==% y) is not TRUE but FALSE).
has_message(), has_warning(), and has_error() gained a message argument for matching the condition message via grepl(), and ... for passing additional arguments to grepl() (e.g., fixed = TRUE, ignore.case = TRUE).
Added support for helper files in tests. Helper files matching helper*.R are sourced into a dedicated environment before tests run, and their objects are available to all tests and snapshots.
Fixed a bug in test_snaps() where a code block without an output block would incorrectly claim a later output block (belonging to a subsequent code block) instead of inserting a new one.
has_error() is now always silent (no longer prints error messages to the console), and its silent argument has been removed.
test_pkg() now suppresses messages and warnings from test scripts, helper files, and snapshot code evaluation. Diagnostic output (diffs, error locations) is emitted via message() so it can be suppressed by callers if needed.
Error messages now include precise source locations (file and line number). assert() reports the exact line of the failing sub-expression, and test_pkg() reports error locations in test scripts, helper files, and snapshot code blocks.
test_pkg() now installs the package to the system temp directory instead of a local R-lib-* folder, and fixes DLL cleanup on Windows so the temporary library can be properly removed (thanks, @jdblischak, #20).
test_pkg() no longer reinstalls the package unnecessarily when called multiple times in the same session. It compares source file modification times against the installed package timestamp to decide if reinstallation is needed.
Snapshot tests now support both ```r and ```{r} R code fences, and snapshot updates preserve the original fence style.
Added and updated snapshot tests (including mini_diff() output snapshots) and refreshed snapshot testing documentation/examples.
test_pkg() compatible with R < 3.3.0 (again).The error location reporting stopped working in the previous version and was fixed in this version.
The error location will come with a clickable link on it if the environment supports ANSI links.
test_pkg() is compatible with R < 3.3.0 (if the function .traceback() is unavailable, the error location will not be printed).
Re-licensed the package to MIT.
options(testit.cleanup = TRUE) (TRUE is the default) can be used to clean up additional files or directories generated in the tests/ directory during the test process.test_pkg() installs the package before running tests when it is called from a non-interactive R session that is not launched by R CMD check, e.g., when you run tests in RStudio via Ctrl/Cmd + Shift + T, so you will not have to install the package manually (Ctrl/Cmd + Shift + B) before running tests.test_pkg() also looks for tests under the tests/testit/ directory. This makes it easier for you to run test_pkg() under the root directory of the package, and you don’t need to change the working directory to tests/.silent to has_error() (thanks, @StevenMMortimer, #6).%==% is used inside assert(), a message will be printed if the value is not TRUE, to show the values of the LHS and RHS, respectively.test_pkg() runs package tests with top-level environment being set to the namespace of the tested package (thanks, @kalibera, #3)
all test scripts (test-*.R) are assumed to be encoded in UTF-8 if they contain multibyte characters
added an infix operator %==% as an alias of identical() (in RStudio, you can use an add-in to insert the text %==%)
test_pkg() will print out the filename of the R script that errored
fact argument of assert() is optional now: all arguments of assert() can be test conditionsthe test files have to be named of the form test-.R (or test-.r), i.e. they have to use the prefix test-
the test environment is always cleaned (all objects removed) before the next test is run
this is the first version of testit; the source code is hosted on Github: https://github.com/yihui/testit
added functions assert(), test_pkg(), has_error() and has_warning()