- Notifications
You must be signed in to change notification settings - Fork0
Simple Test Anything Protocol implementation based on tape by @substack
License
datkt/tape
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TAP [1] output producing test runner for Kotlin mostly ported from@substack'stape module for Node.js [2]. Thispackage is installable with NPM [3], IMS [4], clib [5], GHI [6], and ofcourse, from [source][#install-from-source]
Thedatkt.tape
package an be installed with various package managers.
$ npm install @datkt/tape
Note:This will installtape intonode_modules/@datkt/tape
$ clib install datkt/tape
Note:This will installtape intodeps/tape
$ ghi install datkt/tape
$ git clone git@github.com:datkt/tape.git$cd tape$ make build# or make klib$ make install
$ konanc -r node_modules/@datkt -l tape/tape test.kt -otest
$ konanc deps/@datkt/tape/*.kt test.kt -otest
$ konanc -l tape test.kt -otest## library should be installed in ~/.konan/klib
importdatkt.tape.collectimportdatkt.tape.testimportlerp.*funmain(args:Array<String>) { test("lerp(a, b, c)",fun(t:Test) {val x=1.0val y=2.0val z= lerp(x, y,1.0) t.plan(1) t.ok(2.0== z,"lerp compute fail :shrug:") t.end() }) collect()// collects results and prints to stdout}
Thedatkt.tape
package exports a public API documented in this section.
Creates and returns a new named scoped test. The test callbackwill not be invoked if null is given.
importdatkt.tape.testtest("function test",fun(t:Test) { t.plan(1) t.ok(true,"we're okay") t.end()})
Creates and returns a new skipped scoped test. The test callbackwill not be invoked if null is given.
importdatkt.tape.skipskip("skipped test",fun(t:Test) { t.end(Error("This should never run"))})
Closes results container and writes results to underlyingwrite stream.
importdatkt.tape.collectval results= datkt.tape.collect()
TheTest
class represents a named test that is invoked in afunction callback. When a test is running, it will call various function hooksand write TAP formatted output to a stream.
t=Test("thing",false,fun(t:Test) { t.end})t.run()
Add a callback that will be invoked before the test is ran.
t.onBeforeRun({// do something before the tests is ran})
Add a callback that will be invoked after the test is ran.
t.onAferRun({// do something after the tests is ran})
Add a callback that will be invoked when thereis a test result. It could be aString
orAssertionResult
.
t.onResult(fun(_,result:Any?) {if (resultisString) {// do something with result string }elseif (resultisAssertionResult) {// do something with assertion result }})
Add a callback that will be invoked when a planhas been set.
t.onPlan(fun(_,plan:Int?) {if (null!= plan) {// do something with plan }})
Add a callback that will be invoked when the testhas ended.
t.onEnd({// do something when test ends})
Runs the test runner invoking the runner callbackgiven to the constructor if the test is not skipped.
t.run()// will call test callback, if test is not skipped
Ensure a planned assertion count for a test. Will throwError
ifcount
is0
.
t.plan(4)
Emit a comment
t.comment("@TODO(jwerle): Fix this")
Ends the test runner with an optional error thatwill generate an error assertion.
t.end()
or with anError
t.end(Error("oops"))
Asserts that input is truthy based on some optional assertion options.
t.assert(true)t.assert(1234)t.assert("okay")t.assert(::println)t.assert({1+1 })
Asserts that input is "ok" based on some optional assertion options.
t.ok(null== err)t.ok(thingisThing)t.ok(string.length)
Asserts that input is "not ok" based on some optional assertion options.
t.notOk(err)t.notOk(thingisThat)t.notOk(array.count)
Asserts that an error is falsy. If an error is giventhe message is used in the assertion.
t.error(Error("oops"))// failing assertiont.error(null)// passing
Creates a failing assertion with an optional message.
t.fail("well, that didn't work")
Creates a passing assertion with an optional message.
t.pass("well done!")
Creates a skipping assertion with an optional message.
t.skip("we'll come back to shit")
Creates an equality assertion for two values with an optionalassertion error message.
t.equal("hello","hello","hello == hello")t.equal("good","food","good != food")
Creates an assertion that checks for an error to be throwninside of a given function.
t.throws({throwError("oops") })// passest.throws({throwException("yikes") },Error,"Expection != Error")
Thetape
package can be built from source into various targets.
tape.klib
, a Kotlin library that can be linked withkonanc
can bebuilt from source.
$ make klib
which will producebuild/lib/tape.klib
. The library can be installedwithklib
by runningmake install
libtape.a
, a static library that can be linked withkonanc
can bebuilt from source.
$ make static
which will producebuild/lib/libtape.a
and C header files inbuild/include
. The library can be installed into your system byrunningmake install
. The path prefix can be set by defining thePREFIX
environment ormake
variable. It defaults toPREFIX=/usr/local
libtape.so
, a shared library that can be linked withkonanc
can bebuilt from source.
$ make shared
which will producebuild/lib/libtape.so
and C header files inbuild/include
. The library can be installed into your system byrunningmake install
. The path prefix can be set by defining thePREFIX
environment ormake
variable. It defaults toPREFIX=/usr/local
- ✔ assert [pass: 21, fail: 0, duration: 0ms]
- ✔ constants [pass: 13, fail: 0, duration: 0ms]
- ✔ context [pass: 6, fail: 0, duration: 0ms]
- ✔ options [pass: 6, fail: 0, duration: 0ms]
- ✔ result [pass: 5, fail: 0, duration: 0ms]
- ✔ results [pass: 0, fail: 0, duration: 1ms]
- ✔ simple [pass: 0, fail: 0, duration: 0ms]
- ✔ simple [pass: 2, fail: 0, duration: 0ms]
- ✔ stream [pass: 8, fail: 0, duration: 0ms]
- ✔ test [pass: 36, fail: 0, duration: 0ms]
- ✔ truthy [pass: 11, fail: 0, duration: 3ms]
- duration: 4ms
- planned: 108
- assertions: 108
- pass: 108
- fail: 0
- TAP -https://en.wikipedia.org/wiki/Test_Anything_Protocol
- Node.js -https://nodejs.org/en/
- NPM -https://www.npmjs.com/
- IMS -https://github.com/mafintosh/ims
- clib -https://github.com/clibs/clib
- GHI -https://github.com/stephenmathieson/ghi
MIT
About
Simple Test Anything Protocol implementation based on tape by @substack