import TAP
let test = TAP(tests:3)
test.ok(42+0.195 == 42.195, "42 + 0.195 == 42.195") // ok 1 - 42 + 0.195 == 42.195
test.eq(42+0.195, 42.195, "42 + 0.195 is 42.195") // ok 2 - 42 + 0.195 is 42.195
test.ne(42+0.195, 42, "42 + 0.195 is not 42") // ok 3 - 42 + 0.195 is not 42
test.done()
build and test like below:
$ swift run && prove .build/debug/main
./main .. ok
All tests successful.
Files=1, Tests=2, 0 wallclock secs ( 0.02 usr + 0.00 sys = 0.02 CPU)
Result: PASS
./main actually prints the following:
1..3
ok 1 - 42 + 0.195 == 42.195
ok 2 - 42 + 0.195 is 42.195
ok 3 - 42 + 0.195 is not 42
test without plan
You should specify the number of tests to run via TAP(tests:Int) or .plan(_:Int) but this is optional. But when you do so you cannot omit .done() which prints 1..number_of_tests that the TAP protocol demands.
ok 1 - 42 + 0.195 == 42.195
ok 2 - 42 + 0.195 is 42.195
ok 3 - 42 + 0.195 is not 42
1..2
swift-tap
Test Anything Protocol (TAP) for Swift
Usage
Package.swift../mainactually prints the following:test without plan
You should specify the number of tests to run via
TAP(tests:Int)or.plan(_:Int)but this is optional. But when you do so you cannot omit.done()which prints1..number_of_teststhat the TAP protocol demands..ok,.eqand.ne.ok
Checks if
predicateis true..eq
Checks if
actual==expected. Analogous to.ok(actual == expected)but it is more informative when it is not ok.On the other hand both
actualandexpectedmust beEquatable. So:.eqwhenever you can..okas a last resort.As you can tell from the type signatures,
.eqand.neaccepts arrays and dictionaries if they are equatable..ne
The opposite of
.eq.Why NOT XCTest?
See Also