Skip to content

Commit

Permalink
swift-test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
NikSativa committed Sep 26, 2024
1 parent e6d4592 commit 027edee
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 141 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "NikSativa CI"

on:
push:
branches:
- main
paths:
- ".github/workflows/**"
- "Package.swift"
- "Source/**"
- "Tests/**"
pull_request:
paths:
- ".github/workflows/**"
- "Package.swift"
- "Source/**"
- "Tests/**"

concurrency:
group: ${{ github.ref_name }}
cancel-in-progress: true
jobs:
macOS:
name: "macOS ${{ matrix.xcode }} ${{ matrix.swift }}"
runs-on: ${{ matrix.runsOn }}
env:
DEVELOPER_DIR: "/Applications/${{ matrix.xcode }}.app/Contents/Developer"
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
# unsupported yet
# - xcode: "Xcode_16"
# runsOn: firebreak
# swift: "6.0"
# outputFilter: xcbeautify --renderer github-actions
- xcode: "Xcode_15.4"
runsOn: macOS-14
swift: "5.10"
outputFilter: xcbeautify --renderer github-actions
- xcode: "Xcode_15.2"
runsOn: macOS-14
swift: "5.9"
outputFilter: xcbeautify --renderer github-actions
- xcode: "Xcode_14.3"
runsOn: macOS-13
swift: "5.8"
outputFilter: xcbeautify --renderer github-actions
steps:
- uses: NeedleInAJayStack/setup-swift
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: "build ${{ matrix.xcode }} ${{ matrix.swift }}"
run: swift build -v | ${{ matrix.outputFilter }}
- name: "test ${{ matrix.xcode }} ${{ matrix.swift }}"
run: swift test -v | ${{ matrix.outputFilter }}
36 changes: 0 additions & 36 deletions [email protected]

This file was deleted.

36 changes: 0 additions & 36 deletions [email protected]

This file was deleted.

36 changes: 0 additions & 36 deletions [email protected]

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Helpers/Image+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public extension Image {
}

public extension Image.spry {
#if os(macOS) && swift(>=6.0)
#if os(macOS) && swift(>=5.10)
nonisolated(unsafe) static let testImage: Image = .init(systemSymbolName: "circle", accessibilityDescription: nil)!
nonisolated(unsafe) static let testImage1: Image = .init(systemSymbolName: "square", accessibilityDescription: nil)!
nonisolated(unsafe) static let testImage2: Image = .init(systemSymbolName: "diamond", accessibilityDescription: nil)!
Expand Down Expand Up @@ -59,7 +59,7 @@ public extension Image.spry {
color.setFill()
context.fill(rect)
}
#elseif (swift(>=5.9) && os(visionOS))
#elseif(swift(>=5.9) && os(visionOS))
let data = UIGraphicsImageRenderer(bounds: rect).pngData { context in
color.setFill()
context.fill(rect)
Expand Down
6 changes: 4 additions & 2 deletions Source/Matcher/XCTAssertThrowsAssertion.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#if (os(macOS) || os(iOS) || (swift(>=5.9) && os(visionOS))) && (arch(x86_64) || arch(arm64))
import CwlPreconditionTesting
import Foundation
import XCTest
Expand All @@ -8,6 +7,7 @@ public func XCTAssertThrowsAssertion(_ message: @autoclosure () -> String = "",
file: StaticString = #filePath,
line: UInt = #line,
_ expression: @escaping () throws -> some Any) {
#if (os(macOS) || os(iOS) || (swift(>=5.9) && os(visionOS))) && (arch(x86_64) || arch(arm64))
print(" --- ⚠️ ignore this assertion in console! this is a result of XCTAssertThrowsAssertion ⚠️ --- ")
XCTAssertNotNil(catchBadInstruction(in: {
do {
Expand All @@ -16,6 +16,9 @@ public func XCTAssertThrowsAssertion(_ message: @autoclosure () -> String = "",
XCTFail("catch error: " + error.localizedDescription, file: file, line: line)
}
}), message(), file: file, line: line)
#else
print(" --- ⚠️ this is a result of XCTAssertThrowsAssertion. it is not supported on this platform ⚠️ --- ")
#endif
}

@inline(__always)
Expand All @@ -25,4 +28,3 @@ public func XCTAssertThrowsAssertion(_ expression: @autoclosure @escaping () thr
line: UInt = #line) {
XCTAssertThrowsAssertion(message(), file: file, line: line, expression)
}
#endif
2 changes: 1 addition & 1 deletion Source/Spy/SpyableImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
// A global NSMapTable to hold onto calls for types conforming to Spyable. This map table has "weak to strong objects" options.
//
// - Important: Do NOT use this object.
#if swift(>=6.0)
#if swift(>=5.10)
private nonisolated(unsafe) var callsMapTable: NSMapTable<AnyObject, SpryDictionary<RecordedCall>> = NSMapTable.weakToStrongObjects()
#else
private var callsMapTable: NSMapTable<AnyObject, SpryDictionary<RecordedCall>> = NSMapTable.weakToStrongObjects()
Expand Down
2 changes: 1 addition & 1 deletion Source/Stub/StubbableImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
// A global NSMapTable to hold onto stubs for types conforming to Stubbable. This map table has "weak to strong objects" options.
//
// - Important: Do NOT use this object.
#if swift(>=6.0)
#if swift(>=5.10)
private nonisolated(unsafe) var stubsMapTable: NSMapTable<AnyObject, SpryDictionary<StubInfo>> = NSMapTable.weakToStrongObjects()
#else
private var stubsMapTable: NSMapTable<AnyObject, SpryDictionary<StubInfo>> = NSMapTable.weakToStrongObjects()
Expand Down
11 changes: 6 additions & 5 deletions Tests/ArgumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import XCTest

final class ArgumentTests: XCTestCase {
func test_CustomStringConvertible() {
XCTAssertEqual(Argument.anything.description, "Argument.anything")
XCTAssertEqual(Argument.nonNil.description, "Argument.nonNil")
XCTAssertEqual(Argument.nil.description, "Argument.nil")
XCTAssertEqual(Argument.validator { _ in true }.description, "Argument.validator")
XCTAssertEqual(Argument.closure.description, "Argument.closure")
XCTAssertEqual(Argument.anything.description, "Argument.anything", "Argument.anything")
XCTAssertEqual(Argument.nonNil.description, "Argument.nonNil", "Argument.nonNil")
XCTAssertEqual(Argument.nil.description, "Argument.nil", "Argument.nil")
XCTAssertEqual(Argument.validator { _ in true }.description, "Argument.validator", "Argument.validator")
XCTAssertEqual(Argument.closure.description, "Argument.closure", "Argument.closure")
XCTAssertEqual(Argument.skipped.description, "Argument.skipped", "Argument.skipped")
}

func test_is_equal_args_list() {
Expand Down
52 changes: 34 additions & 18 deletions Tests/CrossPlatformTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,43 @@ final class CrossPlatformTests: XCTestCase {
import UIKit

private enum Screen {
@MainActor static var scale: CGFloat {
#if swift(>=5.10)
nonisolated(unsafe) static var scale: CGFloat {
return syncMainThread { UIScreen.main.scale }
}
#else
static var scale: CGFloat {
return UIScreen.main.scale
}
#endif
}

#elseif os(watchOS)
import WatchKit

private enum Screen {
@MainActor static var scale: CGFloat {
#if swift(>=5.10)
nonisolated(unsafe) static var scale: CGFloat {
return WKInterfaceDevice.current().screenScale
}
#else
static var scale: CGFloat {
return WKInterfaceDevice.current().screenScale
}
#endif
}

#elseif (swift(>=5.9) && os(visionOS))
#elseif(swift(>=5.9) && os(visionOS))
public enum Screen {
#if swift(>=5.10)
/// visionOS doesn't have a screen scale, so we'll just use 2x for Tests.
/// override it on your own risk.
@MainActor public static var scale: CGFloat?
public nonisolated(unsafe) static var scale: CGFloat?
#else
/// visionOS doesn't have a screen scale, so we'll just use 2x for Tests.
/// override it on your own risk.
public static var scale: CGFloat?
#endif
}
#endif

Expand All @@ -63,11 +81,9 @@ private struct PlatformImage {
return sdk.png
}

#elseif (swift(>=5.9) && os(visionOS))
#elseif(swift(>=5.9) && os(visionOS))
init?(data: Data) {
let scale = syncMainThread { Screen.scale }

if let scale,
if let scale = Screen.scale,
let image = UIImage(data: data, scale: scale) {
self.init(image)
} else if let image = UIImage(data: data) {
Expand All @@ -83,7 +99,7 @@ private struct PlatformImage {

#elseif os(iOS) || os(tvOS) || os(watchOS)
init?(data: Data) {
let scale = syncMainThread { Screen.scale }
let scale = Screen.scale

if let image = UIImage(data: data, scale: scale) {
self.init(image)
Expand Down Expand Up @@ -118,25 +134,25 @@ private extension NSImage {

#if swift(>=5.10)
@inline(__always)
private func syncMainThread<T: Sendable>(_ callback: @MainActor () -> T) -> T {
private func syncMainThread<T: Sendable>(_ callback: @MainActor @Sendable () -> T) -> T {
if Thread.isMainThread {
MainActor.assumeIsolated {
callback()
return MainActor.assumeIsolated {
return callback()
}
} else {
DispatchQueue.main.sync {
callback()
return DispatchQueue.main.sync {
return callback()
}
}
}
#else
@inline(__always)
private func syncMainThread<T>(_ callback: @MainActor () -> T) -> T {
private func syncMainThread<T>(_ callback: @Sendable () -> T) -> T {
if Thread.isMainThread {
callback()
return callback()
} else {
DispatchQueue.main.sync {
callback()
return DispatchQueue.main.sync {
return callback()
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/StubbableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,8 @@ final class StubbableTests: XCTestCase {
func test_on_a_class() {
StubbableTestHelper.stub(.classFunction).andReturn("fallbackValue")
StubbableTestHelper.resetStubs()
#if (os(macOS) || os(iOS) || (swift(>=5.9) && os(visionOS))) && (arch(x86_64) || arch(arm64))

XCTAssertThrowsAssertion(StubbableTestHelper.classFunction())
#endif

StubbableTestHelper.stub(.classFunction).andReturn("fallbackValue")
XCTAssertEqual(StubbableTestHelper.classFunction(), "fallbackValue")
Expand Down Expand Up @@ -377,9 +376,8 @@ final class StubbableTests: XCTestCase {

func test_class_version_spot_check() {
StubbableTestHelper.stub(.classFunction).andReturn("original return value")
#if (os(macOS) || os(iOS) || (swift(>=5.9) && os(visionOS))) && (arch(x86_64) || arch(arm64))

XCTAssertThrowsAssertion(StubbableTestHelper.stub(.classFunction).andReturn("original return value"))
#endif

let newReturnValue = "new return value"
StubbableTestHelper.stubAgain(.classFunction).andReturn(newReturnValue)
Expand Down

0 comments on commit 027edee

Please sign in to comment.