Skip to content

Commit b35ec72

Browse files
authored
Merge pull request #681 from Quick/update-cwlpreconditiontesting
Update CwlPreconditionTesting to 2.0.0-beta.1
2 parents 0e51b22 + fc3cd1a commit b35ec72

File tree

19 files changed

+84
-166
lines changed

19 files changed

+84
-166
lines changed

Cartfile.private

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github "mattgallagher/CwlPreconditionTesting" == 1.2.0
1+
github "mattgallagher/CwlCatchException" == 2.0.0-beta.1
2+
github "mattgallagher/CwlPreconditionTesting" == 2.0.0-beta.1

Cartfile.resolved

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github "mattgallagher/CwlPreconditionTesting" "1.2.0"
1+
github "mattgallagher/CwlCatchException" "2.0.0-beta.1"
2+
github "mattgallagher/CwlPreconditionTesting" "2.0.0-beta.1"
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22
import PackageDescription
33

44
let package = Package(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# CwlCatchException
2+
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.
3+
4+
Look at [CwlCatchExceptionTests.swift](https://github.com/mattgallagher/CwlCatchException/blob/master/Tests/CwlCatchExceptionTests/CwlCatchExceptionTests.swift) for syntax.
5+
6+
## Requirements
7+
8+
From version 2.0.0-beta.1, building CwlCatchException requires Swift 5 or newer and the Swift Package Manager.
9+
10+
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).
11+
12+
## Adding to your project
13+
14+
Add the following to the `dependencies` array in your "Package.swift" file:
15+
16+
.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version("2.0.0-beta.1"))
17+
18+
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 numberDiff line numberDiff line change
@@ -20,10 +20,4 @@
2020

2121
#import <Foundation/Foundation.h>
2222

23-
//! Project version number for CwlCatchException.
24-
FOUNDATION_EXPORT double CwlCatchExceptionVersionNumber;
25-
26-
//! Project version string for CwlCatchException.
27-
FOUNDATION_EXPORT const unsigned char CwlCatchExceptionVersionString[];
28-
2923
NSException* __nullable catchExceptionOfKind(Class __nonnull type, void (^ __nonnull inBlock)(void));

Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/README.md

-46
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
// swift-tools-version:4.0
1+
// swift-tools-version:5.0
22
import PackageDescription
33

44
let package = Package(
55
name: "CwlPreconditionTesting",
66
products: [
7-
.library(name: "CwlPreconditionTesting", targets: ["CwlPreconditionTesting", "CwlMachBadInstructionHandler"])
7+
.library(name: "CwlPreconditionTesting", targets: ["CwlPreconditionTesting", "CwlMachBadInstructionHandler"]),
8+
.library(name: "CwlPosixPreconditionTesting", targets: ["CwlPosixPreconditionTesting"])
89
],
910
dependencies: [
10-
.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: "1.2.0")
11+
.package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version(2, 0, 0, prereleaseIdentifiers: ["-beta.1"]))
1112
],
1213
targets: [
1314
.target(
1415
name: "CwlPreconditionTesting",
1516
dependencies: [
1617
.target(name: "CwlMachBadInstructionHandler"),
1718
.product(name: "CwlCatchException")
18-
],
19-
exclude: [
20-
"./Mach/CwlPreconditionTesting.h",
21-
"./Posix/CwlPreconditionTesting.h",
22-
"./CwlCatchBadInstructionPosix.swift"
2319
]
2420
),
21+
.target(
22+
name: "CwlPosixPreconditionTesting"
23+
),
2524
.target(name: "CwlMachBadInstructionHandler"),
26-
.testTarget(name: "CwlPreconditionTestingTests", dependencies: ["CwlPreconditionTesting"])
25+
.testTarget(name: "CwlPreconditionTestingTests", dependencies: ["CwlPreconditionTesting", "CwlPosixPreconditionTesting"])
2726
]
2827
)

Carthage/Checkouts/CwlPreconditionTesting/README.md

+23-35
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,40 @@ For an extended discussion of this code, please see the Cocoa with Love article:
88

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

11-
## Adding to your project
12-
13-
This project can be used by manual inclusion in your projects or through any of the Swift Package Manager, CocoaPods or Carthage.
14-
15-
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.
16-
17-
### Manual inclusion
18-
19-
1. In a subdirectory of your project's directory, run `git clone https://github.com/mattgallagher/CwlPreconditionTesting.git`
20-
2. Drag the "CwlPreconditionTesting.xcodeproj" file from the Finder into your own project's file tree in Xcode
21-
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.
22-
4. Drag the "CwlCatchException.framework" from the "Dependencies" group (within the CwlPreconditionTesting project's file tree) onto the same "Copy Files (Frameworks)" build phase
11+
## Requirements
2312

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

26-
Assuming you're using the `swift-tools-version:4.0` package manager, add the following to the `dependencies` array in your "Package.swift" file:
15+
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).
2716

28-
.package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", majorVersion: 1)
29-
30-
> 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.
31-
32-
### CocoaPods
33-
34-
Add the following lines to your target in your "Podfile":
17+
## Adding to your project
3518

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

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

41-
Add the following line to your Cartfile:
23+
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.
4224

43-
git "https://github.com/mattgallagher/CwlPreconditionTesting.git" "master"
25+
## Usage
4426

45-
## Using POSIX signals and setjmp/longjmp
27+
On macOS and iOS you can use the regular version:
4628

47-
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.
29+
```swift
30+
import CwlPreconditionTesting
4831

49-
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).
32+
let e = catchBadInstruction {
33+
precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED")
34+
}
35+
```
5036

51-
**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).
37+
on tvOS, Linux and other platforms, you can use the POSIX version:
5238

53-
**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.
39+
```swift
40+
import CwlPosixPreconditionTesting
5441

55-
Additional problems in decreasing severity include:
42+
let e = catchBadInstruction {
43+
precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED")
44+
}
45+
```
5646

57-
* the signal handler is whole process (rather than correctly scoped to the thread where the "catch" occurs)
58-
* the signal handler doesn't deal with re-entrancy whereas the mach exception handler remains deterministic in the face of multiple fatal errors
59-
* 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)
47+
**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).

Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstructionPosix.swift Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPosixPreconditionTesting/CwlCatchBadInstructionPosix.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1919
//
2020

21-
#if os(tvOS) && targetEnvironment(simulator)
21+
#if arch(x86_64)
2222

2323
import Foundation
2424

Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/include/CwlPreconditionTesting.h

-35
This file was deleted.

Nimble.podspec

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,23 @@ Pod::Spec.new do |s|
1616

1717
s.source_files = [
1818
"Sources/**/*.{swift,h,m,c}",
19-
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/**/*.{swift,h,m,c}",
19+
"Carthage/Checkouts/CwlCatchException/Sources/**/*.{swift,h,m,c}",
2020
"Carthage/Checkouts/CwlPreconditionTesting/Sources/**/*.{swift,h,m,c}",
2121
]
2222

2323
s.osx.exclude_files = [
24-
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstructionPosix.swift",
24+
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPosixPreconditionTesting/CwlCatchBadInstructionPosix.swift",
2525
]
2626
s.ios.exclude_files = [
27-
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstructionPosix.swift",
27+
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPosixPreconditionTesting/CwlCatchBadInstructionPosix.swift",
2828
]
2929
s.tvos.exclude_files = [
30-
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/Mach/CwlPreconditionTesting.h",
3130
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlCatchBadInstruction.swift",
3231
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlBadInstructionException.swift",
3332
"Carthage/Checkouts/CwlPreconditionTesting/Sources/CwlPreconditionTesting/CwlDarwinDefinitions.swift",
34-
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift",
35-
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchExceptionSupport/CwlCatchException.m",
36-
"Carthage/Checkouts/CwlPreconditionTesting/Dependencies/CwlCatchException/Sources/CwlCatchExceptionSupport/include/CwlCatchException.h",
33+
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchException/CwlCatchException.swift",
34+
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchExceptionSupport/CwlCatchException.m",
35+
"Carthage/Checkouts/CwlCatchException/Sources/CwlCatchExceptionSupport/include/CwlCatchException.h",
3736
]
3837

3938
s.exclude_files = "Sources/Nimble/Adapters/NonObjectiveC/*.swift"

0 commit comments

Comments
 (0)