-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathExpectation.swift
113 lines (97 loc) · 4.33 KB
/
Expectation.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//
/// A type describing an expectation that has been evaluated.
public struct Expectation: Sendable {
/// The expression evaluated by this expectation.
@_spi(ForToolsIntegrationOnly)
public internal(set) var evaluatedExpression: Expression
/// A description of the error mismatch that occurred, if any.
///
/// If this expectation passed, the value of this property is `nil` because no
/// error mismatch occurred.
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
public internal(set) var mismatchedErrorDescription: String?
/// A description of the difference between the operands in the expression
/// evaluated by this expectation, if the difference could be determined.
///
/// If this expectation passed, the value of this property is `nil` because
/// the difference is only computed when necessary to assist with diagnosing
/// test failures.
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
public var differenceDescription: String? {
evaluatedExpression.differenceDescription
}
/// A description of the exit condition that was expected to be matched.
///
/// If this expectation passed, the value of this property is `nil` because no
/// exit test failed.
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
public var mismatchedExitConditionDescription: String?
/// Whether the expectation passed or failed.
///
/// An expectation is considered to pass when its condition evaluates to
/// `true`. If it evaluates to `false`, it fails instead.
public var isPassing: Bool
/// Whether or not the expectation was required to pass.
public var isRequired: Bool
/// The source location where this expectation was evaluated.
public var sourceLocation: SourceLocation
}
/// A type describing an error thrown when an expectation fails during
/// evaluation.
///
/// The testing library throws instances of this type when the `#require()`
/// macro records an issue.
public struct ExpectationFailedError: Error {
/// The expectation that failed.
public var expectation: Expectation
}
#if !SWT_NO_SNAPSHOT_TYPES
// MARK: - Snapshotting
extension Expectation {
/// A serializable type describing an expectation that has been evaluated.
@_spi(ForToolsIntegrationOnly)
public struct Snapshot: Sendable, Codable {
/// The expression evaluated by this expectation.
public var evaluatedExpression: Expression
/// A description of the error mismatch that occurred, if any.
///
/// If this expectation passed, the value of this property is `nil` because no
/// error mismatch occurred.
public var mismatchedErrorDescription: String?
/// A description of the difference between the operands in the expression
/// evaluated by this expectation, if the difference could be determined.
///
/// If this expectation passed, the value of this property is `nil` because
/// the difference is only computed when necessary to assist with diagnosing
/// test failures.
public var differenceDescription: String?
/// Whether the expectation passed or failed.
///
/// An expectation is considered to pass when its condition evaluates to
/// `true`. If it evaluates to `false`, it fails instead.
public var isPassing: Bool
/// Whether or not the expectation was required to pass.
public var isRequired: Bool
/// The source location where this expectation was evaluated.
public var sourceLocation: SourceLocation
/// Creates a snapshot expectation from a real ``Expectation``.
/// - Parameter expectation: The real expectation.
public init(snapshotting expectation: borrowing Expectation) {
self.evaluatedExpression = expectation.evaluatedExpression
self.mismatchedErrorDescription = expectation.mismatchedErrorDescription ?? expectation.mismatchedExitConditionDescription
self.differenceDescription = expectation.differenceDescription
self.isPassing = expectation.isPassing
self.isRequired = expectation.isRequired
self.sourceLocation = expectation.sourceLocation
}
}
}
#endif