Skip to content

Commit aa7a755

Browse files
author
David Ungar
committed
Move mocking functions to the testing directory
1 parent eab0e13 commit aa7a755

File tree

5 files changed

+86
-61
lines changed

5 files changed

+86
-61
lines changed

Sources/SwiftDriver/IncrementalCompilation/DependencyKey.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//===------------------- DependencyKey.swift ------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
112

213
import Foundation
314
import TSCBasic

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -353,23 +353,6 @@ extension ModuleDependencyGraph {
353353
}
354354
}
355355

356-
// MARK: - utilities for unit testing
357-
extension ModuleDependencyGraph {
358-
/// Testing only
359-
/*@_spi(Testing)*/ public func haveAnyNodesBeenTraversed(inMock i: Int) -> Bool {
360-
let dependencySource = DependencySource(mock: i)
361-
// optimization
362-
if let fileNode = nodeFinder.findFileInterfaceNode(forMock: dependencySource),
363-
isTraced(fileNode) {
364-
return true
365-
}
366-
if let nodes = nodeFinder.findNodes(for: dependencySource)?.values,
367-
nodes.contains(where: isTraced) {
368-
return true
369-
}
370-
return false
371-
}
372-
}
373356
// MARK: - verification
374357
extension ModuleDependencyGraph {
375358
@discardableResult

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/DependencySource.swift

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@ public struct DependencySource: Hashable, CustomStringConvertible {
4646
}
4747
}
4848

49-
// MARK: - mocking
50-
extension DependencySource {
51-
/*@_spi(Testing)*/ public init(mock i: Int) {
52-
self.init(try! VirtualPath(path: String(i) + "." + FileType.swiftDeps.rawValue))!
53-
}
54-
55-
/*@_spi(Testing)*/ public var mockID: Int {
56-
Int(file.basenameWithoutExt)!
57-
}
58-
}
59-
6049
// MARK: - reading
6150
extension DependencySource {
6251
/// Throws if a read error
@@ -79,17 +68,7 @@ extension DependencySource {
7968
return graphIfPresent
8069
}
8170
}
82-
// MARK: - testing
83-
extension DependencySource {
84-
/*@_spi(Testing)*/
85-
public var sourceFileProvideNameForMockDependencySource: String {
86-
file.name
87-
}
88-
/*@_spi(Testing)*/
89-
public var interfaceHashForMockDependencySource: String {
90-
file.name
91-
}
92-
}
71+
9372
// MARK: - comparing
9473
extension DependencySource: Comparable {
9574
public static func < (lhs: Self, rhs: Self) -> Bool {

Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraphParts/NodeFinder.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ extension ModuleDependencyGraph {
4040
// MARK: - finding
4141

4242
extension ModuleDependencyGraph.NodeFinder {
43-
func findFileInterfaceNode(
44-
forMock dependencySource: DependencySource
45-
) -> Graph.Node? {
46-
let fileKey = DependencyKey(fileKeyForMockDependencySource: dependencySource)
47-
return findNode((dependencySource, fileKey))
48-
}
4943
func findNode(_ mapKey: (DependencySource?, DependencyKey)) -> Graph.Node? {
5044
nodeMap[mapKey]
5145
}
@@ -235,22 +229,6 @@ extension ModuleDependencyGraph.NodeFinder {
235229
fatalError("An expat is not defined anywhere and thus cannot be used")
236230
}
237231
}
238-
// MARK: - key helpers
239-
240-
fileprivate extension DependencyKey {
241-
init(fileKeyForMockDependencySource dependencySource: DependencySource) {
242-
self.init(aspect: .interface,
243-
designator:
244-
.sourceFileProvide(name: dependencySource.sourceFileProvidesNameForMocking)
245-
)
246-
}
247-
}
248-
fileprivate extension DependencySource {
249-
var sourceFileProvidesNameForMocking: String {
250-
// Only when mocking are these two guaranteed to be the same
251-
file.name
252-
}
253-
}
254232

255233
// MARK: - Checking Serialization
256234
extension ModuleDependencyGraph.NodeFinder {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//===------------- MockingIncrementalCompilation.swift --------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@testable import SwiftDriver
14+
15+
// MARK: - utilities for unit testing
16+
extension ModuleDependencyGraph {
17+
func haveAnyNodesBeenTraversed(inMock i: Int) -> Bool {
18+
let dependencySource = DependencySource(mock: i)
19+
// optimization
20+
if let fileNode = nodeFinder.findFileInterfaceNode(forMock: dependencySource),
21+
isTraced(fileNode) {
22+
return true
23+
}
24+
if let nodes = nodeFinder.findNodes(for: dependencySource)?.values,
25+
nodes.contains(where: isTraced) {
26+
return true
27+
}
28+
return false
29+
}
30+
}
31+
32+
// MARK: - mocking
33+
extension DependencySource {
34+
init(mock i: Int) {
35+
self.init(try! VirtualPath(path: String(i) + "." + FileType.swiftDeps.rawValue))!
36+
}
37+
38+
var mockID: Int {
39+
Int(file.basenameWithoutExt)!
40+
}
41+
42+
var sourceFileProvideNameForMockDependencySource: String {
43+
file.name
44+
}
45+
46+
var interfaceHashForMockDependencySource: String {
47+
file.name
48+
}
49+
}
50+
51+
extension ModuleDependencyGraph.NodeFinder {
52+
func findFileInterfaceNode(
53+
forMock dependencySource: DependencySource
54+
) -> Graph.Node? {
55+
let fileKey = DependencyKey(fileKeyForMockDependencySource: dependencySource)
56+
return findNode((dependencySource, fileKey))
57+
}
58+
}
59+
60+
fileprivate extension DependencyKey {
61+
init(fileKeyForMockDependencySource dependencySource: DependencySource) {
62+
self.init(aspect: .interface,
63+
designator:
64+
.sourceFileProvide(name: dependencySource.sourceFileProvidesNameForMocking)
65+
)
66+
}
67+
}
68+
69+
fileprivate extension DependencySource {
70+
var sourceFileProvidesNameForMocking: String {
71+
// Only when mocking are these two guaranteed to be the same
72+
file.name
73+
}
74+
}

0 commit comments

Comments
 (0)