Skip to content

Commit f27c3e8

Browse files
committed
Fix swift-testing build issue
1 parent 166ee6d commit f27c3e8

File tree

4 files changed

+74
-25
lines changed

4 files changed

+74
-25
lines changed

Package.resolved

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ if useAG {
7272
name: "AttributeGraphTests",
7373
dependencies: [
7474
"AttributeGraph",
75-
.product(name: "Testing", package: "swift-testing"),
7675
]
7776
),
7877
]
@@ -105,7 +104,6 @@ if useAG {
105104
name: "OpenGraphTests",
106105
dependencies: [
107106
"OpenGraph",
108-
.product(name: "Testing", package: "swift-testing"),
109107
]
110108
),
111109
]
@@ -144,8 +142,8 @@ if useOSLog {
144142
}
145143

146144
// Remove this when swift-testing is 1.0.0
147-
let disableSwiftTesting = ProcessInfo.processInfo.environment["OPENSWIFTUI_DISABLE_SWIFT_TESTING"] != nil
148-
if !disableSwiftTesting {
145+
let useSwiftTesting = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_SWIFT_TESTING"] != nil
146+
if useSwiftTesting {
149147
var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? [])
150148
swiftSettings.append(.define("OPENSWIFTUI_USE_SWIFT_TESTING"))
151149
openSwiftUITestTarget.swiftSettings = swiftSettings

Tests/OpenSwiftUITests/DataAndStorage/Internal/BloomFilterTests.swift

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
// Created by Kyle on 2023/10/17.
66
//
77

8-
#if OPENSWIFTUI_USE_SWIFT_TESTING
98
@testable import OpenSwiftUI
10-
import Testing
119
import Foundation
10+
#if OPENSWIFTUI_USE_SWIFT_TESTING
11+
import Testing
12+
#else
13+
import XCTest
14+
#endif
1215

16+
#if OPENSWIFTUI_USE_SWIFT_TESTING
1317
struct BloomFilterTests {
1418
#if os(macOS)
1519
@Test("Bloom Filter's init", .enabled(if: ProcessInfo.processInfo.operatingSystemVersionString == "14.0"))
@@ -50,4 +54,43 @@ struct BloomFilterTests {
5054
#endif
5155
}
5256
}
57+
#else
58+
final class BloomFilterTests: XCTestCase {
59+
60+
func testInitType() throws {
61+
#if os(macOS)
62+
// hashValue: 0x1dd382138
63+
// 1 &<< (value &>> 0x10): 1 &<< 0x38 -> 0x0100_0000_0000_0000
64+
// 1 &<< (value &>> 0x0a): 1 &<< 0x08 -> 0x0000_0000_0000_0100
65+
// 1 &<< (value &>> 0x94): 1 &<< 0x13 -> 0x0000_0000_0008_0000
66+
try initTypeHelper(Int.self, expectedTypeValue: 0x1dd382138, expectedValue: 0x0100_0000_0008_0100, message: "macOS 14.0")
67+
#elseif os(iOS)
68+
try initTypeHelper(Int.self, expectedTypeValue: 0x1df10d1e0, expectedValue: 0x0010_0000_4001_0000, message: "iOS 15.5 Simulator")
69+
#endif
70+
}
71+
72+
private func initTypeHelper(_ type: Any.Type, expectedTypeValue: Int, expectedValue: UInt, message: String = "") throws {
73+
let typeValue = Int(bitPattern: unsafeBitCast(type, to: OpaquePointer.self))
74+
guard typeValue == expectedTypeValue else {
75+
throw XCTSkip("The OS version is not covered. Please run it under \(message)")
76+
}
77+
XCTAssertEqual(BloomFilter(type: type).value, expectedValue)
78+
}
79+
80+
func testInitHashValue() throws {
81+
// hashValue: 0
82+
// 1 &<< (value &>> 0x10): 1 &<< 0 -> 0x0000_0000_0000_0001
83+
// 1 &<< (value &>> 0x0a): 1 &<< 0 -> 0x0000_0000_0000_0001
84+
// 1 &<< (value &>> 0x04): 1 &<< 0 -> 0x0000_0000_0000_0001
85+
XCTAssertEqual(BloomFilter(hashValue: 0).value, 0x0000_0000_0000_0001)
86+
87+
#if arch(x86_64) || arch(arm64)
88+
// hashValue: 0x00000001dfa19ae0
89+
// 1 &<< (value &>> 0x10): 1 &<< 0x21 -> 0x0000_0002_0000_0000
90+
// 1 &<< (value &>> 0x0a): 1 &<< 0x26 -> 0x0000_0040_0000_0000
91+
// 1 &<< (value &>> 0x04): 1 &<< 0x2e -> 0x0000_4000_0000_0000
92+
XCTAssertEqual(BloomFilter(hashValue: 0x00000001dfa19ae0).value, 0x0000_4042_0000_0000)
93+
#endif
94+
}
95+
}
5396
#endif

Tests/OpenSwiftUITests/ProtocolDescriptorTests.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
// Created by Kyle on 2023/10/3.
66
//
77

8-
#if OPENSWIFTUI_USE_SWIFT_TESTING
98
@testable import OpenSwiftUI
109
import OpenSwiftUIShims
10+
#if OPENSWIFTUI_USE_SWIFT_TESTING
1111
import Testing
12+
#else
13+
import XCTest
14+
#endif
1215

16+
#if OPENSWIFTUI_USE_SWIFT_TESTING
1317
struct ProtocolDescriptorTests {
1418
@Test
1519
func testExample() throws {
@@ -31,4 +35,26 @@ struct ProtocolDescriptorTests {
3135
#expect(conformsToProtocol(ContentViewModifier.self, _viewModifierProtocolDescriptor()))
3236
}
3337
}
38+
#else
39+
final class ProtocolDescriptorTests: XCTestCase {
40+
func testExample() throws {
41+
struct ContentView: View {
42+
var body: some View {
43+
EmptyView()
44+
}
45+
}
46+
47+
struct ContentViewModifier: ViewModifier {
48+
func body(content _: Content) -> some View {
49+
EmptyView()
50+
}
51+
}
52+
53+
XCTAssertTrue(conformsToProtocol(ContentView.self, _viewProtocolDescriptor()))
54+
XCTAssertFalse(conformsToProtocol(ContentView.self, _viewModifierProtocolDescriptor()))
55+
56+
XCTAssertFalse(conformsToProtocol(ContentViewModifier.self, _viewProtocolDescriptor()))
57+
XCTAssertTrue(conformsToProtocol(ContentViewModifier.self, _viewModifierProtocolDescriptor()))
58+
}
59+
}
3460
#endif

0 commit comments

Comments
 (0)