diff --git a/Package.swift b/Package.swift index 041dbe66..51a49b2f 100644 --- a/Package.swift +++ b/Package.swift @@ -41,6 +41,7 @@ let package = Package( name: "SpeziTests", dependencies: [ .target(name: "Spezi"), + .target(name: "XCTSpezi"), .product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions") ] ) diff --git a/Sources/Spezi/Standard/StandardPropertyWrapper.swift b/Sources/Spezi/Standard/StandardPropertyWrapper.swift index a8b0ce45..233f5a45 100644 --- a/Sources/Spezi/Standard/StandardPropertyWrapper.swift +++ b/Sources/Spezi/Standard/StandardPropertyWrapper.swift @@ -33,29 +33,7 @@ public class _StandardPropertyWrapper: AnyStandardPropertyWrapper { /// Refer to ``Component/StandardActor`` for information on how to use the `@StandardActor` property wrapper. Do not use the `_StandardPropertyWrapper` directly. - public init(_ constraint: Constraint.Type = Constraint.self) { - guard Constraint.self is any Standard.Type else { - preconditionFailure( - """ - The \(String(describing: Constraint.self)) constraint does not conform to `Standard`. - - Ensure that your constraint type conforms to the `Standard` protocol: - - ```swift - protocol ExampleConstraint: Standard { - // ... - } - - class ExampleComponent: Component { - @StandardActor var standard: any ExampleConstraint - - // ... - } - ``` - """ - ) - } - } + public init(_ constraint: Constraint.Type = Constraint.self) { } func inject(standard: S) { diff --git a/Tests/SpeziTests/StandardTests/StandardConstraintTests.swift b/Tests/SpeziTests/StandardTests/StandardConstraintTests.swift new file mode 100644 index 00000000..cbef547f --- /dev/null +++ b/Tests/SpeziTests/StandardTests/StandardConstraintTests.swift @@ -0,0 +1,74 @@ +// +// This source file is part of the Stanford Spezi open-source project +// +// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + +@testable import Spezi +import SwiftUI +import XCTest +import XCTRuntimeAssertions + + +private protocol ExampleConstraint: Standard { + func betterFulfill(expectation: XCTestExpectation) +} + + +extension MockStandard: ExampleConstraint { + func betterFulfill(expectation: XCTestExpectation) { + fulfill(expectation: expectation) + } +} + + +final class StandardConstraintTests: XCTestCase { + final class StandardConstraintTestComponent: Component { + @StandardActor private var standard: any ExampleConstraint + + let expectation: XCTestExpectation + + + init(expectation: XCTestExpectation) { + self.expectation = expectation + } + + + func configure() { + Task { + await standard.betterFulfill(expectation: expectation) + } + } + } + + class StandardConstraintTestApplicationDelegate: SpeziAppDelegate { + let expectation: XCTestExpectation + + + override var configuration: Configuration { + Configuration(standard: MockStandard()) { + StandardConstraintTestComponent(expectation: expectation) + } + } + + + init(expectation: XCTestExpectation) { + self.expectation = expectation + } + } + + + func testStandardConstraint() async throws { + let expectation = XCTestExpectation(description: "Component") + expectation.assertForOverFulfill = true + + let standardConstraintTestApplicationDelegate = await StandardConstraintTestApplicationDelegate( + expectation: expectation + ) + _ = await standardConstraintTestApplicationDelegate.spezi + + await fulfillment(of: [expectation], timeout: 0.01) + } +} diff --git a/Tests/SpeziTests/StandardTests/StandardTests.swift b/Tests/SpeziTests/StandardTests/StandardInjectionTests.swift similarity index 97% rename from Tests/SpeziTests/StandardTests/StandardTests.swift rename to Tests/SpeziTests/StandardTests/StandardInjectionTests.swift index c71fdb17..37a8e1a0 100644 --- a/Tests/SpeziTests/StandardTests/StandardTests.swift +++ b/Tests/SpeziTests/StandardTests/StandardInjectionTests.swift @@ -12,7 +12,7 @@ import XCTest import XCTRuntimeAssertions -final class StandardTests: XCTestCase { +final class StandardInjectionTests: XCTestCase { final class StandardInjectionTestComponent: Component { @StandardActor var standard: MockStandard diff --git a/Tests/UITests/UITests.xcodeproj/xcshareddata/xcschemes/TestApp.xcscheme b/Tests/UITests/UITests.xcodeproj/xcshareddata/xcschemes/TestApp.xcscheme index c83feaa5..b867602a 100644 --- a/Tests/UITests/UITests.xcodeproj/xcshareddata/xcschemes/TestApp.xcscheme +++ b/Tests/UITests/UITests.xcodeproj/xcshareddata/xcschemes/TestApp.xcscheme @@ -54,74 +54,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES" - onlyGenerateCoverageForSpecifiedTargets = "YES"> - - - - - - - - - - - - - - - - - - - - + shouldUseLaunchSchemeArgsEnv = "YES"> - - - -