mirror of
https://github.com/apple/swift-log
synced 2026-11-24 03:47:49 +00:00
Migrating `swift-log` from XCTest to Swift Testing ### Motivation Swift Testing is a modern alternative to XCTest. Swift Server Ecosystem packages should serve as reference implementations for modern Swift features and best practices. ### Modifications - 1-to-1 migration of test suites, tests, and assertions to Swift Testing syntax with XCTest import removed - XCTest references removed from documentation - `.trace` log level added to relevant tests - `GlobalLoggerTest` suite serialized to handle global `LoggingSystem` access (XCTest runs tests serially by default; Swift Testing runs in parallel, so serializing this suite avoids requiring `swift test --no-parallel` across all CI and development environments) ### Result Successfully executes 52 tests with `swift test --disable-xctest`.
47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Logging API open source project
|
|
//
|
|
// Copyright (c) 2022 Apple Inc. and the Swift Logging API project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of Swift Logging API project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Testing
|
|
|
|
@testable import Logging
|
|
|
|
struct SendableTest {
|
|
@Test func sendableLogger() async {
|
|
let testLogging = TestLogging()
|
|
|
|
let logger = Logger(
|
|
label: "test",
|
|
factory: {
|
|
testLogging.make(label: $0)
|
|
}
|
|
)
|
|
let message1 = Logger.Message(stringLiteral: "critical 1")
|
|
let message2 = Logger.Message(stringLiteral: "critical 2")
|
|
let metadata: Logger.Metadata = ["key": "value"]
|
|
|
|
let task = Task.detached {
|
|
logger.info("info")
|
|
logger.critical(message1)
|
|
logger.critical(message2)
|
|
logger.warning(.init(stringLiteral: "warning"), metadata: metadata)
|
|
}
|
|
|
|
await task.value
|
|
testLogging.history.assertExist(level: .info, message: "info", metadata: [:])
|
|
testLogging.history.assertExist(level: .critical, message: "critical 1", metadata: [:])
|
|
testLogging.history.assertExist(level: .critical, message: "critical 2", metadata: [:])
|
|
testLogging.history.assertExist(level: .warning, message: "warning", metadata: metadata)
|
|
}
|
|
}
|