dankogai/swift-tap
Test Anything Protocol for Swift
Usage
- Add this project to your
Package.swift.
import PackageDescription
let package = Package(
// ...
dependencies: [
.Package(
url: "https://github.com/dankogai/swift-tap.git", from: "0.6.0"
)
],
// ...
)
- write [main.swift] like below:
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 42test 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.ok, .eq and .ne
.ok
Checks if predicate is true.
func ok(@autoclosure predicate:()->Bool, _ message:String = "")->Bool.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 actual and expected must be Equatable. So:
- use
.eqwhenever you can. - use
.okas a last resort.
public func eq<T:Equatable>(actual:T, _ expected:T, _ message:String = "")->BoolAs you can tell from the type signatures, .eq and .ne accepts arrays and dictionaries if they are equatable.
.ne
The opposite of .eq.
public func ne<T:Equatable>(actual:T, _ expected:T, _ message:String = "")->BoolWhy NOT [XCTest]?
[XCTest]: https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/01-introduction.html [travis]: https://travis-ci.org
- Still way too fancy and resource-demanding for some occasions
See Also
- https://testanything.org
- https://en.wikipedia.org/wiki/Test_Anything_Protocol
Package Metadata
Repository: dankogai/swift-tap
Stars: 5
Forks: 1
Open issues: 0
Default branch: master
Primary language: swift
License: MIT
README: README.md