Skip to content

Commit 8a04b23

Browse files
committed
Add tests and documentation
1 parent a1d46ae commit 8a04b23

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

inst/tests/self.Rraw

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ test(1.1, test(0, warning("a"), warning=c("a", "b"), check_value=FALSE), FALSE,
1212
output="Test 0 produced 1 warnings but expected 2\nExpected: a\n b\nObserved: a")
1313
test(1.2, test(0, {warning("a"); warning("b")}, warning="a", check_value=FALSE), FALSE,
1414
output="Test 0 produced 2 warnings but expected 1\nExpected: a\nObserved: a\n b")
15+
16+
# test() catches unexpected console output, #7847
17+
test(2.1, test(0, {cat("123\n"); TRUE}), FALSE,
18+
output="Test 0 produced unexpected output:\n123")
19+
# output printed by verbose mode itself doesn't count as unexpected, #7847
20+
test(2.2, test(0, data.table(a = 1:3)[, sum(a)], 6L),
21+
options=c(datatable.verbose=TRUE),
22+
notOutput="Detected that j")

man/test.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ test(num, x, y = TRUE, ...,
3737

3838
Multiple warnings are supported; supply a vector of strings to \code{warning=}. If \code{x} does not produce the correct number of warnings in the correct order, the test will fail.
3939

40+
Unless \code{output=} or \code{notOutput=} is supplied, you are automatically asserting that \code{x} prints nothing to the console; the test will fail if it does. This does not apply when \code{datatable.verbose} is \code{TRUE}.
41+
4042
Strings passed to \code{notOutput=} should be minimal; e.g. pick out single words from the output that you desire to check does not occur. The reason being so that the test does not incorrectly pass just because the output has slightly changed. For example \code{notOutput="revised"} is better than \code{notOutput="revised flag to true"}. \code{notOutput=} is automatically case insensitive for this reason.
4143
}
4244
\value{

0 commit comments

Comments
 (0)