Tarantool Lua API

tap

The Test Anything Protocol version 13 producer.

The tap module streamlines the testing of other modules. It allows writing of tests in the TAP protocol. The results from the tests can be parsed by standard TAP-analyzers so they can be passed to utilities such as prove. Thus, one can run tests and then use the results for statistics, decision-making, and so on.

Example

To run this example: put the script in a file named ./tap.lua, then make tap.lua executable by saying chmod a+x ./tap.lua, then execute using Tarantool as a script processor by saying ./tap.lua.

#!/usr/bin/tarantool
local tap = require('tap')
test = tap.test("my test name")
test:plan(2)
test:ok(2 * 2 == 4, "2 * 2 is 4")
test:test("some subtests for test2", function(test)
     test:plan(2)
     test:is(2 + 2, 4, "2 + 2 is 4")
     test:isnt(2 + 3, 4, "2 + 3 is not 4")
end)
test:check()

The output from the above script will look approximately like this:

TAP version 13
1..2
ok - 2 * 2 is 4
     # some subtests for test2
     1..2
     ok - 2 + 2 is 4
     ok - 2 + 3 is not 4
     # some subtests for test2: end
ok - some subtests for test2

Methods1

function M.test(name: string, fun: tap_test_fn | nil, ...: any) -> taptest | boolean

Initialize a test.

The result of tap.test is an object, which is necessary for taptest:plan() and all the other methods.

Example:

tap = require('tap')
taptest = tap.test('test-name')
Overloads
function M.test(name: string) -> taptest
function M.test(name: string, fun: tap_test_fn, ...) -> boolean
Parameters
namestring

an arbitrary name to give for the test outputs.

funtap_test_fn | nil

the test logic to run.

...any

optional arguments passed to fun.

Returns
taptest | boolean