|
1 | 1 | import Foundation |
2 | | -import XCTest |
| 2 | +import Testing |
3 | 3 |
|
4 | 4 | /* No @testable import: we mostly test whether the architecture works; we must be as close as possible to a regular client’s use. */ |
5 | 5 | import GlobalConfModule |
6 | 6 |
|
7 | 7 |
|
8 | 8 |
|
9 | | -final class UsageMainActorTests : XCTestCase { |
| 9 | +struct UsageMainActorTests { |
10 | 10 |
|
| 11 | + @Test |
11 | 12 | @MainActor |
12 | 13 | func testUsingMainActorService() { |
13 | 14 | MainActor.preconditionIsolated() |
14 | 15 | let c = MainActorContainer() |
15 | 16 | c.mainActorService.printHello() |
16 | 17 | c.mainActorServiceFromKeyPath.printHello() |
17 | 18 | InjectedConf<MainActorService>.value.printHello() |
18 | | - XCTAssertTrue(c.mainActorService === Conf[\.mainActorService]) |
19 | | - XCTAssertTrue(c.mainActorService === Conf[key: MainActorService.AutoInjectionKey.self]) |
20 | | - XCTAssertTrue(c.mainActorService === Conf.rootValue(for: MainActorService.AutoInjectionKey.self)) |
21 | | - XCTAssertTrue(c.mainActorService === InjectedConf<MainActorService>.value) |
22 | | - XCTAssertTrue(c.mainActorServiceFromKeyPath === InjectedConf<MainActorService>.value) |
| 19 | + #expect(c.mainActorService === Conf[\.mainActorService]) |
| 20 | + #expect(c.mainActorService === Conf[key: MainActorService.AutoInjectionKey.self]) |
| 21 | + #expect(c.mainActorService === Conf.rootValue(for: MainActorService.AutoInjectionKey.self)) |
| 22 | + #expect(c.mainActorService === InjectedConf<MainActorService>.value) |
| 23 | + #expect(c.mainActorServiceFromKeyPath === InjectedConf<MainActorService>.value) |
23 | 24 |
|
24 | | - XCTAssertTrue(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
| 25 | + #expect(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
25 | 26 |
|
26 | 27 | let oldOtherActor = c.otherMainActorService |
27 | 28 | Conf.setRootValue(c.mainActorService, for: \.mainActorService2) |
28 | | - XCTAssertTrue(c.otherMainActorService === InjectedConf<MainActorService>.value) |
| 29 | + #expect(c.otherMainActorService === InjectedConf<MainActorService>.value) |
29 | 30 |
|
30 | 31 | Conf.withValue(oldOtherActor, for: \.mainActorService2, operation: { |
31 | | - XCTAssertTrue(c.mainActorService === Conf[\.mainActorService]) |
32 | | - XCTAssertTrue(c.otherMainActorService === oldOtherActor) |
33 | | - XCTAssertTrue(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
| 32 | + #expect(c.mainActorService === Conf[\.mainActorService]) |
| 33 | + #expect(c.otherMainActorService === oldOtherActor) |
| 34 | + #expect(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
34 | 35 | }) |
35 | 36 |
|
36 | 37 | Conf.withValues{ |
37 | 38 | $0[\.mainActorService2] = MainActorService() |
38 | 39 | }operation:{ |
39 | | - XCTAssertTrue(c.otherMainActorService !== oldOtherActor) |
40 | | - XCTAssertTrue(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
| 40 | + #expect(c.otherMainActorService !== oldOtherActor) |
| 41 | + #expect(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
41 | 42 | } |
42 | 43 |
|
43 | 44 | InjectedConf<MainActorService>.withValue(MainActorService()){ |
44 | | - XCTAssertTrue(c.otherMainActorService !== oldOtherActor) |
45 | | - XCTAssertTrue(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
| 45 | + #expect(c.otherMainActorService !== oldOtherActor) |
| 46 | + #expect(c.otherMainActorService !== InjectedConf<MainActorService>.value) |
46 | 47 | } |
47 | 48 |
|
48 | | - XCTAssertTrue(c.otherMainActorService === InjectedConf<MainActorService>.value) |
| 49 | + #expect(c.otherMainActorService === InjectedConf<MainActorService>.value) |
49 | 50 |
|
50 | 51 | InjectedConf<MainActorService>.rootValue = oldOtherActor |
51 | | - XCTAssertTrue(c.otherMainActorService !== c.mainActorService) |
| 52 | + #expect(c.otherMainActorService !== c.mainActorService) |
52 | 53 | } |
53 | 54 |
|
54 | 55 | @MainActor |
|
0 commit comments