[SDK] Use an extra shim header to remove _silgen_name from XCTest.

This commit is contained in:
Jordan Rose
2016-10-15 09:50:10 -07:00
parent 3778c79dc4
commit 2e560b0319
5 changed files with 39 additions and 33 deletions

View File

@@ -13,16 +13,14 @@
@_exported import XCTest // Clang module
import CoreGraphics
/// Returns the current test case, so we can use free functions instead of methods for the overlay.
@_silgen_name("_XCTCurrentTestCaseBridge") func _XCTCurrentTestCaseBridge() -> XCTestCase
import _SwiftXCTestOverlayShims
// --- Failure Formatting ---
/// 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 {
// Call the real _XCTFailureHandler.
let test = _XCTCurrentTestCaseBridge()
let test = _XCTCurrentTestCase()
_XCTPreformattedFailureHandler(test, expected, file.description, line, condition, message())
}
@@ -43,9 +41,6 @@ func _XCTFailureDescription(_ assertionType: _XCTAssertionType, _ formatIndex: U
// --- Exception Support ---
@_silgen_name("_XCTRunThrowableBlockBridge")
func _XCTRunThrowableBlockBridge(_: @convention(block) () -> Void) -> NSDictionary
/// The Swift-style result of evaluating a block which may throw an exception.
enum _XCTThrowableBlockResult {
case success
@@ -70,13 +65,13 @@ func _XCTRunThrowableBlock(_ block: () throws -> Void) -> _XCTThrowableBlockResu
if let blockError = blockErrorOptional {
return .failedWithError(error: blockError)
} else if d.count > 0 {
let t: String = d["type"] as! String
let t: String = d["type"]!
if t == "objc" {
return .failedWithException(
className: d["className"] as! String,
name: d["name"] as! String,
reason: d["reason"] as! String)
className: d["className"]!,
name: d["name"]!,
reason: d["reason"]!)
} else {
return .failedWithUnknownException
}

View File

@@ -126,36 +126,15 @@ fail:
@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
// 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
// it.
//
// 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 *result;

View File

@@ -14,6 +14,7 @@ set(sources
SwiftStdint.h
UnicodeShims.h
Visibility.h
XCTestOverlayShims.h
module.modulemap
)
set(output_dir "${SWIFTLIB_DIR}/shims")

View 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

View File

@@ -16,3 +16,8 @@ module SwiftShims {
header "Visibility.h"
export *
}
module _SwiftXCTestOverlayShims {
header "XCTestOverlayShims.h"
export *
}