forked from Quick/Nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThrowAssertionTest.swift
77 lines (63 loc) · 1.99 KB
/
ThrowAssertionTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Foundation
import XCTest
import Nimble
private let error: Error = NSError(domain: "test", code: 0, userInfo: nil)
final class ThrowAssertionTest: XCTestCase {
func testPositiveMatch() {
#if canImport(Darwin)
expect { () -> Void in fatalError() }.to(throwAssertion())
#endif
}
func testErrorThrown() {
#if canImport(Darwin)
expect { throw error }.toNot(throwAssertion())
#endif
}
func testPostAssertionCodeNotRun() {
#if canImport(Darwin)
var reachedPoint1 = false
var reachedPoint2 = false
expect {
reachedPoint1 = true
precondition(false, "condition message")
reachedPoint2 = true
}.to(throwAssertion())
expect(reachedPoint1) == true
expect(reachedPoint2) == false
#endif
}
func testNegativeMatch() {
#if canImport(Darwin)
var reachedPoint1 = false
expect { reachedPoint1 = true }.toNot(throwAssertion())
expect(reachedPoint1) == true
#endif
}
func testPositiveMessage() {
#if canImport(Darwin)
failsWithErrorMessage("expected to throw an assertion") {
expect { () -> Void? in return }.to(throwAssertion())
}
failsWithErrorMessage("expected to throw an assertion; threw error instead <\(error)>") {
expect { throw error }.to(throwAssertion())
}
#endif
}
func testNegativeMessage() {
#if canImport(Darwin)
failsWithErrorMessage("expected to not throw an assertion") {
expect { () -> Void in fatalError() }.toNot(throwAssertion())
}
#endif
}
func testNonVoidClosure() {
#if canImport(Darwin)
expect { () -> Int in fatalError() }.to(throwAssertion())
#endif
}
func testChainOnThrowAssertion() {
#if canImport(Darwin)
expect { () -> Int in return 5 }.toNot(throwAssertion()).to(equal(5))
#endif
}
}