Skip to content

Commit b69a4d1

Browse files
committed
Fixup Broken Incremental Tests
These tests were stomping over each other and reading stale priors data that was just hanging around from the last run in the driver-computed temporary directory. Even within a single test, this is wrong because multiple modules will read the same priors file. Use the name of the module to diversify things here.
1 parent 67f6089 commit b69a4d1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Tests/SwiftDriverTests/CrossModuleIncrementalBuildTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import TestUtilities
1919
class CrossModuleIncrementalBuildTests: XCTestCase {
2020
func makeOutputFileMap(
2121
in workingDirectory: AbsolutePath,
22+
module: String,
2223
for files: [AbsolutePath],
2324
outputTransform transform: (String) -> String = { $0 }
2425
) -> String {
2526
"""
2627
{
2728
"": {
28-
"swift-dependencies": "\(workingDirectory.appending(component: "module.swiftdeps").nativePathString(escaped: true))"
29+
"swift-dependencies": "\(workingDirectory.appending(component: "\(module).swiftdeps").nativePathString(escaped: true))"
2930
}
3031
""".appending(files.map { file in
3132
"""
@@ -53,7 +54,7 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
5354

5455
let ofm = path.appending(component: "ofm.json")
5556
try localFileSystem.writeFileContents(ofm) {
56-
$0 <<< self.makeOutputFileMap(in: path, for: [ magic ]) {
57+
$0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) {
5758
$0 + "-some_suffix"
5859
}
5960
}
@@ -75,7 +76,7 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
7576
}
7677

7778
try localFileSystem.writeFileContents(ofm) {
78-
$0 <<< self.makeOutputFileMap(in: path, for: [ magic ]) {
79+
$0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ]) {
7980
$0 + "-some_other_suffix"
8081
}
8182
}
@@ -102,7 +103,7 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
102103

103104
let ofm = path.appending(component: "ofm.json")
104105
try localFileSystem.writeFileContents(ofm) {
105-
$0 <<< self.makeOutputFileMap(in: path, for: [ magic ])
106+
$0 <<< self.makeOutputFileMap(in: path, module: "MagicKit", for: [ magic ])
106107
}
107108

108109
var driver = try Driver(args: [
@@ -127,7 +128,7 @@ class CrossModuleIncrementalBuildTests: XCTestCase {
127128

128129
let ofm = path.appending(component: "ofm2.json")
129130
try localFileSystem.writeFileContents(ofm) {
130-
$0 <<< self.makeOutputFileMap(in: path, for: [ main ])
131+
$0 <<< self.makeOutputFileMap(in: path, module: "theModule", for: [ main ])
131132
}
132133

133134
var driver = try Driver(args: [

Tests/SwiftDriverTests/DependencyGraphSerializationTests.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker
2222
///
2323
/// Ensure that a round-trip fails when the minor version number changes
2424
func testSerializedVersionChangeDetection() throws {
25-
let mockPath = VirtualPath.absolute(AbsolutePath("/module-dependency-graph"))
25+
let mockPath = try VirtualPath.absolute(AbsolutePath(validating: "/module-dependency-graph"))
2626
let fs = InMemoryFileSystem()
2727
let graph = Self.mockGraphCreator.mockUpAGraph()
2828
let currentVersion = ModuleDependencyGraph.serializedGraphVersion
@@ -37,7 +37,7 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker
3737
try graph.write(
3838
to: mockPath,
3939
on: fs,
40-
buildRecord: info,
40+
buildRecord: graph.buildRecord,
4141
mockSerializedGraphVersion: alteredVersion)
4242
}
4343

@@ -60,7 +60,7 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker
6060
}
6161

6262
func roundTrip(_ originalGraph: ModuleDependencyGraph) throws {
63-
let mockPath = VirtualPath.absolute(AbsolutePath("/module-dependency-graph"))
63+
let mockPath = try VirtualPath.absolute(AbsolutePath(validating: "/module-dependency-graph"))
6464
let fs = InMemoryFileSystem()
6565
let outputFileMap = OutputFileMap.mock(maxIndex: Self.maxIndex)
6666
let diagnosticsEngine = DiagnosticsEngine()
@@ -69,13 +69,14 @@ class DependencyGraphSerializationTests: XCTestCase, ModuleDependencyGraphMocker
6969
outputFileMap: outputFileMap,
7070
compilerVersion: "Swift 99")
7171
try originalGraph.blockingConcurrentMutation {
72-
try originalGraph.write(to: mockPath, on: fs, buildRecord: buildRecord)
72+
try originalGraph.write(
73+
to: mockPath, on: fs,
74+
buildRecord: originalGraph.buildRecord)
7375
}
7476

7577
let info = IncrementalCompilationState.IncrementalDependencyAndInputSetup.mock(outputFileMap: outputFileMap, fileSystem: fs)
76-
let deserializedGraph = try info.blockingConcurrentAccessOrMutation {
77-
try ModuleDependencyGraph.read(from: mockPath,
78-
info: info)!
78+
let deserializedGraph = try info.blockingConcurrentAccessOrMutation {
79+
try XCTUnwrap(ModuleDependencyGraph.read(from: mockPath, info: info))
7980
}
8081

8182
let descsToCompare = [originalGraph, deserializedGraph].map {

0 commit comments

Comments
 (0)