Skip to content

Commit 4bd9e00

Browse files
committed
Migrate some tests to swift-testing
Some are more difficult and/or not really possible due to, for instance, swift-syntax not having done the utilities for them (see <swiftlang/swift-syntax#2720>).
1 parent 2f1abd5 commit 4bd9e00

3 files changed

Lines changed: 36 additions & 30 deletions

File tree

Tests/GlobalConfTests/DocTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
import Foundation
2-
import XCTest
2+
import Testing
33

44
/* No @testable import: we mostly test whether the architecture works; we must be as close as possible to a regular client’s use. */
55
import GlobalConfModule
66

77

88

99
/* We mostly just check the examples in the Readme compile. */
10-
final class DocTests : XCTestCase {
10+
struct DocTests {
1111

12+
@Test
1213
func testDependencyInjectionUsage() {
1314
Conf.setRootValue(DefaultDocService(), for: \.docService)
1415
docService.doAmazingStuff()
15-
XCTAssertTrue(true)
16+
#expect(true)
1617
}
1718

1819
@InjectedConf(\.docService)
1920
var docService: DocService
2021

22+
@Test
2123
func testConfUsage() {
22-
XCTAssertEqual(Conf[\.docConf], 42)
23-
XCTAssertEqual(Conf.docConf, 42)
24+
#expect(Conf[\.docConf] == 42)
25+
#expect(Conf.docConf == 42)
2426
}
2527

28+
@Test
2629
func testAutoInjectedUsage() {
27-
XCTAssertNotNil(docAutoInjectedService)
30+
#expect(docAutoInjectedService != nil)
2831
}
2932

3033
@InjectedConf()

Tests/GlobalConfTests/UsageMainActorTests.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
import Foundation
2-
import XCTest
2+
import Testing
33

44
/* No @testable import: we mostly test whether the architecture works; we must be as close as possible to a regular client’s use. */
55
import GlobalConfModule
66

77

88

9-
final class UsageMainActorTests : XCTestCase {
9+
struct UsageMainActorTests {
1010

11+
@Test
1112
@MainActor
1213
func testUsingMainActorService() {
1314
MainActor.preconditionIsolated()
1415
let c = MainActorContainer()
1516
c.mainActorService.printHello()
1617
c.mainActorServiceFromKeyPath.printHello()
1718
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)
2324

24-
XCTAssertTrue(c.otherMainActorService !== InjectedConf<MainActorService>.value)
25+
#expect(c.otherMainActorService !== InjectedConf<MainActorService>.value)
2526

2627
let oldOtherActor = c.otherMainActorService
2728
Conf.setRootValue(c.mainActorService, for: \.mainActorService2)
28-
XCTAssertTrue(c.otherMainActorService === InjectedConf<MainActorService>.value)
29+
#expect(c.otherMainActorService === InjectedConf<MainActorService>.value)
2930

3031
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)
3435
})
3536

3637
Conf.withValues{
3738
$0[\.mainActorService2] = MainActorService()
3839
}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)
4142
}
4243

4344
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)
4647
}
4748

48-
XCTAssertTrue(c.otherMainActorService === InjectedConf<MainActorService>.value)
49+
#expect(c.otherMainActorService === InjectedConf<MainActorService>.value)
4950

5051
InjectedConf<MainActorService>.rootValue = oldOtherActor
51-
XCTAssertTrue(c.otherMainActorService !== c.mainActorService)
52+
#expect(c.otherMainActorService !== c.mainActorService)
5253
}
5354

5455
@MainActor

Tests/GlobalConfTests/UsageTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import Foundation
2-
import XCTest
2+
import Testing
33

44
/* No @testable import: we mostly test whether the architecture works; we must be as close as possible to a regular client’s use. */
55
import GlobalConfModule
66

77

88

9-
final class UsageTests : XCTestCase {
9+
struct UsageTests {
1010

11+
@Test
1112
func testUsingNoActorService() {
1213
noActorService.printHello()
1314
noActorServiceFromKeyPath.printHello()
1415
InjectedConf<NoActorService>.value.printHello()
15-
XCTAssertTrue(noActorService === InjectedConf<NoActorService>.value)
16-
XCTAssertTrue(noActorServiceFromKeyPath === InjectedConf<NoActorService>.value)
16+
#expect(noActorService === InjectedConf<NoActorService>.value)
17+
#expect(noActorServiceFromKeyPath === InjectedConf<NoActorService>.value)
1718
}
1819

20+
@Test
1921
func testUsingNoActorServiceWithFactory() {
20-
XCTAssertTrue(noActorService === noActorService)
21-
XCTAssertTrue(noActorFactoryService !== noActorFactoryService)
22+
#expect(noActorService === noActorService)
23+
#expect(noActorFactoryService !== noActorFactoryService)
2224
}
2325

2426
@InjectedConf()

0 commit comments

Comments
 (0)