Skip to content

Commit d6ac6bc

Browse files
committed
migrate to Swift Testing
1 parent 6fbc114 commit d6ac6bc

File tree

9 files changed

+268
-223
lines changed

9 files changed

+268
-223
lines changed

Tests/InMemoryTracingTests/InMemoryTracerTests.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if canImport(Testing)
15+
@_spi(Testing) import InMemoryTracing
1616
@_spi(Locking) import Instrumentation
1717
import Testing
1818
import Tracing
19-
@_spi(Testing) import InMemoryTracing
2019

2120
@Suite("InMemoryTracer")
2221
struct InMemoryTracerTests {
@@ -437,5 +436,3 @@ private final class MockClock {
437436
Instant(nanosecondsSinceEpoch: self._now)
438437
}
439438
}
440-
441-
#endif

Tests/InstrumentationTests/InstrumentTests.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import Instrumentation
1617
import ServiceContextModule
17-
import XCTest
18+
import Testing
1819

19-
final class InstrumentTests: XCTestCase {
20-
func testMultiplexInvokesAllInstruments() {
20+
@Suite("MultiplexInstrument")
21+
struct InstrumentTests {
22+
@Test("MultiplexInstrument invokes all instruments")
23+
func multiplexInvokesAllInstruments() {
2124
let instrument = MultiplexInstrument([
2225
FirstFakeTracer(),
2326
SecondFakeTracer(),
@@ -26,15 +29,14 @@ final class InstrumentTests: XCTestCase {
2629
var context = ServiceContext.topLevel
2730
instrument.extract([String: String](), into: &context, using: DictionaryExtractor())
2831

29-
XCTAssertEqual(context[FirstFakeTracer.TraceIDKey.self], FirstFakeTracer.defaultTraceID)
30-
XCTAssertEqual(context[SecondFakeTracer.TraceIDKey.self], SecondFakeTracer.defaultTraceID)
32+
#expect(context[FirstFakeTracer.TraceIDKey.self] == FirstFakeTracer.defaultTraceID)
33+
#expect(context[SecondFakeTracer.TraceIDKey.self] == SecondFakeTracer.defaultTraceID)
3134

3235
var subsequentRequestHeaders = ["Accept": "application/json"]
3336
instrument.inject(context, into: &subsequentRequestHeaders, using: DictionaryInjector())
3437

35-
XCTAssertEqual(
36-
subsequentRequestHeaders,
37-
[
38+
#expect(
39+
subsequentRequestHeaders == [
3840
"Accept": "application/json",
3941
FirstFakeTracer.headerName: FirstFakeTracer.defaultTraceID,
4042
SecondFakeTracer.headerName: SecondFakeTracer.defaultTraceID,

Tests/TracingTests/ActorTracingTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import ServiceContextModule
16+
import Testing
1617
import Tracing
17-
import XCTest
1818

1919
@testable import Instrumentation
2020

2121
/// This is a compile-time test
22-
final class ActorTracingTests: XCTestCase {
23-
func test() {}
22+
@Suite("Actor Tracing Compatibility")
23+
struct ActorTracingTests {
24+
@Test("Compiles with actor isolation")
25+
func compilesWithActorIsolation() {
26+
// This test exists purely to verify that the code compiles
27+
// with Swift's strict concurrency checking
28+
}
2429
}
2530

2631
func work() async {}

Tests/TracingTests/DynamicTracepointTracerTests.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Foundation
1516
import ServiceContextModule
17+
import Testing
1618
import Tracing
17-
import XCTest
1819

1920
@testable import Instrumentation
2021

21-
final class DynamicTracepointTracerTests: XCTestCase {
22-
func test_adhoc_enableBySourceLoc() {
22+
@Suite("Dynamic Tracepoint Tracer Tests")
23+
struct DynamicTracepointTracerTests {
24+
@Test("Ad-hoc tracepoint enable by source location")
25+
func adhoc_enableBySourceLoc() {
2326
let tracer = DynamicTracepointTestTracer()
2427

2528
let fileID = #fileID
@@ -49,16 +52,17 @@ final class DynamicTracepointTracerTests: XCTestCase {
4952
}
5053
}
5154

52-
XCTAssertEqual(tracer.spans.count, 4)
55+
#expect(tracer.spans.count == 4)
5356

5457
for span in tracer.spans {
55-
XCTAssertEqual(span.context.traceID, "trace-id-fake-\(fileID)-\(fakeLine)")
58+
#expect(span.context.traceID == "trace-id-fake-\(fileID)-\(fakeLine)")
5659
}
57-
XCTAssertEqual(tracer.spans[0].context.spanID, "span-id-fake-\(fileID)-\(fakeLine)")
58-
XCTAssertEqual(tracer.spans[1].context.spanID, "span-id-fake-\(fileID)-\(fakeNextLine)")
60+
#expect(tracer.spans[0].context.spanID == "span-id-fake-\(fileID)-\(fakeLine)")
61+
#expect(tracer.spans[1].context.spanID == "span-id-fake-\(fileID)-\(fakeNextLine)")
5962
}
6063

61-
func test_adhoc_enableByFunction() {
64+
@Test("Ad-hoc tracepoint enable by function")
65+
func adhoc_enableByFunction() {
6266
let tracer = DynamicTracepointTestTracer()
6367

6468
let fileID = #fileID
@@ -70,12 +74,12 @@ final class DynamicTracepointTracerTests: XCTestCase {
7074
self.logic(fakeLine: 55, tracer: tracer)
7175
self.traceMeLogic(fakeLine: fakeLine, tracer: tracer)
7276

73-
XCTAssertEqual(tracer.spans.count, 2)
77+
#expect(tracer.spans.count == 2)
7478
for span in tracer.spans {
75-
XCTAssertEqual(span.context.traceID, "trace-id-fake-\(fileID)-\(fakeLine)")
79+
#expect(span.context.traceID == "trace-id-fake-\(fileID)-\(fakeLine)")
7680
}
77-
XCTAssertEqual(tracer.spans[0].context.spanID, "span-id-fake-\(fileID)-\(fakeLine)")
78-
XCTAssertEqual(tracer.spans[1].context.spanID, "span-id-fake-\(fileID)-\(fakeNextLine)")
81+
#expect(tracer.spans[0].context.spanID == "span-id-fake-\(fileID)-\(fakeLine)")
82+
#expect(tracer.spans[1].context.spanID == "span-id-fake-\(fileID)-\(fakeNextLine)")
7983
}
8084

8185
func logic(fakeLine: UInt, tracer: any Tracer) {

0 commit comments

Comments
 (0)