Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/tapePublic

Simple Test Anything Protocol implementation based on tape by @substack

License

NotificationsYou must be signed in to change notification settings

datkt/tape

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]

Installation

Thedatkt.tape package an be installed with various package managers.

From NPM

$ npm install @datkt/tape

Note:This will installtape intonode_modules/@datkt/tape

From clib

$ clib install datkt/tape

Note:This will installtape intodeps/tape

From GHI

$ ghi install datkt/tape

Install From Source

$ git clone git@github.com:datkt/tape.git$cd tape$ make build# or make klib$ make install

Compiling

From NPM Installation

$ konanc -r node_modules/@datkt -l tape/tape test.kt -otest

From clib Installation

$ konanc deps/@datkt/tape/*.kt test.kt -otest

From Source Installation

$ konanc -l tape test.kt -otest## library should be installed in ~/.konan/klib

Usage

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}

API

Thedatkt.tape package exports a public API documented in this section.

test(name: String, callback: (t: Test) -> Any?): Test

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()})

skip(name: String, callback: Callback?): Test

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"))})

collect(): Results?

Closes results container and writes results to underlyingwrite stream.

importdatkt.tape.collectval results= datkt.tape.collect()

class Test(name: String?, skip: Boolean, callback: Callback?, stream: Stream?)

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()

t.onBeforeRun(callback: (Test) -> Any?)

Add a callback that will be invoked before the test is ran.

t.onBeforeRun({// do something before the tests is ran})

t.onAfterRun(callback: (Test) -> Any?)

Add a callback that will be invoked after the test is ran.

t.onAferRun({// do something after the tests is ran})

t.onResult(callback: (Test, Any?) -> Any?)

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  }})

t.onPlan(callback: (Test, Int?) -> Any?)

Add a callback that will be invoked when a planhas been set.

t.onPlan(fun(_,plan:Int?) {if (null!= plan) {// do something with plan  }})

t.onEnd(callback: (Test) -> Any?)

Add a callback that will be invoked when the testhas ended.

t.onEnd({// do something when test ends})

t.run(): Test

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

t.plan(count: Int): Test

Ensure a planned assertion count for a test. Will throwError ifcount is0.

t.plan(4)

t.comment(comment: String): Test

Emit a comment

t.comment("@TODO(jwerle): Fix this")

t.end(err: Error?): Test

Ends the test runner with an optional error thatwill generate an error assertion.

t.end()

or with anError

t.end(Error("oops"))

t.assert(ok: Any?, opts: AssertionOptions?): AssertionResult

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 })

ok(ok: Any?, msg: String?, opts: AssertionOptions?): AssertionResult

Asserts that input is "ok" based on some optional assertion options.

t.ok(null== err)t.ok(thingisThing)t.ok(string.length)

notOk(ok: Any?, msg: String?, opts: AssertionOptions?): AssertionResult

Asserts that input is "not ok" based on some optional assertion options.

t.notOk(err)t.notOk(thingisThat)t.notOk(array.count)

error(err: Error?, msg: String?, opts: AssertionOptions?): AssertionResult

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

t.fail(msg: String?, opts: AssertionOptions?) : AssertionResult

Creates a failing assertion with an optional message.

t.fail("well, that didn't work")

t.pass( msg: String?, opts: AssertionOptions?) : AssertionResult

Creates a passing assertion with an optional message.

t.pass("well done!")

t.skip(msg: String?, opts: AssertionOptions?) : AssertionResult

Creates a skipping assertion with an optional message.

t.skip("we'll come back to shit")

`t.equal(a: Any?, b: Any?, msg: String?, opts: AssertionOptions?): AssertionResult

Creates an equality assertion for two values with an optionalassertion error message.

t.equal("hello","hello","hello == hello")t.equal("good","food","good != food")

`t.throws(fn: () -> Unit, expected: Any?, msg: String?, opts: AssertionOptions?): AssertionResult

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")

Building

Thetape package can be built from source into various targets.

Kotlin Library

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

Static Library

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

Shared Library

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

Tests

  • ✔ 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]

Summary

  • duration: 4ms
  • planned: 108
  • assertions: 108
  • pass: 108
  • fail: 0

References

  1. TAP -https://en.wikipedia.org/wiki/Test_Anything_Protocol
  2. Node.js -https://nodejs.org/en/
  3. NPM -https://www.npmjs.com/
  4. IMS -https://github.com/mafintosh/ims
  5. clib -https://github.com/clibs/clib
  6. GHI -https://github.com/stephenmathieson/ghi

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp