An internal testing function used in
data.table test scripts that are run by
test(num, x, y = TRUE, error = NULL, warning = NULL, message = NULL, output = NULL, notOutput = NULL, ignore.warning = NULL)
A unique identifier for a test, helpful in identifying the source of failure when testing is not working. Currently, we use a manually-incremented system with tests formatted as
An input expression to be evaluated.
Pre-defined value to compare to
When you are testing behaviour of code that you expect to fail with an error, supply the expected error message to this argument. It is interpreted as a regular expression, so you can be abbreviated, but try to include the key portion of the error so as not to accidentally include a different error message.
If you are testing the printing/console output behaviour; e.g. with
Or if you are testing that a feature does not print particular console output. Case insensitive (unlike output) so that the test does not incorrectly pass just because the string is not found due to case.
A single character string. Any warnings emitted by
NaN are treated as equal, use
identical if distinction is needed. See examples below.
warning= is not supplied then you are automatically asserting no warning is expected; the test will fail if any warning does occur. Similarly for
Multiple warnings are supported; supply a vector of strings to
x does not produce the correct number of warnings in the correct order, the test will fail.
Strings passed to
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
notOutput="revised" is better than
notOutput="revised flag to true".
notOutput= is automatically case insensitive for this reason.
TRUE when test passes,
FALSE when test fails. Invisibly.
test = data.table:::test test(1, x = sum(1:5), y = 15L) test(2, log(-1), NaN, warning="NaNs") test(3, sum("a"), error="invalid.*character") # test failure example stopifnot( test(4, TRUE, FALSE) == FALSE )#> Test 4 ran without errors but failed check that x equals y: #> > x = TRUE #> First 1 of 1 (type 'logical'): #>  TRUE #> > y = FALSE #> First 1 of 1 (type 'logical'): #>  FALSE #> 1 element mismatch