Skip to content

Commit d05d460

Browse files
Perform swift-format on SwiftDriverTests
1 parent 4be1617 commit d05d460

36 files changed

Lines changed: 9327 additions & 5241 deletions

Tests/SwiftDriverTests/APIDigesterTests.swift

Lines changed: 308 additions & 179 deletions
Large diffs are not rendered by default.

Tests/SwiftDriverTests/CachingBuildTests.swift

Lines changed: 603 additions & 421 deletions
Large diffs are not rendered by default.

Tests/SwiftDriverTests/CompileJobTests.swift

Lines changed: 751 additions & 304 deletions
Large diffs are not rendered by default.

Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Testing
16-
import TSCBasic
17-
1815
@_spi(Testing) import SwiftDriver
1916
import SwiftOptions
17+
import TSCBasic
2018
import TestUtilities
19+
import Testing
2120

2221
@Suite(.enabled(if: sdkArgumentsAvailable)) struct CrossModuleIncrementalBuildTests {
2322
func makeOutputFileMap(
@@ -31,17 +30,19 @@ import TestUtilities
3130
"": {
3231
"swift-dependencies": "\(workingDirectory.appending(component: "\(module).swiftdeps").nativePathString(escaped: true))"
3332
}
34-
""".appending(files.map { file in
35-
"""
36-
,
37-
"\(file.nativePathString(escaped: true))": {
38-
"dependencies": "\(transform(file.basenameWithoutExt) + ".d")",
39-
"object": "\(transform(file.nativePathString(escaped: true)) + ".o")",
40-
"swiftmodule": "\(transform(file.basenameWithoutExt) + "~partial.swiftmodule")",
41-
"swift-dependencies": "\(transform(file.basenameWithoutExt) + ".swiftdeps")"
42-
}
43-
"""
44-
}.joined(separator: "\n").appending("\n}"))
33+
""".appending(
34+
files.map { file in
35+
"""
36+
,
37+
"\(file.nativePathString(escaped: true))": {
38+
"dependencies": "\(transform(file.basenameWithoutExt) + ".d")",
39+
"object": "\(transform(file.nativePathString(escaped: true)) + ".o")",
40+
"swiftmodule": "\(transform(file.basenameWithoutExt) + "~partial.swiftmodule")",
41+
"swift-dependencies": "\(transform(file.basenameWithoutExt) + ".swiftdeps")"
42+
}
43+
"""
44+
}.joined(separator: "\n").appending("\n}")
45+
)
4546
}
4647

4748
@Test func changingOutputFileMap() async throws {
@@ -54,31 +55,36 @@ import TestUtilities
5455

5556
let ofm = path.appending(component: "ofm.json")
5657
try localFileSystem.writeFileContents(ofm) {
57-
$0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) {
58-
$0 + "-some_suffix"
59-
})
58+
$0.send(
59+
self.makeOutputFileMap(in: path, module: "MagicKit", for: [magic]) {
60+
$0 + "-some_suffix"
61+
}
62+
)
6063
}
6164

62-
let driverArgs = [
63-
"swiftc",
64-
"-incremental",
65-
"-emit-module",
66-
"-output-file-map", ofm.pathString,
67-
"-module-name", "MagicKit",
68-
"-working-directory", path.pathString,
69-
"-c",
70-
magic.pathString,
71-
] + sdkArguments
65+
let driverArgs =
66+
[
67+
"swiftc",
68+
"-incremental",
69+
"-emit-module",
70+
"-output-file-map", ofm.pathString,
71+
"-module-name", "MagicKit",
72+
"-working-directory", path.pathString,
73+
"-c",
74+
magic.pathString,
75+
] + sdkArguments
7276
do {
7377
var driver = try TestDriver(args: driverArgs)
7478
let jobs = try await driver.planBuild()
7579
try await driver.run(jobs: jobs)
7680
}
7781

7882
try localFileSystem.writeFileContents(ofm) {
79-
$0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) {
80-
$0 + "-some_other_suffix"
81-
})
83+
$0.send(
84+
self.makeOutputFileMap(in: path, module: "MagicKit", for: [magic]) {
85+
$0 + "-some_other_suffix"
86+
}
87+
)
8288
}
8389

8490
do {
@@ -100,19 +106,21 @@ import TestUtilities
100106

101107
let ofm = path.appending(component: "ofm.json")
102108
try localFileSystem.writeFileContents(ofm) {
103-
$0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]))
109+
$0.send(self.makeOutputFileMap(in: path, module: "MagicKit", for: [magic]))
104110
}
105111

106-
var driver = try TestDriver(args: [
107-
"swiftc",
108-
"-incremental",
109-
"-emit-module",
110-
"-output-file-map", ofm.pathString,
111-
"-module-name", "MagicKit",
112-
"-working-directory", path.pathString,
113-
"-c",
114-
magic.pathString,
115-
] + sdkArguments)
112+
var driver = try TestDriver(
113+
args: [
114+
"swiftc",
115+
"-incremental",
116+
"-emit-module",
117+
"-output-file-map", ofm.pathString,
118+
"-module-name", "MagicKit",
119+
"-working-directory", path.pathString,
120+
"-c",
121+
magic.pathString,
122+
] + sdkArguments
123+
)
116124
let jobs = try await driver.planBuild()
117125
try await driver.run(jobs: jobs)
118126
}
@@ -125,31 +133,36 @@ import TestUtilities
125133

126134
let ofm = path.appending(component: "ofm2.json")
127135
try localFileSystem.writeFileContents(ofm) {
128-
$0.send(self.makeOutputFileMap(in: path, module: "theModule", for: [ main ]))
136+
$0.send(self.makeOutputFileMap(in: path, module: "theModule", for: [main]))
129137
}
130138

131-
var driver = try TestDriver(args: [
132-
"swiftc",
133-
"-incremental",
134-
"-emit-module",
135-
"-output-file-map", ofm.pathString,
136-
"-module-name", "theModule",
137-
"-I", path.pathString,
138-
"-working-directory", path.pathString,
139-
"-c",
140-
main.pathString,
141-
] + sdkArguments)
139+
var driver = try TestDriver(
140+
args: [
141+
"swiftc",
142+
"-incremental",
143+
"-emit-module",
144+
"-output-file-map", ofm.pathString,
145+
"-module-name", "theModule",
146+
"-I", path.pathString,
147+
"-working-directory", path.pathString,
148+
"-c",
149+
main.pathString,
150+
] + sdkArguments
151+
)
142152

143153
let jobs = try await driver.planBuild()
144154
try await driver.run(jobs: jobs)
145155

146156
let sourcePath = path.appending(component: "main.swiftdeps")
147157
let data = try localFileSystem.readFileContents(sourcePath)
148158
try driver.withModuleDependencyGraph { host in
149-
let testGraph = try #require(try SourceFileDependencyGraph(
150-
internedStringTable: host.internedStringTable,
151-
data: data,
152-
fromSwiftModule: false))
159+
let testGraph = try #require(
160+
try SourceFileDependencyGraph(
161+
internedStringTable: host.internedStringTable,
162+
data: data,
163+
fromSwiftModule: false
164+
)
165+
)
153166
#expect(testGraph.majorVersion == 1)
154167
#expect(testGraph.minorVersion == 0)
155168
testGraph.verify()
@@ -158,7 +171,8 @@ import TestUtilities
158171
let swiftmodulePath = ExternalDependency(
159172
fileName: path.appending(component: "MagicKit.swiftmodule")
160173
.pathString.intern(in: host),
161-
host.internedStringTable)
174+
host.internedStringTable
175+
)
162176
testGraph.forEachNode { node in
163177
if case .externalDepend(swiftmodulePath) = node.key.designator {
164178
#expect(!foundNode)

Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Testing
1615
@_spi(Testing) import SwiftDriver
1716
import TSCBasic
17+
import Testing
1818

1919
@Suite struct DependencyGraphSerializationTests: ModuleDependencyGraphMocker {
2020
static let maxIndex = 12
@@ -35,23 +35,27 @@ import TSCBasic
3535
to: mockPath,
3636
on: fs,
3737
buildRecord: graph.buildRecord,
38-
mockSerializedGraphVersion: alteredVersion)
38+
mockSerializedGraphVersion: alteredVersion
39+
)
3940
}
4041

4142
do {
4243
let outputFileMap = OutputFileMap.mock(maxIndex: Self.maxIndex)
43-
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup.mock(outputFileMap: outputFileMap, fileSystem: fs)
44+
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup.mock(
45+
outputFileMap: outputFileMap,
46+
fileSystem: fs
47+
)
4448
try info.blockingConcurrentAccessOrMutation {
45-
_ = try ModuleDependencyGraph.read(from: mockPath,
46-
info: info)
49+
_ = try ModuleDependencyGraph.read(
50+
from: mockPath,
51+
info: info
52+
)
4753
Issue.record("Should have thrown an exception")
4854
}
49-
}
50-
catch let ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion(expected, read) {
55+
} catch let ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion(expected, read) {
5156
#expect(expected == currentVersion)
5257
#expect(read == alteredVersion)
53-
}
54-
catch {
58+
} catch {
5559
Issue.record("Threw an unexpected exception: \(error.localizedDescription)")
5660
}
5761
}
@@ -63,11 +67,16 @@ import TSCBasic
6367

6468
try originalGraph.blockingConcurrentMutation {
6569
try originalGraph.write(
66-
to: mockPath, on: fs,
67-
buildRecord: originalGraph.buildRecord)
70+
to: mockPath,
71+
on: fs,
72+
buildRecord: originalGraph.buildRecord
73+
)
6874
}
6975

70-
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup.mock(outputFileMap: outputFileMap, fileSystem: fs)
76+
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup.mock(
77+
outputFileMap: outputFileMap,
78+
fileSystem: fs
79+
)
7180
let deserializedGraph = try info.blockingConcurrentAccessOrMutation {
7281
try #require(try ModuleDependencyGraph.read(from: mockPath, info: info))
7382
}
@@ -78,9 +87,11 @@ import TSCBasic
7887
graph.nodeFinder.forEachNode {
7988
nodes.insert($0.description(in: graph))
8089
}
81-
let uses: [String: Set<String>] = graph.nodeFinder.usesByDef.reduce(into: Dictionary()) { usesByDef, keyAndNodes in
90+
let uses: [String: Set<String>] = graph.nodeFinder.usesByDef.reduce(into: Dictionary()) {
91+
usesByDef,
92+
keyAndNodes in
8293
usesByDef[keyAndNodes.0.description(in: graph)] =
83-
keyAndNodes.1.reduce(into: Set()) { $0.insert($1.description(in: graph))}
94+
keyAndNodes.1.reduce(into: Set()) { $0.insert($1.description(in: graph)) }
8495
}
8596
let feds: Set<String> = graph.fingerprintedExternalDependencies.reduce(into: Set()) {
8697
$0.insert($1.description(in: graph))
@@ -89,7 +100,10 @@ import TSCBasic
89100
}
90101
#expect(descsToCompare[0].nodes == descsToCompare[1].nodes, "Round trip node difference!")
91102
#expect(descsToCompare[0].uses == descsToCompare[1].uses, "Round trip def-uses difference!")
92-
#expect(descsToCompare[0].feds == descsToCompare[1].feds, "Round trip fingerprinted external dependency difference!")
103+
#expect(
104+
descsToCompare[0].feds == descsToCompare[1].feds,
105+
"Round trip fingerprinted external dependency difference!"
106+
)
93107
}
94108

95109
@Test func roundTripFixtures() throws {
@@ -114,10 +128,13 @@ import TSCBasic
114128
.load(index: 6, nodes: [.member: ["m,mm", "n,nn"]]),
115129
.load(index: 7, nodes: [.member: ["o,oo->", "p,pp->"]]),
116130
.load(index: 8, nodes: [.externalDepend: ["/foo->", "/bar->"]]),
117-
.load(index: 9, nodes: [
118-
.nominal: ["a", "b", "c->", "d->"],
119-
.topLevel: ["b", "c", "d->", "a->"]
120-
])
131+
.load(
132+
index: 9,
133+
nodes: [
134+
.nominal: ["a", "b", "c->", "d->"],
135+
.topLevel: ["b", "c", "d->", "a->"],
136+
]
137+
),
121138
]),
122139
GraphFixture(commands: [
123140
.load(index: 0, nodes: [.topLevel: ["a0", "a->"]]),
@@ -173,7 +190,7 @@ import TSCBasic
173190
]),
174191
GraphFixture(commands: [
175192
.load(index: 0, nodes: [.member: ["a,aa", "b,bb", "c,cc"]]),
176-
.load(index: 1, nodes: [.member: ["x,xx->", "b,bb->", "z,zz->"]])
193+
.load(index: 1, nodes: [.member: ["x,xx->", "b,bb->", "z,zz->"]]),
177194
]),
178195
GraphFixture(commands: [
179196
.load(index: 0, nodes: [.nominal: ["a", "b", "c"]]),
@@ -217,7 +234,7 @@ import TSCBasic
217234
.load(index: 0, nodes: [.nominal: ["a"]]),
218235
.load(index: 1, nodes: [.nominal: ["a->"]]),
219236
.load(index: 2, nodes: [.nominal: ["b->"]]),
220-
.reload(index: 0, nodes: [.nominal: ["a", "b"]])
237+
.reload(index: 0, nodes: [.nominal: ["a", "b"]]),
221238
]),
222239
GraphFixture(commands: [
223240
.reload(index: 1, nodes: [.nominal: ["b", "a->"]])
@@ -227,7 +244,7 @@ import TSCBasic
227244
.load(index: 1, nodes: [.nominal: ["B1", "A1->"]]),
228245
.load(index: 2, nodes: [.nominal: ["C1", "A2->"]]),
229246
.load(index: 3, nodes: [.nominal: ["D1"]]),
230-
.reload(index: 0, nodes: [.nominal: ["A1", "A2"]], fingerprint: "changed")
247+
.reload(index: 0, nodes: [.nominal: ["A1", "A2"]], fingerprint: "changed"),
231248
]),
232249
GraphFixture(commands: [
233250
.load(index: 0, nodes: [.nominal: ["A"]]),
@@ -258,7 +275,7 @@ import TSCBasic
258275
.load(index: 4, nodes: [.nominal: ["B2", "C2", "A2->B2"]]),
259276
.load(index: 5, nodes: [.nominal: ["B2->"]]),
260277
.load(index: 6, nodes: [.nominal: ["C2->"]]),
261-
.reload(index: 0, nodes: [.nominal: ["A1@11", "A2@2"]])
278+
.reload(index: 0, nodes: [.nominal: ["A1@11", "A2@2"]]),
262279
]),
263280
GraphFixture(commands: [
264281
.load(index: 0, nodes: [.externalDepend: ["/foo->", "/bar->"]], fingerprint: "ABCDEFG"),
@@ -270,9 +287,9 @@ import TSCBasic
270287
let graph = Self.mockGraphCreator.mockUpAGraph()
271288
for loadCommand in fixture.commands {
272289
switch loadCommand {
273-
case .load(index: let index, nodes: let nodes, fingerprint: let fingerprint):
290+
case .load(let index, let nodes, let fingerprint):
274291
graph.simulateLoad(index, nodes, fingerprint)
275-
case .reload(index: let index, nodes: let nodes, fingerprint: let fingerprint):
292+
case .reload(let index, let nodes, let fingerprint):
276293
_ = graph.simulateReload(index, nodes, fingerprint)
277294
}
278295
}

0 commit comments

Comments
 (0)