diff --git a/Sources/MockSwift/Assertions/XCTestFailureRecorder.swift b/Sources/MockSwift/Assertions/TestingFailureRecorder.swift similarity index 59% rename from Sources/MockSwift/Assertions/XCTestFailureRecorder.swift rename to Sources/MockSwift/Assertions/TestingFailureRecorder.swift index 8e23462..2407007 100644 --- a/Sources/MockSwift/Assertions/XCTestFailureRecorder.swift +++ b/Sources/MockSwift/Assertions/TestingFailureRecorder.swift @@ -23,6 +23,8 @@ SOFTWARE. */ +#if canImport(XCTest) + import XCTest class XCTestFailureRecorder: FailureRecorder { @@ -30,3 +32,34 @@ class XCTestFailureRecorder: FailureRecorder { XCTFail(message, file: file, line: line) } } +#endif + +#if canImport(Testing) + +import Testing + +class SwiftTestingFailureRecorder: FailureRecorder { + func recordFailure(message: String, file: StaticString, line: UInt) { + Issue.record( + Comment(rawValue: message), + sourceLocation: Testing.SourceLocation( + fileID: #fileID, // TODO: pass #fileID from then() + filePath: file.withUTF8Buffer { String(decoding: $0, as: UTF8.self) }, + line: Int(line), + column: 1 // TODO: pass #column from then() + ) + ) + } +} +#endif + +class TestingFailureRecorder: FailureRecorder { + func recordFailure(message: String, file: StaticString, line: UInt) { +#if canImport(XCTest) + XCTestFailureRecorder().recordFailure(message: message, file: file, line: line) +#endif +#if canImport(Testing) + SwiftTestingFailureRecorder().recordFailure(message: message, file: file, line: line) +#endif + } +} diff --git a/Sources/MockSwift/Core/Then/Then.swift b/Sources/MockSwift/Core/Then/Then.swift index 411976a..06c3876 100644 --- a/Sources/MockSwift/Core/Then/Then.swift +++ b/Sources/MockSwift/Core/Then/Then.swift @@ -49,7 +49,7 @@ func then(_ value: WrappedType, public func then(_ value: WrappedType, file: StaticString = #file, line: UInt = #line) -> Then { - then(value, errorHandler: ErrorHandler(), failureRecorder: XCTestFailureRecorder(), file: file, line: line) + then(value, errorHandler: ErrorHandler(), failureRecorder: TestingFailureRecorder(), file: file, line: line) } /// Call `completion` with a `Then` based on `value`. diff --git a/Tests/MockSwiftIntegrationTests/IntegrationTests/Helpers/DummyProtocol.swift b/Tests/MockSwiftIntegrationTests/IntegrationTests/Helpers/DummyProtocol.swift index 0f9ffb6..8660dc5 100644 --- a/Tests/MockSwiftIntegrationTests/IntegrationTests/Helpers/DummyProtocol.swift +++ b/Tests/MockSwiftIntegrationTests/IntegrationTests/Helpers/DummyProtocol.swift @@ -71,7 +71,7 @@ extension Given where WrappedType == DummyProtocol { mockable(first, second) } - subscript(first: Predicate, second: Predicate) -> MockableSubscript.Readable { + subscript(first: MockSwift.Predicate, second: MockSwift.Predicate) -> MockableSubscript.Readable { mockable(first, second) } @@ -79,15 +79,15 @@ extension Given where WrappedType == DummyProtocol { mockable(first, second) } - subscript(x first: Predicate, y second: Predicate) -> MockableSubscript.Writable { + subscript(x first: MockSwift.Predicate, y second: MockSwift.Predicate) -> MockableSubscript.Writable { mockable(first, second) } func function(identifier: String) -> Mockable { mockable(identifier) } - func function(identifier: Predicate) -> Mockable { mockable(identifier) } + func function(identifier: MockSwift.Predicate) -> Mockable { mockable(identifier) } func function(identifier: String) -> Mockable { mockable(identifier) } - func function(identifier: Predicate) -> Mockable { mockable(identifier) } + func function(identifier: MockSwift.Predicate) -> Mockable { mockable(identifier) } } extension Then where WrappedType == DummyProtocol { @@ -99,7 +99,7 @@ extension Then where WrappedType == DummyProtocol { verifiable(first, second) } - subscript(first: Predicate, second: Predicate) -> VerifiableSubscript.Readable { + subscript(first: MockSwift.Predicate, second: MockSwift.Predicate) -> VerifiableSubscript.Readable { verifiable(first, second) } @@ -107,13 +107,13 @@ extension Then where WrappedType == DummyProtocol { verifiable(first, second) } - subscript(x first: Predicate, y second: Predicate) -> VerifiableSubscript.Writable { + subscript(x first: MockSwift.Predicate, y second: MockSwift.Predicate) -> VerifiableSubscript.Writable { verifiable(first, second) } func function(identifier: String) -> Verifiable { verifiable(identifier) } - func function(identifier: Predicate) -> Verifiable { verifiable(identifier) } + func function(identifier: MockSwift.Predicate) -> Verifiable { verifiable(identifier) } func function(identifier: String) -> Verifiable { verifiable(identifier) } - func function(identifier: Predicate) -> Verifiable { verifiable(identifier) } + func function(identifier: MockSwift.Predicate) -> Verifiable { verifiable(identifier) } } diff --git a/Tests/MockSwiftTests/Predicates/PredicateBoolTests.swift b/Tests/MockSwiftTests/Predicates/PredicateBoolTests.swift index 1572912..0eef7aa 100644 --- a/Tests/MockSwiftTests/Predicates/PredicateBoolTests.swift +++ b/Tests/MockSwiftTests/Predicates/PredicateBoolTests.swift @@ -29,32 +29,32 @@ import XCTest class PredicatBoolTests: XCTestCase { func test_isTrue_shouldReturnTrue() { - let predicate: Predicate = .isTrue() + let predicate: MockSwift.Predicate = .isTrue() XCTAssertTrue(predicate.satisfy(by: true)) } func test_isTrue_shouldReturnFalse() { - let predicate: Predicate = .isTrue() + let predicate: MockSwift.Predicate = .isTrue() XCTAssertFalse(predicate.satisfy(by: false)) } func test_isTrue_description() { - let predicate: Predicate = .isTrue() + let predicate: MockSwift.Predicate = .isTrue() XCTAssertEqual(predicate.description, "True") } func test_isFalse_shouldReturnTrue() { - let predicate: Predicate = .isFalse() + let predicate: MockSwift.Predicate = .isFalse() XCTAssertTrue(predicate.satisfy(by: false)) } func test_isFalse_shouldReturnFalse() { - let predicate: Predicate = .isFalse() + let predicate: MockSwift.Predicate = .isFalse() XCTAssertFalse(predicate.satisfy(by: true)) } func test_isFalse_description() { - let predicate: Predicate = .isFalse() + let predicate: MockSwift.Predicate = .isFalse() XCTAssertEqual(predicate.description, "False") } } diff --git a/Tests/MockSwiftTests/Predicates/PredicateOptionalTests.swift b/Tests/MockSwiftTests/Predicates/PredicateOptionalTests.swift index 394c24b..5ebcf4a 100644 --- a/Tests/MockSwiftTests/Predicates/PredicateOptionalTests.swift +++ b/Tests/MockSwiftTests/Predicates/PredicateOptionalTests.swift @@ -29,17 +29,17 @@ import XCTest class PredicateOptionalTests: XCTestCase { func test_isNil_shouldReturnTrue() { - let predicate: Predicate = .isNil() + let predicate: MockSwift.Predicate = .isNil() XCTAssertTrue(predicate.satisfy(by: nil)) } func test_isNil_shouldReturnFalse() { - let predicate: Predicate = .isNil() + let predicate: MockSwift.Predicate = .isNil() XCTAssertFalse(predicate.satisfy(by: 0)) } func test_isNil_description() { - let predicate: Predicate = .isNil() + let predicate: MockSwift.Predicate = .isNil() XCTAssertEqual(predicate.description, "nil") } } diff --git a/Tests/MockSwiftTests/Predicates/PredicateTests.swift b/Tests/MockSwiftTests/Predicates/PredicateTests.swift index a8f358d..af0d5d2 100644 --- a/Tests/MockSwiftTests/Predicates/PredicateTests.swift +++ b/Tests/MockSwiftTests/Predicates/PredicateTests.swift @@ -32,7 +32,7 @@ class PredicateTests: XCTestCase { // MARK: - match(description:any type:_ predicate:) func test_match_withMatchShouldReturnFalseIfInputIsNotTheSameType() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertFalse(predicate.satisfy(by: 1)) } @@ -40,7 +40,7 @@ class PredicateTests: XCTestCase { } func test_match_shouldReturnFalseIfInputNotMatched() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertFalse(predicate.satisfy(by: "not Empty")) } @@ -48,7 +48,7 @@ class PredicateTests: XCTestCase { } func test_match_shouldReturnTrueIfInputMatched() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertTrue(predicate.satisfy(by: "")) } @@ -56,7 +56,7 @@ class PredicateTests: XCTestCase { } func test_match_description() { - let predicate: Predicate = .match { _ in + let predicate: MockSwift.Predicate = .match { _ in true } XCTAssertEqual("\(predicate)", "a String") @@ -65,7 +65,7 @@ class PredicateTests: XCTestCase { // MARK: - match(_ value:file:line:) func test_match_shouldReturnTrueIfInputMatchedByAnyPredicate() { - let anyPredicate: AnyPredicate = Predicate.match { value in + let anyPredicate: AnyPredicate = MockSwift.Predicate.match { value in value.isEmpty } let predicate: AnyPredicate = Predicate.match(anyPredicate) @@ -99,7 +99,7 @@ class PredicateTests: XCTestCase { // MARK: - match(description:any type:when keyPath:) func test_match_shouldReturnTrueIfKeyPathReturnTrue() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertTrue(predicate.satisfy(by: "")) } @@ -107,7 +107,7 @@ class PredicateTests: XCTestCase { } func test_match_shouldReturnFalseIfKeyPathReturnFalse() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertFalse(predicate.satisfy(by: "not Empty")) } @@ -115,7 +115,7 @@ class PredicateTests: XCTestCase { } func test_match_KeyPathDescription() { - let predicate: Predicate = .match(\.isEmpty) + let predicate: MockSwift.Predicate = .match(\.isEmpty) XCTAssertEqual("\(predicate)", "a String") } @@ -123,7 +123,7 @@ class PredicateTests: XCTestCase { // MARK: - any(_ type:) func test_any_shouldReturnFalse() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertFalse(predicate.satisfy(by: 1)) } @@ -131,7 +131,7 @@ class PredicateTests: XCTestCase { } func test_any_shouldReturnTrue() { - func assertion(_ predicate: Predicate) { + func assertion(_ predicate: MockSwift.Predicate) { XCTAssertTrue(predicate.satisfy(by: "")) } @@ -139,23 +139,23 @@ class PredicateTests: XCTestCase { } func test_any_description() { - let predicate: Predicate = .any() + let predicate: MockSwift.Predicate = .any() XCTAssertEqual("\(predicate)", "any String") } func test_not_shouldReturnFalse() { - let predicate: Predicate = .not(.match { _ in true }) + let predicate: MockSwift.Predicate = .not(.match { _ in true }) XCTAssertFalse(predicate.satisfy(by: "")) } func test_not_shouldReturnTrue() { - let predicate: Predicate = .not(.match { _ in false }) + let predicate: MockSwift.Predicate = .not(.match { _ in false }) XCTAssertTrue(predicate.satisfy(by: "")) } func test_not_description() { - let predicate: Predicate = .not(.match(description: "description") { _ in true }) + let predicate: MockSwift.Predicate = .not(.match(description: "description") { _ in true }) XCTAssertEqual("\(predicate)", "not description") } }