-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathExpectation.swift
106 lines (91 loc) · 3.92 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
//
// 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.
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.
@_spi(ForToolsIntegrationOnly)
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.
@_spi(ForToolsIntegrationOnly)
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
}
/// 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
}
// MARK: - Snapshotting
extension Expectation {
/// A serializable snapshot of an ``Expectation`` instance.
@_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.
@_spi(ForToolsIntegrationOnly)
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.
@_spi(ForToolsIntegrationOnly)
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
/// Initialize an instance of this type by snapshotting the specified
/// expectation.
///
/// - Parameters:
/// - expectation: The original expectation to snapshot.
public init(snapshotting expectation: Expectation) {
self.evaluatedExpression = expectation.evaluatedExpression
self.mismatchedErrorDescription = expectation.mismatchedErrorDescription
self.differenceDescription = expectation.differenceDescription
self.isPassing = expectation.isPassing
self.isRequired = expectation.isRequired
self.sourceLocation = expectation.sourceLocation
}
}
}