taptest
A test object returned by tap.test(). It has methods for performing tests, printing diagnostic messages, and planning the number of checks.
Methods20
function taptest.diag(test: taptest, fmt: string, ...: any) -> nil
Display a diagnostic message.
Parameters:
fmt-- the format string of the message to be displayed....-- optional arguments for the format string.
function taptest.ok(test: taptest, cond: boolean, message: string, extra: nil | table) -> boolean
This is a basic function which is used by other functions.
Depending on the value of cond, print 'ok' or 'not ok' along with debugging information. Displays the message.
Parameters:
cond-- an expression which is true or false.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the condition is true, otherwise false.
Example:
tarantool> taptest:ok(true, 'x')
ok - x
---
- true
...
tarantool> tap = require('tap')
---
...
tarantool> taptest = tap.test('test-name')
TAP version 13
---
...
tarantool> taptest:ok(1 + 1 == 2, 'X')
ok - X
---
- true
...
function taptest.fail(test: taptest, message: string, extra: nil | table) -> boolean
taptest:fail('x') is equivalent to taptest:ok(false, 'x').
Displays the message.
Parameters:
message-- name of the test.extra-- extra information to print in case of failure.
Returns false.
function taptest.skip(test: taptest, message: string, extra: nil | table) -> nil
taptest:skip('x') is equivalent to taptest:ok(true, 'x' .. '# skip').
Displays the message.
Parameters:
message-- name of the test.extra-- extra information.
Returns nil.
Example:
tarantool> taptest:skip('message')
ok - message # skip
---
- true
...
function taptest.like(test: taptest, got: any, pattern: string, message: string, extra: nil | table) -> boolean
Verify a string against a pattern. Ok if match is found.
Example:
test:like(tarantool.version, '^[1-9]', "version")
Parameters:
got-- actual result.pattern-- the pattern to search for.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the pattern matches, otherwise false.
function taptest.unlike(test: taptest, got: any, pattern: string, message: string, extra: nil | table) -> boolean
This is the negation of taptest:like().
Ok if no match is found.
Parameters:
got-- actual result.pattern-- the pattern to search for.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the pattern does not match, otherwise false.
function taptest.is(test: taptest, got: any, expected: any, message: string, extra: nil | table) -> boolean
Check whether the first argument equals the second argument.
Displays an extensive message if the result is false.
Parameters:
got-- actual result.expected-- expected result.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the arguments are equal, otherwise false.
function taptest.isnt(test: taptest, got: any, unexpected: any, message: string, extra: nil | table) -> boolean
This is the negation of taptest:is().
Parameters:
got-- actual result.unexpected-- unexpected result.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the arguments are different, otherwise false.
function taptest.is_deeply(test: taptest, got: any, expected: any, message: string, extra: nil | table) -> boolean
Recursive version of taptest:is(...).
It can be used to compare tables as well as scalar values.
Parameters:
got-- actual result.expected-- expected result.message-- name of the test.extra-- extra information to print in case of failure.
Returns true if the arguments are equal, otherwise false.
function taptest.isnil(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is nil.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.isnumber(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is a number.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.isstring(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is a string.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.istable(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is a table.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.isboolean(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is a boolean.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.isfunction(test: taptest, v: any, message: string, extra: nil | table) -> boolean
Test whether a value is a function.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.isudata(test: taptest, v: any, utype: string, message: string, extra: nil | table) -> boolean
Test whether a value is a userdata with the specified metatable type.
Displays a long message if the value is not of the specified type.
Parameters:
v-- value the type of which is to be checked.utype-- type of data that a passed value should have.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.iscdata(test: taptest, v: any, ctype: string, message: string, extra: nil | table) -> boolean
Test whether a value is a cdata of the specified type.
Displays a long message if the value is not of the specified type.
Example:
test:iscdata(slab_info.quota_size, ffi.typeof('uint64_t'),
'memcached.slab.info().quota_size returns a cdata')
Parameters:
v-- value the type of which is to be checked.ctype-- type of data that a passed value should have.message-- text that will be shown to the user in case of failure.extra-- extra information to print in case of failure.
Returns true if the value has the specified type.
function taptest.test(parent: taptest | nil, name: string, fun: tap_test_fn | nil, ...: any) -> taptest | boolean
Create a subtest, or create a subtest, run the test function and print the result.
If no fun argument is specified, create a subtest. If all arguments are specified, create a subtest, run the test function and print the result.
Parameters:
name-- an arbitrary name to give for the test outputs.fun-- the test logic to run....-- optional arguments passed tofun.
Returns the created subtest, or the result of taptest:check() if fun is specified.
function taptest.test(parent: taptest | nil, name: string, fun: tap_test_fn, ...) -> booleanparenttaptest | nilthe parent test object, or nil for the root test.
namestringan arbitrary name to give for the test outputs.
funtap_test_fn | nilthe test logic to run.
...anyoptional arguments passed to
fun.
- taptest | boolean
the created subtest, or the result of
taptest:check()iffunis specified
function taptest.plan(test: taptest, planned: number) -> nil
Indicate how many tests will be performed.
Parameters:
planned-- the number of tests to perform.
function taptest.check(test: taptest) -> boolean
Checks the number of tests performed.
The result will be a display saying # bad plan: ... if the number of completed tests is not equal to the number of tests specified by taptest:plan(...). (This is a purely Tarantool feature: "bad plan" messages are out of the TAP13 standard.)
This check should only be done after all planned tests are complete, so ordinarily taptest:check() will only appear at the end of a script. However, as a Tarantool extension, taptest:check() may appear at the end of any subtest. Therefore there are three ways to cause the check:
- by calling
taptest:check()at the end of a script, - by calling a function which ends with a call to
taptest:check(), - or by calling
taptest:test('...', subtest-function-name)where
subtest-function-name does not need to end with taptest:check() because it can be called after the subtest is complete.
Returns true if the number of completed tests equals the planned number and no tests failed, otherwise false.
Fields1
taptest.strict : boolean
Flag, true if comparisons with nil should be strict.
Set taptest.strict=true if taptest:is(), taptest:isnt() and taptest:is_deeply() must be compared strictly with nil. Set taptest.strict=false if nil and box.NULL both have the same effect. The default is false.
For example, if and only if taptest.strict=true has happened, then taptest:is_deeply({a = box.NULL}, {}) will return false.
Since v. 2.8.3, taptest.strict is inherited in all subtests:
t = require('tap').test('123')
t.strict = true
t:is_deeply({a = box.NULL}, {}) -- false
t:test('subtest', function(t)
t:is_deeply({a = box.NULL}, {}) -- also false
end)