Files
swift-service-lifecycle/Tests/ServiceLifecycleTests/ClosureServiceTests.swift
T
Gus Cairo 9db4c30383 Add a ClosureService (#227)
This PR adds a `ClosureService`.

You can use a `ClosureService` to create a lightweight, inline `Service`
without defining and conforming a dedicated type.
2026-02-20 14:49:38 +01:00

42 lines
1.1 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftServiceLifecycle open source project
//
// Copyright (c) 2026 Apple Inc. and the SwiftServiceLifecycle project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftServiceLifecycle project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import ServiceLifecycle
import Testing
struct ClosureServiceTests {
@Test
func runExecutesClosure() async throws {
try await confirmation { executed in
let service = ClosureService {
executed()
}
try await service.run()
}
}
@Test
func runPropagatesErrors() async {
struct TestError: Error {}
let service = ClosureService {
throw TestError()
}
await #expect(throws: TestError.self) {
try await service.run()
}
}
}