Skip to content
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

Task local to opt out of XCTModify exhaustivity. #102

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/CasePaths/XCTUnwrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public func XCTModify<Root, Case>(
return
}

if let isEqual = _isEqual(before, value), isEqual {
if
XCTModifyLocals.isExhaustive,
let isEqual = _isEqual(before, value),
isEqual
{
XCTFail(
"""
XCTModify failed: expected "\(Case.self)" value to be modified but it was unchanged.
Expand All @@ -77,4 +81,8 @@ public func XCTModify<Root, Case>(
root = casePath.embed(value)
}

@_spi(Internals) public enum XCTModifyLocals {
@TaskLocal public static var isExhaustive = true
}

private struct UnwrappingCase: Error {}
13 changes: 12 additions & 1 deletion Tests/CasePathsTests/XCTModifyTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if DEBUG && (os(iOS) || os(macOS) || os(tvOS) || os(watchOS))
import CasePaths
@_spi(Internals) import CasePaths
import XCTest

final class XCTModifyTests: XCTestCase {
Expand Down Expand Up @@ -117,6 +117,17 @@
}
XCTAssertEqual(result, .success(2))
}

func testXCTModifyFailUnchangedEquatable_NonExhaustive() throws {
try XCTSkipIf(ProcessInfo.processInfo.environment["CI"] != nil)

var result = Result<Int, SomeError>.success(2)
XCTModifyLocals.$isExhaustive.withValue(false) {
XCTModify(&result, case: /Result.success) {
_ = $0
}}
XCTAssertEqual(result, .success(2))
}
}

private struct SomeError: Error, Equatable {}
Expand Down