diff --git a/Package.resolved b/Package.resolved index 88e71b7..ffd45dd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -18,6 +18,15 @@ "version" : "1.0.0" } }, + { + "identity" : "swift-issue-reporting", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-issue-reporting", + "state" : { + "revision" : "926f43898706eaa127db79ac42138e1ad7e85a3f", + "version" : "1.2.0" + } + }, { "identity" : "swift-macro-testing", "kind" : "remoteSourceControl", @@ -44,15 +53,6 @@ "revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c", "version" : "600.0.0-prerelease-2024-06-12" } - }, - { - "identity" : "xctest-dynamic-overlay", - "kind" : "remoteSourceControl", - "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", - "state" : { - "revision" : "6f30bdba373bbd7fbfe241dddd732651f2fbd1e2", - "version" : "1.1.2" - } } ], "version" : 2 diff --git a/Package.swift b/Package.swift index 03b877d..4caabc8 100644 --- a/Package.swift +++ b/Package.swift @@ -19,15 +19,16 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"), + .package(url: "https://github.com/pointfreeco/swift-issue-reporting", from: "1.2.0"), .package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"), - .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"), ], targets: [ .target( name: "CasePaths", dependencies: [ "CasePathsMacros", - .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"), + .product(name: "IssueReporting", package: "swift-issue-reporting"), + .product(name: "XCTestDynamicOverlay", package: "swift-issue-reporting"), ] ), .testTarget( diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 1fb0261..69bcb61 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -19,15 +19,16 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"), + .package(url: "https://github.com/pointfreeco/swift-issue-reporting", from: "1.2.0"), .package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"), - .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"), ], targets: [ .target( name: "CasePaths", dependencies: [ "CasePathsMacros", - .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"), + .product(name: "IssueReporting", package: "swift-issue-reporting"), + .product(name: "XCTestDynamicOverlay", package: "swift-issue-reporting"), ] ), .testTarget( diff --git a/Sources/CasePaths/CasePathable.swift b/Sources/CasePaths/CasePathable.swift index 775308d..7bf7c01 100644 --- a/Sources/CasePaths/CasePathable.swift +++ b/Sources/CasePaths/CasePathable.swift @@ -1,4 +1,4 @@ -import XCTestDynamicOverlay +import IssueReporting /// A type that provides a collection of all of its case paths. /// @@ -479,18 +479,22 @@ extension CasePathable { public mutating func modify( _ keyPath: CaseKeyPath, yield: (inout Value) -> Void, - file: StaticString = #filePath, - line: UInt = #line + fileID: StaticString = #fileID, + filePath: StaticString = #filePath, + line: UInt = #line, + column: UInt = #column ) { let `case` = Case(keyPath) guard var value = `case`.extract(from: self) else { - XCTFail( + reportIssue( """ Can't modify '\(String(describing: self))' via 'CaseKeyPath<\(Self.self), \(Value.self)>' \ (aka '\(String(reflecting: keyPath))') """, - file: file, - line: line + fileID: fileID, + filePath: filePath, + line: line, + column: column ) return } diff --git a/Sources/CasePaths/Internal/Deprecations.swift b/Sources/CasePaths/Internal/Deprecations.swift index e9dd001..feec737 100644 --- a/Sources/CasePaths/Internal/Deprecations.swift +++ b/Sources/CasePaths/Internal/Deprecations.swift @@ -220,7 +220,7 @@ public func XCTUnwrap( let message = message() XCTFail( """ - XCTUnwrap failed: expected to extract value of type "\(typeName(Case.self))" from \ + XCTUnwrap: Expected to extract value of type "\(typeName(Case.self))" from \ "\(typeName(Enum.self))"\ \(message.isEmpty ? "" : " - " + message) … diff --git a/Sources/CasePaths/XCTestSupport.swift b/Sources/CasePaths/XCTestSupport.swift index 3662dd7..2b96db6 100644 --- a/Sources/CasePaths/XCTestSupport.swift +++ b/Sources/CasePaths/XCTestSupport.swift @@ -7,11 +7,12 @@ import Foundation /// - optional: An optional value. /// - message: An optional description of a failure. /// - body: A closure that can modify the wrapped value of the given optional. +@available(*, deprecated, message: "Use 'CasePathable.modify' to mutate an expected case, instead.") public func XCTModify( _ optional: inout Wrapped?, _ message: @autoclosure () -> String = "", _ body: (inout Wrapped) throws -> Void, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { XCTModify(&optional, case: \.some, message(), body, file: file, line: line) @@ -24,12 +25,13 @@ public func XCTModify( /// - casePath: A case path that can extract and embed the associated value of a particular case. /// - message: An optional description of a failure. /// - body: A closure that can modify the associated value of the given case. +@available(*, deprecated, message: "Use 'CasePathable.modify' to mutate an expected case, instead.") public func XCTModify( _ enum: inout Enum, case keyPath: CaseKeyPath, _ message: @autoclosure () -> String = "", _ body: (inout Case) throws -> Void, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { _XCTModify(&`enum`, case: AnyCasePath(keyPath), message(), body, file: file, line: line) @@ -40,7 +42,7 @@ func _XCTModify( case casePath: AnyCasePath, _ message: @autoclosure () -> String = "", _ body: (inout Case) throws -> Void, - file: StaticString = #file, + file: StaticString = #filePath, line: UInt = #line ) { guard var value = casePath.extract(from: `enum`) @@ -51,7 +53,7 @@ func _XCTModify( let message = message() XCTFail( """ - XCTModify failed: expected to extract value of type "\(typeName(Case.self))" from \ + XCTModify: Expected to extract value of type "\(typeName(Case.self))" from \ "\(typeName(Enum.self))"\ \(message.isEmpty ? "" : " - " + message) … @@ -77,7 +79,7 @@ func _XCTModify( { XCTFail( """ - XCTModify failed: expected "\(typeName(Case.self))" value to be modified but it was unchanged. + XCTModify: Expected "\(typeName(Case.self))" value to be modified but it was unchanged. """ ) } diff --git a/Tests/CasePathsTests/DeprecatedXCTModifyTests.swift b/Tests/CasePathsTests/DeprecatedXCTModifyTests.swift index 2a35f39..8d2a384 100644 --- a/Tests/CasePathsTests/DeprecatedXCTModifyTests.swift +++ b/Tests/CasePathsTests/DeprecatedXCTModifyTests.swift @@ -23,7 +23,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from "Result" … + failed - XCTModify: Expected to extract value of type "Int" from "Result" … Actual: failure(CasePathsTests.DeprecatedXCTModifyTests.SomeError()) @@ -41,7 +41,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type \ + failed - XCTModify: Expected to extract value of type \ "DeprecatedXCTModifyTests.Sheet.State" from \ "DeprecatedXCTModifyTests.Destination.State?" … @@ -61,7 +61,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from \ + failed - XCTModify: Expected to extract value of type "Int" from \ "Optional>" … Actual: @@ -80,7 +80,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from "Result" - \ + failed - XCTModify: Expected to extract value of type "Int" from "Result" - \ Should be success … Actual: @@ -119,7 +119,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected "Int" value to be modified but it was unchanged. + failed - XCTModify: Expected "Int" value to be modified but it was unchanged. """ } @@ -135,7 +135,7 @@ XCTExpectFailure { $0.compactDescription == """ - Threw error: SomeError() + failed - Threw error: SomeError() """ } diff --git a/Tests/CasePathsTests/XCTModifyTests.swift b/Tests/CasePathsTests/XCTModifyTests.swift index 55e51ea..a86c6e3 100644 --- a/Tests/CasePathsTests/XCTModifyTests.swift +++ b/Tests/CasePathsTests/XCTModifyTests.swift @@ -23,7 +23,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from "Result" … + failed - XCTModify: Expected to extract value of type "Int" from "Result" … Actual: failure(CasePathsTests.XCTModifyTests.SomeError()) @@ -41,7 +41,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "XCTModifyTests.Sheet.State" from \ + failed - XCTModify: Expected to extract value of type "XCTModifyTests.Sheet.State" from \ "XCTModifyTests.Destination.State?" … Actual: @@ -60,7 +60,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from \ + failed - XCTModify: Expected to extract value of type "Int" from \ "Optional>" … Actual: @@ -79,7 +79,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected to extract value of type "Int" from "Result" - \ + failed - XCTModify: Expected to extract value of type "Int" from "Result" - \ Should be success … Actual: @@ -118,7 +118,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTModify failed: expected "Int" value to be modified but it was unchanged. + failed - XCTModify: Expected "Int" value to be modified but it was unchanged. """ } @@ -134,7 +134,7 @@ XCTExpectFailure { $0.compactDescription == """ - Threw error: SomeError() + failed - Threw error: SomeError() """ } diff --git a/Tests/CasePathsTests/XCTUnwrapTests.swift b/Tests/CasePathsTests/XCTUnwrapTests.swift index 68cc8bf..62db555 100644 --- a/Tests/CasePathsTests/XCTUnwrapTests.swift +++ b/Tests/CasePathsTests/XCTUnwrapTests.swift @@ -9,7 +9,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTUnwrap failed: expected to extract value of type "Error" from "Result" … + failed - XCTUnwrap: Expected to extract value of type "Error" from "Result" … Actual: success(2) @@ -23,7 +23,7 @@ XCTExpectFailure { $0.compactDescription == """ - XCTUnwrap failed: expected to extract value of type "Error" from "Result" - \ + failed - XCTUnwrap: Expected to extract value of type "Error" from "Result" - \ Should be 'failure' … Actual: