Skip to content

Commit

Permalink
Update CwlPreconditionTesting to 2.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed Sep 14, 2019
1 parent 0e51b22 commit fc3cd1a
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 166 deletions.
3 changes: 2 additions & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "mattgallagher/CwlPreconditionTesting" == 1.2.0
github "mattgallagher/CwlCatchException" == 2.0.0-beta.1
github "mattgallagher/CwlPreconditionTesting" == 2.0.0-beta.1
3 changes: 2 additions & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "mattgallagher/CwlPreconditionTesting" "1.2.0"
github "mattgallagher/CwlCatchException" "2.0.0-beta.1"
github "mattgallagher/CwlPreconditionTesting" "2.0.0-beta.1"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.0
import PackageDescription

let package = Package(
Expand Down
18 changes: 18 additions & 0 deletions Carthage/Checkouts/CwlCatchException/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CwlCatchException
A simple Swift wrapper around an Objective-C `@try`/`@catch` statement that selectively catches Objective-C exceptions by `NSException` subtype, rethrowing if any caught exception is not the expected subtype.

Look at [CwlCatchExceptionTests.swift](https://github.com/mattgallagher/CwlCatchException/blob/master/Tests/CwlCatchExceptionTests/CwlCatchExceptionTests.swift) for syntax.

## Requirements

From version 2.0.0-beta.1, building CwlCatchException requires Swift 5 or newer and the Swift Package Manager.

For use with older versions of Swift or other package managers, [use version 1.2.0 or older](https://github.com/mattgallagher/CwlCatchException/tree/1.2.0).

## Adding to your project

Add the following to the `dependencies` array in your "Package.swift" file:

.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version("2.0.0-beta.1"))

Or by adding `https://github.com/mattgallagher/CwlCatchException.git`, version 2.0.0-beta.1 or later, to the list of Swift packages for any project in Xcode.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@

#import <Foundation/Foundation.h>

//! Project version number for CwlCatchException.
FOUNDATION_EXPORT double CwlCatchExceptionVersionNumber;

//! Project version string for CwlCatchException.
FOUNDATION_EXPORT const unsigned char CwlCatchExceptionVersionString[];

NSException* __nullable catchExceptionOfKind(Class __nonnull type, void (^ __nonnull inBlock)(void));

This file was deleted.

17 changes: 8 additions & 9 deletions Carthage/Checkouts/CwlPreconditionTesting/Package.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// swift-tools-version:4.0
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "CwlPreconditionTesting",
products: [
.library(name: "CwlPreconditionTesting", targets: ["CwlPreconditionTesting", "CwlMachBadInstructionHandler"])
.library(name: "CwlPreconditionTesting", targets: ["CwlPreconditionTesting", "CwlMachBadInstructionHandler"]),
.library(name: "CwlPosixPreconditionTesting", targets: ["CwlPosixPreconditionTesting"])
],
dependencies: [
.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: "1.2.0")
.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version(2, 0, 0, prereleaseIdentifiers: ["-beta.1"]))
],
targets: [
.target(
name: "CwlPreconditionTesting",
dependencies: [
.target(name: "CwlMachBadInstructionHandler"),
.product(name: "CwlCatchException")
],
exclude: [
"./Mach/CwlPreconditionTesting.h",
"./Posix/CwlPreconditionTesting.h",
"./CwlCatchBadInstructionPosix.swift"
]
),
.target(
name: "CwlPosixPreconditionTesting"
),
.target(name: "CwlMachBadInstructionHandler"),
.testTarget(name: "CwlPreconditionTestingTests", dependencies: ["CwlPreconditionTesting"])
.testTarget(name: "CwlPreconditionTestingTests", dependencies: ["CwlPreconditionTesting", "CwlPosixPreconditionTesting"])
]
)
58 changes: 23 additions & 35 deletions Carthage/Checkouts/CwlPreconditionTesting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,40 @@ For an extended discussion of this code, please see the Cocoa with Love article:

[Partial functions in Swift, Part 2: Catching precondition failures](http://cocoawithlove.com/blog/2016/02/02/partial-functions-part-two-catching-precondition-failures.html)

## Adding to your project

This project can be used by manual inclusion in your projects or through any of the Swift Package Manager, CocoaPods or Carthage.

Minimum requirements are iOS 8 (simulator-only) or macOS 10.9. The project includes tvOS 9 and POSIX targets but these aren't regularly tested.

### Manual inclusion

1. In a subdirectory of your project's directory, run `git clone https://github.com/mattgallagher/CwlPreconditionTesting.git`
2. Drag the "CwlPreconditionTesting.xcodeproj" file from the Finder into your own project's file tree in Xcode
3. Add the "CwlPreconditionTesting.framework" from the "Products" folder of the CwlPreconditionTesting project's file tree to the "Copy Files (Frameworks)" build phases of any targets that you want to include this module.
4. Drag the "CwlCatchException.framework" from the "Dependencies" group (within the CwlPreconditionTesting project's file tree) onto the same "Copy Files (Frameworks)" build phase
## Requirements

### Swift Package Manager
From version 2.0.0-beta.1, building CwlPreconditionTesting requires Swift 5 or newer and the Swift Package Manager.

Assuming you're using the `swift-tools-version:4.0` package manager, add the following to the `dependencies` array in your "Package.swift" file:
For use with older versions of Swift or other package managers, [use version 1.2.0 or older](https://github.com/mattgallagher/CwlPreconditionTesting/tree/1.2.0).

.package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", majorVersion: 1)

> NOTE: even though this git repository includes its dependencies in the Dependencies folder, building via the Swift Package manager fetches and builds these dependencies independently.
### CocoaPods

Add the following lines to your target in your "Podfile":
## Adding to your project

pod 'CwlPreconditionTesting', :git => 'https://github.com/mattgallagher/CwlPreconditionTesting.git'
pod 'CwlCatchException', :git => 'https://github.com/mattgallagher/CwlCatchException.git'
Add the following to the `dependencies` array in your "Package.swift" file:

### Carthage
.package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", from: Version("2.0.0-beta.1"))

Add the following line to your Cartfile:
Or by adding `https://github.com/mattgallagher/CwlPreconditionTesting.git`, version 2.0.0-beta.1 or later, to the list of Swift packages for any project in Xcode.

git "https://github.com/mattgallagher/CwlPreconditionTesting.git" "master"
## Usage

## Using POSIX signals and setjmp/longjmp
On macOS and iOS you can use the regular version:

For comparison or for anyone running this code on a platform without Mach exceptions or the Objective-C runtime, I've added a proof-of-concept implementation of `catchBadInstruction` that uses a POSIX SIGILL `sigaction` and `setjmp`/`longjmp` to perform the throw.
```swift
import CwlPreconditionTesting

In Xcode, you can simply select the CwlPreconditionTesting_POSIX target (instead of the OSX or iOS targets). If you're building without Xcode: all you need is the CwlCatchBadInstructionPOSIX.swift file (compared to the Mach exception handler, the code is tiny doesn't have any weird Objective-C/MiG file dependencies).
let e = catchBadInstruction {
precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED")
}
```

**Warning No. 1**: on OS X, this approach can't be used when lldb is attached since lldb's Mach exception handler blocks the SIGILL from ever occurring (I've disabled the "Debug Executable" setting for the tests in Xcode - re-enable it to witness the problem).
on tvOS, Linux and other platforms, you can use the POSIX version:

**Warning No. 2**: if you're switching between the CwlPreconditionTesting_OSX and CwlPreconditionTesting_POSIX targets, Xcode (as of Xcode 7.2.1) will not detect the change and will not remove the old framework correctly so you'll need to *clean your project* otherwise the old framework will hang around.
```swift
import CwlPosixPreconditionTesting

Additional problems in decreasing severity include:
let e = catchBadInstruction {
precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED")
}
```

* the signal handler is whole process (rather than correctly scoped to the thread where the "catch" occurs)
* the signal handler doesn't deal with re-entrancy whereas the mach exception handler remains deterministic in the face of multiple fatal errors
* the signal handler overwrites the "[red zone](https://en.wikipedia.org/wiki/Red_zone_(computing))" which is technically frowned upon in signal handlers (although unlikely to cause problems here)
**Warning**: this POSIX version can't be used when lldb is attached since lldb's Mach exception handler blocks the SIGILL from ever occurring. You should disable the "Debug Executable" setting for the tests in Xcode. The POSIX version of the signal handler is also whole process (rather than correctly scoped to the thread where the "catch" occurs).
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//

#if os(tvOS) && targetEnvironment(simulator)
#if arch(x86_64)

import Foundation

Expand Down

This file was deleted.

13 changes: 6 additions & 7 deletions Nimble.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ Pod::Spec.new do |s|

s.source_files = [
"Sources/**/*.{swift,h,m,c}",
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/**/*.{swift,h,m,c}",
"Carthage/Checkouts/CwlCatchException/Sources/**/*.{swift,h,m,c}",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/**/*.{swift,h,m,c}",
]

s.osx.exclude_files = [
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstructionPosix.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPosixPreconditionTesting/CwlCatchBadInstructionPosix.swift",
]
s.ios.exclude_files = [
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstructionPosix.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPosixPreconditionTesting/CwlCatchBadInstructionPosix.swift",
]
s.tvos.exclude_files = [
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/Mach/CwlPreconditionTesting.h",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstruction.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift",
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchExceptionSupport/CwlCatchException.m",
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchExceptionSupport/include/CwlCatchException.h",
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift",
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchExceptionSupport/CwlCatchException.m",
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchExceptionSupport/include/CwlCatchException.h",
]

s.exclude_files = "Sources/Nimble/Adapters/NonObjectiveC/*.swift"
Expand Down
Loading

0 comments on commit fc3cd1a

Please sign in to comment.