-
Notifications
You must be signed in to change notification settings - Fork 47
[chore]: improve Swift Testing support in test utilities #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
|
||
#if DEBUG | ||
import IssueReporting | ||
import Workflow | ||
import WorkflowTesting | ||
import XCTest | ||
|
@@ -62,9 +63,9 @@ extension RenderTester { | |
guard !workflow.worker.isEquivalent(to: expectedWorker) else { | ||
return | ||
} | ||
XCTFail( | ||
reportIssue( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no Apple-provided way to do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by 'this', what do you mean? record an issue in either testing framework? if so, i don't think so, at least not that i could easily find. |
||
"Workers of type \(ExpectedWorkerType.self) not equivalent. Expected: \(expectedWorker). Got: \(workflow.worker)", | ||
file: file, | ||
filePath: file, | ||
line: line | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Testing | ||
import Workflow | ||
import XCTest | ||
|
||
@testable import WorkflowTesting | ||
|
||
struct SwiftTestingCompatibilityTests { | ||
@Test | ||
func testInternalFailureRecordsExpectationFailure_swiftTesting() { | ||
withKnownIssue { | ||
TestAction | ||
.tester(withState: false) | ||
.send(action: .change(true)) | ||
.assertNoOutput() // should fail the test | ||
} | ||
} | ||
} | ||
|
||
final class XCTestCompatibilityTests: XCTestCase { | ||
func testInternalFailureRecordsExpectationFailure_xctest() { | ||
XCTExpectFailure { | ||
_ = TestAction | ||
.tester(withState: false) | ||
.send(action: .change(true)) | ||
.assertNoOutput() // should fail the test | ||
} | ||
} | ||
} | ||
|
||
private enum TestAction: WorkflowAction { | ||
typealias WorkflowType = TestWorkflow | ||
|
||
case change(Bool) | ||
|
||
func apply(toState state: inout Bool) -> TestWorkflow.Output? { | ||
if case .change(let newState) = self { | ||
state = newState | ||
} | ||
return 42 | ||
} | ||
} | ||
|
||
private struct TestWorkflow: Workflow { | ||
typealias Rendering = Void | ||
typealias Output = Int | ||
|
||
func makeInitialState() -> Bool { true } | ||
func render(state: Bool, context: RenderContext<TestWorkflow>) {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my education: where is this lib coming from? Apple side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a pointfree library – it's a dependency of the CustomDump lib that we already use: https://github.com/pointfreeco/swift-issue-reporting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though now that you bring it up... i wonder if it should be listed as an explicit dependency in the package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup and i see where the magic is coming from: https://github.com/pointfreeco/swift-issue-reporting/blob/main/Sources/IssueReporting/ReportIssue.swift#L71