Skip to content

Commit

Permalink
Support for release builds (#60)
Browse files Browse the repository at this point in the history
* Support release builds

* wip

* wip
  • Loading branch information
stephencelis authored Jan 23, 2024
1 parent 2b3f81c commit b58e662
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 260 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
name: MacOS
runs-on: macOS-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run tests
run: make test

ubuntu:
name: Ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run tests
run: make test-linux

Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
with:
branch: swift-5.8.1-release
tag: 5.8.1-RELEASE
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: swift build -c ${{ matrix.config }}
- name: Run tests (debug only)
Expand All @@ -67,3 +67,19 @@ jobs:
# that is generally available.
if: ${{ matrix.config == 'debug' }}
run: swift test

static-stdlib:
name: Static standard library
strategy:
matrix:
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: '5.8.0'
- name: Install dependencies
run: sudo apt-get install -y libcurl4-openssl-dev
- uses: actions/checkout@v4
- name: Build for static-stdlib
run: make build-for-static-stdlib
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ test-debug:
test: test-debug
@swift test -c release

test-linux: test-debug

test-linux: test

test-linux-docker:
Expand All @@ -36,6 +38,10 @@ test-linux-static-stdlib:
swift:5.6.2-focal \
bash -c "swift build -c release -Xswiftc -static-stdlib"

build-for-static-stdlib:
@swift build -c debug --static-swift-stdlib
@swift build -c release --static-swift-stdlib

format:
@swift format \
--ignore-unparsable-files \
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ import XCTestDynamicOverlay // ✅

…and your application or library will continue to compile just fine.

> ⚠️ Important: The dynamically loaded `XCTFail` is only available in `DEBUG` builds in order
to prevent App Store rejections due to runtime loading of symbols.


## Example

Expand Down
42 changes: 18 additions & 24 deletions Sources/XCTestDynamicOverlay/Internal/XCTCurrentTestCase.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
#if DEBUG
#if canImport(ObjectiveC)
import Foundation
#if canImport(ObjectiveC)
import Foundation

@_spi(CurrentTestCase) public var XCTCurrentTestCase: AnyObject? {
guard
let XCTestObservationCenter = NSClassFromString("XCTestObservationCenter"),
let XCTestObservationCenter = XCTestObservationCenter as Any as? NSObjectProtocol,
let shared = XCTestObservationCenter.perform(Selector(("sharedTestObservationCenter")))?
.takeUnretainedValue(),
let observers = shared.perform(Selector(("observers")))?
.takeUnretainedValue() as? [AnyObject],
let observer =
observers
.first(where: { NSStringFromClass(type(of: $0)) == "XCTestMisuseObserver" }),
let currentTestCase = observer.perform(Selector(("currentTestCase")))?
.takeUnretainedValue()
else { return nil }
return currentTestCase
}
#else
@_spi(CurrentTestCase) public var XCTCurrentTestCase: AnyObject? {
nil
}
#endif
@_spi(CurrentTestCase) public var XCTCurrentTestCase: AnyObject? {
guard
let XCTestObservationCenter = NSClassFromString("XCTestObservationCenter"),
let XCTestObservationCenter = XCTestObservationCenter as Any as? NSObjectProtocol,
let shared = XCTestObservationCenter.perform(Selector(("sharedTestObservationCenter")))?
.takeUnretainedValue(),
let observers = shared.perform(Selector(("observers")))?
.takeUnretainedValue() as? [AnyObject],
let observer =
observers
.first(where: { NSStringFromClass(type(of: $0)) == "XCTestMisuseObserver" }),
let currentTestCase = observer.perform(Selector(("currentTestCase")))?
.takeUnretainedValue()
else { return nil }
return currentTestCase
}
#else
@_spi(CurrentTestCase) public var XCTCurrentTestCase: AnyObject? {
nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTestDynamicOverlay/XCTExpectFailure.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

#if DEBUG && canImport(ObjectiveC)
#if canImport(ObjectiveC)
/// Instructs the test to expect a failure in an upcoming assertion, with options to customize
/// expected failure checking and handling.
///
Expand Down
Loading

0 comments on commit b58e662

Please sign in to comment.