mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SDK] Use an extra shim header to remove _silgen_name from XCTest.
This commit is contained in:
@@ -13,16 +13,14 @@
|
|||||||
@_exported import XCTest // Clang module
|
@_exported import XCTest // Clang module
|
||||||
|
|
||||||
import CoreGraphics
|
import CoreGraphics
|
||||||
|
import _SwiftXCTestOverlayShims
|
||||||
/// Returns the current test case, so we can use free functions instead of methods for the overlay.
|
|
||||||
@_silgen_name("_XCTCurrentTestCaseBridge") func _XCTCurrentTestCaseBridge() -> XCTestCase
|
|
||||||
|
|
||||||
// --- Failure Formatting ---
|
// --- Failure Formatting ---
|
||||||
|
|
||||||
/// Register the failure, expected or unexpected, of the current test case.
|
/// Register the failure, expected or unexpected, of the current test case.
|
||||||
func _XCTRegisterFailure(_ expected: Bool, _ condition: String, _ message: @autoclosure () -> String, _ file: StaticString, _ line: UInt) -> Void {
|
func _XCTRegisterFailure(_ expected: Bool, _ condition: String, _ message: @autoclosure () -> String, _ file: StaticString, _ line: UInt) -> Void {
|
||||||
// Call the real _XCTFailureHandler.
|
// Call the real _XCTFailureHandler.
|
||||||
let test = _XCTCurrentTestCaseBridge()
|
let test = _XCTCurrentTestCase()
|
||||||
_XCTPreformattedFailureHandler(test, expected, file.description, line, condition, message())
|
_XCTPreformattedFailureHandler(test, expected, file.description, line, condition, message())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +41,6 @@ func _XCTFailureDescription(_ assertionType: _XCTAssertionType, _ formatIndex: U
|
|||||||
|
|
||||||
// --- Exception Support ---
|
// --- Exception Support ---
|
||||||
|
|
||||||
@_silgen_name("_XCTRunThrowableBlockBridge")
|
|
||||||
func _XCTRunThrowableBlockBridge(_: @convention(block) () -> Void) -> NSDictionary
|
|
||||||
|
|
||||||
/// The Swift-style result of evaluating a block which may throw an exception.
|
/// The Swift-style result of evaluating a block which may throw an exception.
|
||||||
enum _XCTThrowableBlockResult {
|
enum _XCTThrowableBlockResult {
|
||||||
case success
|
case success
|
||||||
@@ -70,13 +65,13 @@ func _XCTRunThrowableBlock(_ block: () throws -> Void) -> _XCTThrowableBlockResu
|
|||||||
if let blockError = blockErrorOptional {
|
if let blockError = blockErrorOptional {
|
||||||
return .failedWithError(error: blockError)
|
return .failedWithError(error: blockError)
|
||||||
} else if d.count > 0 {
|
} else if d.count > 0 {
|
||||||
let t: String = d["type"] as! String
|
let t: String = d["type"]!
|
||||||
|
|
||||||
if t == "objc" {
|
if t == "objc" {
|
||||||
return .failedWithException(
|
return .failedWithException(
|
||||||
className: d["className"] as! String,
|
className: d["className"]!,
|
||||||
name: d["name"] as! String,
|
name: d["name"]!,
|
||||||
reason: d["reason"] as! String)
|
reason: d["reason"]!)
|
||||||
} else {
|
} else {
|
||||||
return .failedWithUnknownException
|
return .failedWithUnknownException
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,36 +126,15 @@ fail:
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
// Swift's memory management expectations are different than Objective-C; it
|
|
||||||
// expects everything to be +1 rather than +0. So we need to bridge the
|
|
||||||
// _XCTCurrentTestCase function to return a +1 object.
|
|
||||||
|
|
||||||
XCT_EXPORT XCTestCase *_XCTCurrentTestCase(void);
|
|
||||||
|
|
||||||
XCT_EXPORT SWIFT_CC(swift) NS_RETURNS_RETAINED
|
|
||||||
XCTestCase *_XCTCurrentTestCaseBridge(void);
|
|
||||||
|
|
||||||
NS_RETURNS_RETAINED XCTestCase *_XCTCurrentTestCaseBridge(void)
|
|
||||||
{
|
|
||||||
return [_XCTCurrentTestCase() retain];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Since Swift doesn't natively support exceptions, but Objective-C code can
|
// Since Swift doesn't natively support exceptions, but Objective-C code can
|
||||||
// still throw them, use a helper to evaluate a block that may result in an
|
// still throw them, use a helper to evaluate a block that may result in an
|
||||||
// exception being thrown that passes back the most important information about
|
// exception being thrown that passes back the most important information about
|
||||||
// it.
|
// it.
|
||||||
//
|
//
|
||||||
// If no exception is thrown by the block, returns an empty dictionary.
|
// If no exception is thrown by the block, returns an empty dictionary.
|
||||||
//
|
|
||||||
// Note that this function needs Swift calling conventions, hence the use of
|
|
||||||
// NS_RETURNS_RETAINED and Block_release. (The argument should also be marked
|
|
||||||
// NS_RELEASES_ARGUMENT, but clang doesn't realize that a block parameter
|
|
||||||
// should be treated as an Objective-C parameter here.)
|
|
||||||
|
|
||||||
XCT_EXPORT NS_RETURNS_RETAINED NSDictionary *_XCTRunThrowableBlockBridge(void (^block)());
|
XCT_EXPORT NSDictionary *_XCTRunThrowableBlockBridge(void (^block)());
|
||||||
|
|
||||||
SWIFT_CC(swift) NS_RETURNS_RETAINED
|
|
||||||
NSDictionary *_XCTRunThrowableBlockBridge(void (^block)())
|
NSDictionary *_XCTRunThrowableBlockBridge(void (^block)())
|
||||||
{
|
{
|
||||||
NSDictionary *result;
|
NSDictionary *result;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ set(sources
|
|||||||
SwiftStdint.h
|
SwiftStdint.h
|
||||||
UnicodeShims.h
|
UnicodeShims.h
|
||||||
Visibility.h
|
Visibility.h
|
||||||
|
XCTestOverlayShims.h
|
||||||
module.modulemap
|
module.modulemap
|
||||||
)
|
)
|
||||||
set(output_dir "${SWIFTLIB_DIR}/shims")
|
set(output_dir "${SWIFTLIB_DIR}/shims")
|
||||||
|
|||||||
26
stdlib/public/SwiftShims/XCTestOverlayShims.h
Normal file
26
stdlib/public/SwiftShims/XCTestOverlayShims.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//===--- XCTestOverlayShims.h -----------------------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// This source file is part of the Swift.org open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
||||||
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
//
|
||||||
|
// See http://swift.org/LICENSE.txt for license information
|
||||||
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef SWIFT_STDLIB_SHIMS_XCTEST_OVERLAY_H
|
||||||
|
#define SWIFT_STDLIB_SHIMS_XCTEST_OVERLAY_H
|
||||||
|
|
||||||
|
@import Foundation;
|
||||||
|
|
||||||
|
@class XCTestCase;
|
||||||
|
|
||||||
|
XCTestCase * _Nonnull _XCTCurrentTestCase(void);
|
||||||
|
|
||||||
|
NSDictionary<NSString *, NSString *> * _Nonnull
|
||||||
|
_XCTRunThrowableBlockBridge(void (^ _Nonnull NS_NOESCAPE block)());
|
||||||
|
|
||||||
|
#endif // SWIFT_STDLIB_SHIMS_XCTEST_OVERLAY_H
|
||||||
|
|
||||||
@@ -16,3 +16,8 @@ module SwiftShims {
|
|||||||
header "Visibility.h"
|
header "Visibility.h"
|
||||||
export *
|
export *
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module _SwiftXCTestOverlayShims {
|
||||||
|
header "XCTestOverlayShims.h"
|
||||||
|
export *
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user