diff --git a/Package.resolved b/Package.resolved index dbd59ed..22b65ab 100644 --- a/Package.resolved +++ b/Package.resolved @@ -17,6 +17,24 @@ "branch" : "main", "revision" : "6835ce0972f40ef76f1214dc0efc75ec19082631" } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036", + "version" : "509.0.2" + } + }, + { + "identity" : "swift-testing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-testing", + "state" : { + "revision" : "56f3c5086bcb6c88680f48aeba7222617ed088d3", + "version" : "0.2.0" + } } ], "version" : 2 diff --git a/Package.swift b/Package.swift index 79e233b..0faa371 100644 --- a/Package.swift +++ b/Package.swift @@ -78,7 +78,6 @@ let package = Package( .target(name: "CoreServices", path: "PrivateFrameworks/CoreServices"), .target(name: "UIKitCore", path: "PrivateFrameworks/UIKitCore"), openSwiftUITarget, - openSwiftUITestTarget, openSwiftUICompatibilityTestTarget, ] ) @@ -153,7 +152,7 @@ if swiftLogCondition { } // Remove the check when swift-testing reaches 1.0.0 -let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING") +let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING", default: true) if swiftTestingCondition { package.dependencies.append( .package(url: "https://github.com/apple/swift-testing", from: "0.2.0") @@ -161,9 +160,7 @@ if swiftTestingCondition { openSwiftUITestTarget.dependencies.append( .product(name: "Testing", package: "swift-testing") ) - var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? []) - swiftSettings.append(.define("OPENSWIFTUI_SWIFT_TESTING")) - openSwiftUITestTarget.swiftSettings = swiftSettings + package.targets.append(openSwiftUITestTarget) } let compatibilityTestCondition = envEnable("OPENSWIFTUI_COMPATIBILITY_TEST") diff --git a/Tests/OpenSwiftUITests/Accessibility/internal/AccessibilityBoundedNumberTests.swift b/Tests/OpenSwiftUITests/Accessibility/internal/AccessibilityBoundedNumberTests.swift index ca315cb..b09c9b0 100644 --- a/Tests/OpenSwiftUITests/Accessibility/internal/AccessibilityBoundedNumberTests.swift +++ b/Tests/OpenSwiftUITests/Accessibility/internal/AccessibilityBoundedNumberTests.swift @@ -6,29 +6,23 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class AccessibilityBoundedNumberTests: XCTestCase { - func testBoundedNumberLocalizedDescription() throws { - if let boundedNumber = AccessibilityBoundedNumber(for: 4.5, in: 3.0...16.0, by: 0.1) { - XCTAssertEqual(boundedNumber.localizedDescription, "4.5") //decimal case - } else { - XCTFail("Failed to init bounded number") - } - if let boundedNumber = AccessibilityBoundedNumber(for: 4.5, in: 1.0...101.0, by: 0.1) { - XCTAssertEqual(boundedNumber.localizedDescription, "4%") // .percent case - } else { - XCTFail("Failed to init bounded number") - } - if let boundedNumber = AccessibilityBoundedNumber(for: 1.5, in: 1.3...2.3, by: 0.1) { - XCTAssertEqual(boundedNumber.localizedDescription, "1.5") // .decimal case - } else { - XCTFail("Failed to init bounded number") - } - if let boundedNumber = AccessibilityBoundedNumber(for: 1.5, in: 1.0...2.0, by: 0.1) { - XCTAssertEqual(boundedNumber.localizedDescription, "150%") // .percent case - } else { - XCTFail("Failed to init bounded number") - } +struct AccessibilityBoundedNumberTests { + @Test(arguments: [ + (4.5, 3.0 ... 16.0, 0.1,"4.5"), + (4.5, 1.0 ... 101.0, 0.1,"4%"), + (1.5, 1.3 ... 2.3, 0.1,"1.5"), + (1.5, 1.0 ... 2.0, 0.1,"150%"), + + ]) + func boundedNumberLocalizedDescription( + value: Double, + range: ClosedRange, + strideValue: Double, + expectedDescription: String + ) throws { + let boundedNumber = try #require(AccessibilityBoundedNumber(for: value, in: range, by: strideValue)) + #expect(boundedNumber.localizedDescription == expectedDescription) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/EnvironmentValues/EnvironmentValuesOpenURLTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/EnvironmentValues/EnvironmentValuesOpenURLTests.swift index 3c884aa..4c33337 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/EnvironmentValues/EnvironmentValuesOpenURLTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/EnvironmentValues/EnvironmentValuesOpenURLTests.swift @@ -1,15 +1,17 @@ // // EnvironmentValuesOpenURLTests.swift -// +// // // Created by Kyle on 2023/11/28. // -import XCTest +import Foundation @testable import OpenSwiftUI +import Testing -final class EnvironmentValuesOpenURLTests: XCTestCase { +struct EnvironmentValuesOpenURLTests { #if os(iOS) || os(macOS) || os(tvOS) + @Test func testOpenURLActionKey() { let value = OpenURLActionKey.defaultValue value.callAsFunction(URL(string: "https://example.com")!) diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/BloomFilterTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/BloomFilterTests.swift index b9f36ad..2334027 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/BloomFilterTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/BloomFilterTests.swift @@ -5,15 +5,10 @@ // Created by Kyle on 2023/10/17. // -@testable import OpenSwiftUI import Foundation -#if OPENSWIFTUI_SWIFT_TESTING +@testable import OpenSwiftUI import Testing -#else -import XCTest -#endif -#if OPENSWIFTUI_SWIFT_TESTING struct BloomFilterTests { #if os(macOS) @Test("Bloom Filter's init", .enabled(if: ProcessInfo.processInfo.operatingSystemVersionString == "14.0")) @@ -54,43 +49,3 @@ struct BloomFilterTests { #endif } } -#else -final class BloomFilterTests: XCTestCase { - - func testInitType() throws { - #if os(macOS) - // hashValue: 0x1dd382138 - // 1 &<< (value &>> 0x10): 1 &<< 0x38 -> 0x0100_0000_0000_0000 - // 1 &<< (value &>> 0x0a): 1 &<< 0x08 -> 0x0000_0000_0000_0100 - // 1 &<< (value &>> 0x94): 1 &<< 0x13 -> 0x0000_0000_0008_0000 - try initTypeHelper(Int.self, expectedTypeValue: 0x1dd382138, expectedValue: 0x0100_0000_0008_0100, message: "macOS 14.0") - #elseif os(iOS) - try initTypeHelper(Int.self, expectedTypeValue: 0x1df10d1e0, expectedValue: 0x0010_0000_4001_0000, message: "iOS 15.5 Simulator") - #endif - } - - private func initTypeHelper(_ type: Any.Type, expectedTypeValue: Int, expectedValue: UInt, message: String = "") throws { - let typeValue = Int(bitPattern: unsafeBitCast(type, to: OpaquePointer.self)) - guard typeValue == expectedTypeValue else { - throw XCTSkip("The OS version is not covered. Please run it under \(message)") - } - XCTAssertEqual(BloomFilter(type: type).value, expectedValue) - } - - func testInitHashValue() throws { - // hashValue: 0 - // 1 &<< (value &>> 0x10): 1 &<< 0 -> 0x0000_0000_0000_0001 - // 1 &<< (value &>> 0x0a): 1 &<< 0 -> 0x0000_0000_0000_0001 - // 1 &<< (value &>> 0x04): 1 &<< 0 -> 0x0000_0000_0000_0001 - XCTAssertEqual(BloomFilter(hashValue: 0).value, 0x0000_0000_0000_0001) - - #if arch(x86_64) || arch(arm64) - // hashValue: 0x00000001dfa19ae0 - // 1 &<< (value &>> 0x10): 1 &<< 0x21 -> 0x0000_0002_0000_0000 - // 1 &<< (value &>> 0x0a): 1 &<< 0x26 -> 0x0000_0040_0000_0000 - // 1 &<< (value &>> 0x04): 1 &<< 0x2e -> 0x0000_4000_0000_0000 - XCTAssertEqual(BloomFilter(hashValue: 0x00000001dfa19ae0).value, 0x0000_4042_0000_0000) - #endif - } -} -#endif diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Boxes/MutableBoxTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Boxes/MutableBoxTests.swift index 069479a..a02d74c 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Boxes/MutableBoxTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Boxes/MutableBoxTests.swift @@ -1,17 +1,18 @@ // // MutableBoxTests.swift -// +// // // Created by Kyle on 2023/10/17. // -import XCTest @testable import OpenSwiftUI +import Testing -final class MutableBoxTests: XCTestCase { - func testExample() throws { +struct MutableBoxTests { + @Test + func wrappedValue() { @MutableBox var box = 3 $box.wrappedValue = 4 - XCTAssertEqual(box, 4) + #expect(box == 4) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/ConstantLocationTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/ConstantLocationTests.swift index 251ffea..3ced97d 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/ConstantLocationTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/ConstantLocationTests.swift @@ -6,16 +6,17 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class ConstantLocationTests: XCTestCase { - func testConstantLocation() throws { +struct ConstantLocationTests { + @Test + func constantLocation() throws { let location = ConstantLocation(value: 0) - XCTAssertEqual(location.wasRead, true) - XCTAssertEqual(location.get(), 0) + #expect(location.wasRead == true) + #expect(location.get() == 0) location.wasRead = false location.set(1, transaction: .init()) - XCTAssertEqual(location.wasRead, true) - XCTAssertEqual(location.get(), 0) + #expect(location.wasRead == true) + #expect(location.get() == 0) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/FunctionalLocationTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/FunctionalLocationTests.swift index eb94285..2d17ab9 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/FunctionalLocationTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/FunctionalLocationTests.swift @@ -6,10 +6,11 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class FunctionalLocationTests: XCTestCase { - func testFunctionalLocation() throws { +struct FunctionalLocationTests { + @Test + func functionalLocation() { class V { var count = 0 } @@ -19,12 +20,11 @@ final class FunctionalLocationTests: XCTestCase { } setValue: { newCount, _ in value.count = newCount * newCount } - - XCTAssertEqual(location.wasRead, true) - XCTAssertEqual(location.get(), 0) + #expect(location.wasRead == true) + #expect(location.get() == 0) location.wasRead = false location.set(2, transaction: .init()) - XCTAssertEqual(location.wasRead, true) - XCTAssertEqual(location.get(), 4) + #expect(location.wasRead == true) + #expect(location.get() == 4) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationBoxTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationBoxTests.swift index ac4509b..493d800 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationBoxTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationBoxTests.swift @@ -5,17 +5,18 @@ // Created by Kyle on 2023/11/8. // -import XCTest @testable import OpenSwiftUI +import Testing -final class LocationBoxTests: XCTestCase { - func testBasicLocationBox() throws { +struct LocationBoxTests { + @Test + func basicLocationBox() throws { class MockLocation: Location { - private var value: Int = 0 - var wasRead: Bool = false + private var value = 0 + var wasRead = false typealias Value = Int func get() -> Value { value } - func set(_ value: Int, transaction: Transaction) { self.value = value } + func set(_ value: Int, transaction _: Transaction) { self.value = value } func update() -> (Int, Bool) { defer { value += 1 } return (value, value == 0) @@ -25,41 +26,41 @@ final class LocationBoxTests: XCTestCase { let location = MockLocation() let box = LocationBox(location: location) - XCTAssertEqual(location.wasRead, false) - XCTAssertEqual(box.wasRead, false) + #expect(location.wasRead == false) + #expect(box.wasRead == false) location.wasRead = true - XCTAssertEqual(location.wasRead, true) - XCTAssertEqual(box.wasRead, true) + #expect(location.wasRead == true) + #expect(box.wasRead == true) box.wasRead = false - XCTAssertEqual(location.wasRead, false) - XCTAssertEqual(box.wasRead, false) + #expect(location.wasRead == false) + #expect(box.wasRead == false) - XCTAssertEqual(location.get(), 0) - XCTAssertEqual(box.get(), 0) + #expect(location.get() == 0) + #expect(box.get() == 0) location.set(3, transaction: .init()) - XCTAssertEqual(location.get(), 3) - XCTAssertEqual(box.get(), 3) + #expect(location.get() == 3) + #expect(box.get() == 3) box.set(0, transaction: .init()) - XCTAssertEqual(location.get(), 0) - XCTAssertEqual(box.get(), 0) + #expect(location.get() == 0) + #expect(box.get() == 0) let (value, result) = box.update() - XCTAssertEqual(location.get(), 1) - XCTAssertEqual(value, 0) - XCTAssertEqual(result, true) + #expect((value, result) == (0, true)) + #expect(location.get() == 1) } - func testProjecting() { + @Test + func projecting() { struct V { var count = 0 } class MockLocation: Location { private var value = V() - var wasRead: Bool = false + var wasRead = false typealias Value = V func get() -> Value { value } - func set(_ value: Value, transaction: Transaction) { self.value = value } + func set(_ value: Value, transaction _: Transaction) { self.value = value } func update() -> (Value, Bool) { defer { value.count += 1 } return (value, value.count == 0) @@ -70,12 +71,12 @@ final class LocationBoxTests: XCTestCase { let box = LocationBox(location: location) let keyPath: WritableKeyPath = \V.count - XCTAssertEqual(box.cache.checkReference(for: keyPath, on: location), false) + #expect(box.cache.checkReference(for: keyPath, on: location) == false) let newLocation = box.projecting(keyPath) - XCTAssertEqual(box.cache.checkReference(for: keyPath, on: location), true) - XCTAssertEqual(location.get().count, 0) + #expect(box.cache.checkReference(for: keyPath, on: location) == true) + #expect(location.get().count == 0) _ = box.update() - XCTAssertEqual(location.get().count, 1) - XCTAssertEqual(newLocation.get(), 1) + #expect(location.get().count == 1) + #expect(newLocation.get() == 1) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationProjectionCacheTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationProjectionCacheTests.swift index 7f35442..2a4ae12 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationProjectionCacheTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationProjectionCacheTests.swift @@ -6,10 +6,11 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class LocationProjectionCacheTests: XCTestCase { - func testLocationProjectionCache() throws { +struct LocationProjectionCacheTests { + @Test + func locationProjectionCache() throws { struct V { var count = 0 var name = "" @@ -25,22 +26,21 @@ final class LocationProjectionCacheTests: XCTestCase { let countKeyPath: WritableKeyPath = \V.count let nameKeyPath: WritableKeyPath = \V.name var cache = LocationProjectionCache() - XCTAssertEqual(cache.checkReference(for: countKeyPath, on: location), false) - XCTAssertEqual(cache.checkReference(for: nameKeyPath, on: location), false) + #expect(cache.checkReference(for: countKeyPath, on: location) == false) + #expect(cache.checkReference(for: nameKeyPath, on: location) == false) _ = cache.reference(for: countKeyPath, on: location) - XCTAssertEqual(cache.checkReference(for: countKeyPath, on: location), false) - XCTAssertEqual(cache.checkReference(for: nameKeyPath, on: location), false) + #expect(cache.checkReference(for: countKeyPath, on: location) == false) + #expect(cache.checkReference(for: nameKeyPath, on: location) == false) _ = cache.reference(for: nameKeyPath, on: location) - XCTAssertEqual(cache.checkReference(for: countKeyPath, on: location), false) - XCTAssertEqual(cache.checkReference(for: nameKeyPath, on: location), false) + #expect(cache.checkReference(for: countKeyPath, on: location) == false) + #expect(cache.checkReference(for: nameKeyPath, on: location) == false) withExtendedLifetime(cache.reference(for: countKeyPath, on: location)) { - XCTAssertEqual(cache.checkReference(for: countKeyPath, on: location), true) - XCTAssertEqual(cache.checkReference(for: nameKeyPath, on: location), false) - withExtendedLifetime(cache.reference(for: nameKeyPath, on: location)) { - XCTAssertEqual(cache.checkReference(for: countKeyPath, on: location), true) - XCTAssertEqual(cache.checkReference(for: nameKeyPath, on: location), true) + #expect(cache.checkReference(for: countKeyPath, on: location) == true) + #expect(cache.checkReference(for: nameKeyPath, on: location) == false) + withExtendedLifetime(cache.reference(for: nameKeyPath, on: location)) { #expect(cache.checkReference(for: countKeyPath, on: location) == true) + #expect(cache.checkReference(for: nameKeyPath, on: location) == true) } } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationTests.swift index 43f7dc4..1a5ce4f 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Location/LocationTests.swift @@ -6,10 +6,11 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class LocationTests: XCTestCase { - func testLocation() throws { +struct LocationTests { + @Test + func location() { struct L: Location { typealias Value = Int var wasRead = false @@ -18,7 +19,6 @@ final class LocationTests: XCTestCase { } let location = L() let (value, result) = location.update() - XCTAssertEqual(value, 0) - XCTAssertEqual(result, true) + #expect((value, result) == (0, true)) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Property/PropertyListTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Property/PropertyListTests.swift index 60e1c06..53e4bd5 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/Property/PropertyListTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/Property/PropertyListTests.swift @@ -6,11 +6,12 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class PropertyListTests: XCTestCase { - func testDescription() throws { +struct PropertyListTests { + @Test + func description() throws { let plist = PropertyList() - XCTAssertEqual(plist.description, "[]") + #expect(plist.description == "[]") } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Internal/UnsafeLockedPointerTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Internal/UnsafeLockedPointerTests.swift index 69f6e9e..c887cb8 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Internal/UnsafeLockedPointerTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Internal/UnsafeLockedPointerTests.swift @@ -1,27 +1,29 @@ // // UnsafeLockedPointerTests.swift -// +// // // Created by Kyle on 2023/10/19. // -import XCTest @testable import OpenSwiftUI +import Testing -final class UnsafeLockedPointerTests: XCTestCase { - func testBasic() { +struct UnsafeLockedPointerTests { + @Test + func basic() { let pointer = UnsafeLockedPointer(wrappedValue: 2) defer { pointer.destroy() } - XCTAssertEqual(pointer.wrappedValue, 2) + #expect(pointer.wrappedValue == 2) pointer.wrappedValue = 3 - XCTAssertEqual(pointer.wrappedValue, 3) + #expect(pointer.wrappedValue == 3) } - func testPropertyWrapper() { + @Test + func propertyWrapper() { @UnsafeLockedPointer var value = 2 defer { $value.destroy() } - XCTAssertEqual(value, 2) + #expect(value == 2) $value.wrappedValue = 3 - XCTAssertEqual(value, 3) + #expect(value == 3) } } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/ModelData/Binding/BindingOperationsTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/ModelData/Binding/BindingOperationsTests.swift index cd83608..b2a227e 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/ModelData/Binding/BindingOperationsTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/ModelData/Binding/BindingOperationsTests.swift @@ -6,9 +6,9 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class BindingOperationsTests: XCTestCase { - func testForceUnwrapping() throws { - } +struct BindingOperationsTests { + @Test + func forceUnwrapping() {} } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyTests.swift index 90e9d9a..c38e688 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyTests.swift @@ -6,8 +6,9 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class DynamicPropertyTests: XCTestCase { - func testExample() throws {} +struct DynamicPropertyTests { + @Test + func example() {} } diff --git a/Tests/OpenSwiftUITests/DataAndStorage/Preferences/PreferenceKeyTests.swift b/Tests/OpenSwiftUITests/DataAndStorage/Preferences/PreferenceKeyTests.swift index 74b75fb..74531d4 100644 --- a/Tests/OpenSwiftUITests/DataAndStorage/Preferences/PreferenceKeyTests.swift +++ b/Tests/OpenSwiftUITests/DataAndStorage/Preferences/PreferenceKeyTests.swift @@ -6,9 +6,9 @@ // @testable import OpenSwiftUI -import XCTest +import Testing -final class PreferenceKeyTests: XCTestCase { +struct PreferenceKeyTests { struct DemoKey: PreferenceKey { struct Value: ExpressibleByNilLiteral { var value = 0 @@ -21,12 +21,12 @@ final class PreferenceKeyTests: XCTestCase { } } - func testPreferenceKeyReduce() throws { + @Test + func preferenceKeyReduce() throws { var value = DemoKey.defaultValue DemoKey.reduce(value: &value) { DemoKey.Value(value: 3) } - // Migrate to use swift-test - XCTAssertEqual(value.value, 3) + #expect(value.value == 3) } } diff --git a/Tests/OpenSwiftUITests/InterfaceIdiomTests.swift b/Tests/OpenSwiftUITests/InterfaceIdiomTests.swift index 47fa56d..f75e8f4 100644 --- a/Tests/OpenSwiftUITests/InterfaceIdiomTests.swift +++ b/Tests/OpenSwiftUITests/InterfaceIdiomTests.swift @@ -6,66 +6,49 @@ // @testable import OpenSwiftUI -import XCTest +import Testing +#if canImport(UIKit) +import UIKit +#endif -final class InterfaceIdiomTests: XCTestCase { - func testIdiomEqual() throws { - XCTAssertEqual(AnyInterfaceIdiomType.phone, AnyInterfaceIdiomType.phone) - XCTAssertNotEqual(AnyInterfaceIdiomType.phone, AnyInterfaceIdiomType.touchBar) +struct InterfaceIdiomTests { + @Test + func idiomEqual() { + #expect(AnyInterfaceIdiomType.phone == .phone) + #expect(AnyInterfaceIdiomType.phone != .touchBar) } - func testIdiomAccepts() throws { - XCTAssertTrue(InterfaceIdiom.Phone.accepts(InterfaceIdiom.Phone.self)) - XCTAssertFalse(InterfaceIdiom.Phone.accepts(InterfaceIdiom.CarPlay.self)) + @Test + func idiomAccepts() throws { + #expect(InterfaceIdiom.Phone.accepts(InterfaceIdiom.Phone.self) == true) + #expect(InterfaceIdiom.Phone.accepts(InterfaceIdiom.CarPlay.self) == false) } #if os(iOS) || os(tvOS) - func testInterfaceIdiom() throws { - XCTAssertEqual( - UIUserInterfaceIdiom.unspecified.idiom, - nil - ) - XCTAssertEqual( - UIUserInterfaceIdiom.phone.idiom, - .phone - ) - XCTAssertEqual( - UIUserInterfaceIdiom.pad.idiom, - .pad - ) - XCTAssertEqual( - UIUserInterfaceIdiom.tv.idiom, - .tv - ) - XCTAssertEqual( - UIUserInterfaceIdiom.carPlay.idiom, - .carplay - ) - XCTAssertEqual( - UIUserInterfaceIdiom(rawValue: 4)?.idiom, - .watch - ) - + @Test + func interfaceIdiom() throws { + #expect(UIUserInterfaceIdiom.unspecified.idiom == nil) + #expect(UIUserInterfaceIdiom.phone.idiom == .phone) + #expect(UIUserInterfaceIdiom.pad.idiom == .pad) + #expect(UIUserInterfaceIdiom.tv.idiom == .tv) + #expect(UIUserInterfaceIdiom.carPlay.idiom == .carplay) + #expect(UIUserInterfaceIdiom(rawValue: 4)?.idiom == .watch) if #available(iOS 14, tvOS 14, *) { - XCTAssertEqual( - UIUserInterfaceIdiom.mac.idiom, - .mac - ) + #expect(UIUserInterfaceIdiom.mac.idiom == .mac) } if #available(iOS 17, tvOS 17, *) { - XCTAssertEqual( - UIUserInterfaceIdiom.vision.idiom, - .vision - ) + #expect(UIUserInterfaceIdiom.vision.idiom == .vision) } } - func testInterfaceIdiomInput() throws { - XCTAssertNil(InterfaceIdiom.Input.defaultValue) + @Test + func interfaceIdiomInput() { + #expect(InterfaceIdiom.Input.defaultValue == nil) let idiom = UIDevice.current.userInterfaceIdiom.idiom InterfaceIdiom.Input.defaultValue = idiom - XCTAssertEqual(InterfaceIdiom.Input.defaultValue, idiom) - XCTAssertEqual(InterfaceIdiom.Input.targetValue, .phone) + + #expect(InterfaceIdiom.Input.defaultValue == idiom) + #expect(InterfaceIdiom.Input.targetValue == .phone) } #endif } diff --git a/Tests/OpenSwiftUITests/Layout/LayoutAdjustments/Alignment/AlignmentIDTests.swift b/Tests/OpenSwiftUITests/Layout/LayoutAdjustments/Alignment/AlignmentIDTests.swift index f485dcf..00f92aa 100644 --- a/Tests/OpenSwiftUITests/Layout/LayoutAdjustments/Alignment/AlignmentIDTests.swift +++ b/Tests/OpenSwiftUITests/Layout/LayoutAdjustments/Alignment/AlignmentIDTests.swift @@ -6,35 +6,44 @@ // @testable import OpenSwiftUI -import XCTest +import Testing +#if canImport(Darwin) +import CoreGraphics +#elseif os(Linux) +import Foundation +#endif -final class AlignmentIDTests: XCTestCase { +struct AlignmentIDTests { private struct TestAlignment: AlignmentID { static func defaultValue(in _: ViewDimensions) -> CGFloat { .zero } } - func testCombineExplicitLinear() throws { + @Test + func combineExplicitLinear() throws { var value: CGFloat? - (0 ... 10).forEach { n in + try (0 ... 10).forEach { n in TestAlignment._combineExplicit( childValue: .init(n), n, into: &value ) - XCTAssertEqual(value!, CGFloat(n) / 2, accuracy: 0.0001) + let value = try #require(value) + #expect(abs(value - CGFloat(n) / 2) <= 0.0001) } } - func testCombineExplicitSame() throws { + @Test + func combineExplicitSame() throws { var value: CGFloat? let child = CGFloat.random(in: 0.0 ... 100.0) - (0 ... 10).forEach { n in + try (0 ... 10).forEach { n in TestAlignment._combineExplicit( childValue: child, n, into: &value ) - XCTAssertEqual(value!, child, accuracy: 0.0001) + let value = try #require(value) + #expect(abs(value - child) <= 0.0001) } } } diff --git a/Tests/OpenSwiftUITests/ProtocolDescriptorTests.swift b/Tests/OpenSwiftUITests/ProtocolDescriptorTests.swift index 3a050ef..5a39199 100644 --- a/Tests/OpenSwiftUITests/ProtocolDescriptorTests.swift +++ b/Tests/OpenSwiftUITests/ProtocolDescriptorTests.swift @@ -7,16 +7,11 @@ @testable import OpenSwiftUI import OpenSwiftUIShims -#if OPENSWIFTUI_SWIFT_TESTING import Testing -#else -import XCTest -#endif -#if OPENSWIFTUI_SWIFT_TESTING struct ProtocolDescriptorTests { @Test - func testExample() throws { + func conformsToProtocolCheck() throws { struct ContentView: View { var body: some View { EmptyView() @@ -35,26 +30,3 @@ struct ProtocolDescriptorTests { #expect(conformsToProtocol(ContentViewModifier.self, _viewModifierProtocolDescriptor())) } } -#else -final class ProtocolDescriptorTests: XCTestCase { - func testExample() throws { - struct ContentView: View { - var body: some View { - EmptyView() - } - } - - struct ContentViewModifier: ViewModifier { - func body(content _: Content) -> some View { - EmptyView() - } - } - - XCTAssertTrue(conformsToProtocol(ContentView.self, _viewProtocolDescriptor())) - XCTAssertFalse(conformsToProtocol(ContentView.self, _viewModifierProtocolDescriptor())) - - XCTAssertFalse(conformsToProtocol(ContentViewModifier.self, _viewProtocolDescriptor())) - XCTAssertTrue(conformsToProtocol(ContentViewModifier.self, _viewModifierProtocolDescriptor())) - } -} -#endif diff --git a/Tests/OpenSwiftUITests/Scaffolding.swift b/Tests/OpenSwiftUITests/Scaffolding.swift index e95d362..e3067ec 100644 --- a/Tests/OpenSwiftUITests/Scaffolding.swift +++ b/Tests/OpenSwiftUITests/Scaffolding.swift @@ -5,7 +5,6 @@ // Created by Kyle on 2023/11/8. // -#if OPENSWIFTUI_SWIFT_TESTING import Testing import XCTest @@ -14,4 +13,3 @@ final class AllTests: XCTestCase { await XCTestScaffold.runAllTests(hostedBy: self) } } -#endif diff --git a/Tests/OpenSwiftUITests/Shims/LockedPointerTests.swift b/Tests/OpenSwiftUITests/Shims/LockedPointerTests.swift index a1dd96c..d60eca0 100644 --- a/Tests/OpenSwiftUITests/Shims/LockedPointerTests.swift +++ b/Tests/OpenSwiftUITests/Shims/LockedPointerTests.swift @@ -7,10 +7,11 @@ @testable import OpenSwiftUI import OpenSwiftUIShims -import XCTest +import Testing -final class LockedPointerTests: XCTestCase { - func testAlignmentOffset() throws { +struct LockedPointerTests { + @Test + func alignmentOffset() { // The alignment of a struct type is the maximum alignment out of all its properties. // Between an Int and a Bool, the Int has a larger alignment value of 8, so the struct uses it. struct A { @@ -25,19 +26,19 @@ final class LockedPointerTests: XCTestCase { let v1: SIMD3 let v2: Bool } + + #expect(MemoryLayout.size == 9) + #expect(MemoryLayout.stride == 16) + #expect(MemoryLayout.alignment == 8) - XCTAssertEqual(MemoryLayout.size, 9) - XCTAssertEqual(MemoryLayout.stride, 16) - XCTAssertEqual(MemoryLayout.alignment, 8) - - XCTAssertEqual(MemoryLayout.size, 16) - XCTAssertEqual(MemoryLayout.stride, 16) - XCTAssertEqual(MemoryLayout.alignment, 8) - - XCTAssertEqual(MemoryLayout.size, 33) - XCTAssertEqual(MemoryLayout.stride, 48) - XCTAssertEqual(MemoryLayout.alignment, 16) - + #expect(MemoryLayout.size == 16) + #expect(MemoryLayout.stride == 16) + #expect(MemoryLayout.alignment == 8) + + #expect(MemoryLayout.size == 33) + #expect(MemoryLayout.stride == 48) + #expect(MemoryLayout.alignment == 16) + let p1 = LockedPointer(type: A.self) let p2 = LockedPointer(type: B.self) let p3 = LockedPointer(type: C.self) @@ -46,27 +47,27 @@ final class LockedPointerTests: XCTestCase { p2.delete() p3.delete() } - - XCTAssertEqual(p1.rawValue.pointee.offset, 8) - XCTAssertEqual(p2.rawValue.pointee.offset, 8) - XCTAssertEqual(p3.rawValue.pointee.offset, 16) + #expect(p1.rawValue.pointee.offset == 8) + #expect(p2.rawValue.pointee.offset == 8) + #expect(p3.rawValue.pointee.offset == 16) } - func testLocking() { + @Test + func locking() { #if canImport(os) let pointer = LockedPointer(type: Int.self) - XCTAssertEqual(pointer.rawValue.pointee.lock._os_unfair_lock_opaque, 0) + #expect(pointer.rawValue.pointee.lock._os_unfair_lock_opaque == 0) pointer.lock() - XCTAssertNotEqual(pointer.rawValue.pointee.lock._os_unfair_lock_opaque, 0) + #expect(pointer.rawValue.pointee.lock._os_unfair_lock_opaque != 0) pointer.unlock() - XCTAssertEqual(pointer.rawValue.pointee.lock._os_unfair_lock_opaque, 0) + #expect(pointer.rawValue.pointee.lock._os_unfair_lock_opaque == 0) #else let pointer = LockedPointer(type: Int.self) - XCTAssertEqual(pointer.rawValue.pointee.lock, 0) + #expect(pointer.rawValue.pointee.lock == 0) pointer.lock() - XCTAssertNotEqual(pointer.rawValue.pointee.lock, 0) + #expect(pointer.rawValue.pointee.lock != 0) pointer.unlock() - XCTAssertEqual(pointer.rawValue.pointee.lock, 0) + #expect(pointer.rawValue.pointee.lock == 0) #endif } } diff --git a/Tests/OpenSwiftUITests/Views/ControlsAndIndicators/Slider/SliderTests.swift b/Tests/OpenSwiftUITests/Views/ControlsAndIndicators/Slider/SliderTests.swift index 4dfaac5..b531024 100644 --- a/Tests/OpenSwiftUITests/Views/ControlsAndIndicators/Slider/SliderTests.swift +++ b/Tests/OpenSwiftUITests/Views/ControlsAndIndicators/Slider/SliderTests.swift @@ -5,13 +5,14 @@ // Created by Kyle on 2023/12/16. // -import XCTest +import Testing @testable import OpenSwiftUI -final class SliderTests: XCTestCase { - func testExample() throws { +struct SliderTests { + @Test + func example() { let s = Slider(value: .constant(233), in: 200.0 ... 300.0, step: 28.0) - XCTAssertEqual(s.skipDistance, 0.333, accuracy: 0.001) - XCTAssertEqual(s.discreteValueCount, 4) + #expect(abs(s.skipDistance - 0.333) <= 0.001) + #expect(s.discreteValueCount == 4) } } diff --git a/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AngleTests.swift b/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AngleTests.swift index f1a0fdd..ff0d7f8 100644 --- a/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AngleTests.swift +++ b/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AngleTests.swift @@ -6,39 +6,42 @@ // import OpenSwiftUI -import XCTest +import Testing -final class AngleTests: XCTestCase { +struct AngleTests { private func helper(radians: Double, degrees: Double) { let a1 = Angle(radians: radians) - XCTAssertEqual(a1.radians, radians) - XCTAssertEqual(a1.degrees, degrees) - XCTAssertEqual(a1.animatableData, radians * 128) + #expect(a1.radians == radians) + #expect(a1.degrees == degrees) + #expect(a1.animatableData == radians * 128) let a2 = Angle(degrees: degrees) - XCTAssertEqual(a2.radians, radians) - XCTAssertEqual(a2.degrees, degrees) - XCTAssertEqual(a1, a2) - XCTAssertEqual(a1.animatableData * 2, (a2 * 2).animatableData) + #expect(a2.radians == radians) + #expect(a2.degrees == degrees) + #expect(a1 == a2) + #expect(a1.animatableData * 2 == (a2 * 2).animatableData) var a3 = a1 a3.animatableData *= 2 var a4 = a1 a4.radians *= 2 - XCTAssertEqual(a3, a4) + #expect(a3 == a4) } - func testZero() { + @Test + func zero() { helper(radians: .zero, degrees: .zero) } - func testRightAngle() { + @Test + func rightAngle() { helper(radians: .pi / 2, degrees: 90) } - func testHalfCircle() { + @Test + func halfCircle() { helper(radians: .pi, degrees: 180) } - func testCircle() { + func circle() { helper(radians: .pi * 2, degrees: 360) } } diff --git a/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AxisTests.swift b/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AxisTests.swift index f6f2849..6a3ada3 100644 --- a/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AxisTests.swift +++ b/Tests/OpenSwiftUITests/Views/DrawingAndGraphics/AxisTests.swift @@ -6,21 +6,22 @@ // import OpenSwiftUI -import XCTest +import Testing -final class AxisTests: XCTestCase { - func testExample() { +struct AxisTests { + @Test + func example() { let h = Axis.horizontal let v = Axis.vertical - XCTAssertEqual(Axis.allCases, [h, v]) - XCTAssertEqual(h.rawValue, 0) - XCTAssertEqual(v.rawValue, 1) - - XCTAssertEqual(h.description, "horizontal") - XCTAssertEqual(v.description, "vertical") + #expect(Axis.allCases == [h, v]) + #expect(h.rawValue == 0) + #expect(v.rawValue == 1) + #expect(h.description == "horizontal") + #expect(v.description == "vertical") + let hs = Axis.Set.horizontal let vs = Axis.Set.vertical - XCTAssertFalse(hs.contains(vs)) + #expect(hs.contains(vs) == false) } } diff --git a/Tests/OpenSwiftUITests/_ViewDebugTests.swift b/Tests/OpenSwiftUITests/_ViewDebugTests.swift index aa950f9..e2938a7 100644 --- a/Tests/OpenSwiftUITests/_ViewDebugTests.swift +++ b/Tests/OpenSwiftUITests/_ViewDebugTests.swift @@ -1,43 +1,48 @@ // // _ViewDebugTests.swift -// +// // // Created by Kyle on 2023/10/6. // -import XCTest @testable import OpenSwiftUI +import Testing +#if canImport(Darwin) +import CoreGraphics +#elseif os(Linux) +import Foundation +#endif -final class _ViewDebugTests: XCTestCase { - func testType() throws { - throw XCTSkip("Skip the test until we finish the implementation of _ViewDebug") -// let data = try XCTUnwrap(_ViewDebug.serializedData([ -// .init( -// data: [ -// .type: CGSize.self, -// ], -// childData: [] -// ) -// ])) -// let content = String(decoding: data, as: UTF8.self) -// XCTAssertEqual(content, """ -// [{"properties":[{"id":0,"attribute":{"type":"__C.CGSize","flags":0,"readableType":""}}],"children":[]}] -// """) +struct _ViewDebugTests { + @Test(.disabled("Skip the test until we finish the implementation of _ViewDebug")) + func type() throws { + let data = try #require(_ViewDebug.serializedData([ + .init( + data: [ + .type: CGSize.self, + ], + childData: [] + ), + ])) + let content = String(decoding: data, as: UTF8.self) + #expect(content == #""" + [{"properties":[{"id":0,"attribute":{"type":"__C.CGSize","flags":0,"readableType":""}}],"children":[]}] + """#) } - func testSize() throws { - throw XCTSkip("Skip the test until we finish the implementation of _ViewDebug") -// let data = try XCTUnwrap(_ViewDebug.serializedData([ -// .init( -// data: [ -// .size: CGSize(width: 20, height: 20), -// ], -// childData: [] -// ) -// ])) -// let content = String(decoding: data, as: UTF8.self) -// XCTAssertEqual(content, """ -// [{"properties":[],"children":[]}] -// """) + @Test(.disabled("Skip the test until we finish the implementation of _ViewDebug")) + func size() throws { + let data = try #require(_ViewDebug.serializedData([ + .init( + data: [ + .size: CGSize(width: 20, height: 20), + ], + childData: [] + ), + ])) + let content = String(decoding: data, as: UTF8.self) + #expect(content == #""" + [{"properties":[],"children":[]}] + """#) } }