-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide basic integration with Swift Testing
This is not reliable, in fact, failure reporting is flaky.
- Loading branch information
Showing
5 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
#if canImport(Testing) | ||
import Testing | ||
#endif | ||
|
||
public class NimbleSwiftTestingHandler: AssertionHandler { | ||
public func assert(_ assertion: Bool, message: FailureMessage, location: SourceLocation) { | ||
if !assertion { | ||
recordTestingFailure("\(message.stringValue)\n", location: location) | ||
} | ||
} | ||
} | ||
|
||
func isSwiftTestingAvailable() -> Bool { | ||
#if canImport(Testing) | ||
true | ||
#else | ||
false | ||
#endif | ||
} | ||
|
||
func isRunningSwiftTest() -> Bool { | ||
#if canImport(Testing) | ||
Test.current != nil | ||
#else | ||
false | ||
#endif | ||
} | ||
|
||
public func recordTestingFailure(_ message: String, location: SourceLocation) { | ||
#if canImport(Testing) | ||
Issue.record("\(message)", filePath: "\(location.file)", line: Int(location.line), column: 0) | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#if canImport(Testing) | ||
import Nimble | ||
import Testing | ||
import XCTest | ||
|
||
@Suite struct SwiftTestingSupportSuite { | ||
@Test func reportsAssertionFailuresToSwiftTesting() { | ||
withKnownIssue { | ||
fail() | ||
} | ||
} | ||
|
||
@Test func reportsRequireErrorsToSwiftTesting() throws { | ||
withKnownIssue { | ||
try require(false).to(beTrue()) | ||
} | ||
} | ||
} | ||
|
||
class MixedSwiftTestingXCTestSupport: XCTestCase { | ||
func testAlsoRecordsErrorsToXCTest() { | ||
XCTExpectFailure("This should fail") | ||
fail() | ||
|
||
} | ||
|
||
func testAlsoRecordsRequireErrorsToXCTest() throws { | ||
XCTExpectFailure("This should fail") | ||
try require(false).to(beTrue()) | ||
} | ||
} | ||
|
||
#endif |