Skip to content

Commit 23c6604

Browse files
authored
Merge pull request #100 from ahoppen/remove-testable-imports-stresstester
Remove @testable imports in the stress tester and make all requirements public
2 parents 313cf7f + b67c21c commit 23c6604

File tree

13 files changed

+80
-58
lines changed

13 files changed

+80
-58
lines changed

SourceKitStressTester/Sources/StressTester/Action.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
enum Action: Equatable {
13+
public enum Action: Equatable {
1414
case cursorInfo(offset: Int)
1515
case codeComplete(offset: Int)
1616
case rangeInfo(offset: Int, length: Int)
@@ -21,7 +21,7 @@ enum Action: Equatable {
2121
}
2222

2323
extension Action: CustomStringConvertible {
24-
var description: String {
24+
public var description: String {
2525
switch self {
2626
case .cursorInfo(let offset):
2727
return "CusorInfo at offset \(offset)"
@@ -45,7 +45,7 @@ extension Action: Codable {
4545
enum CodingKeys: String, CodingKey {
4646
case action, offset, length, text
4747
}
48-
enum BaseAction: String, Codable {
48+
public enum BaseAction: String, Codable {
4949
case cursorInfo, codeComplete, rangeInfo, replaceText, typeContextInfo, conformingMethodList, collectExpressionType
5050
}
5151

SourceKitStressTester/Sources/StressTester/ActionGenerators.swift

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
import Foundation
1414
import SwiftSyntax
1515

16-
protocol ActionGenerator {
16+
public protocol ActionGenerator {
1717
func generate(for tree: SourceFileSyntax) -> [Action]
1818
}
1919

2020
extension ActionGenerator {
2121
/// Entrypoint intended for testing purposes only
22-
func generate(for file: URL) -> [Action] {
22+
public func generate(for file: URL) -> [Action] {
2323
let tree = try! SyntaxParser.parse(file)
2424
return generate(for: tree)
2525
}
2626

2727
/// Entrypoint intended for testing purposes only
28-
func generate(for source: String) -> [Action] {
28+
public func generate(for source: String) -> [Action] {
2929
let tree = try! SyntaxParser.parse(source: source)
3030
return generate(for: tree)
3131
}
@@ -102,9 +102,11 @@ extension ActionGenerator {
102102

103103
/// Walks through the provided source files token by token, generating
104104
/// CursorInfo, RangeInfo, and CodeComplete actions as it goes.
105-
final class RequestActionGenerator: ActionGenerator {
105+
public final class RequestActionGenerator: ActionGenerator {
106106

107-
func generate(for tree: SourceFileSyntax) -> [Action] {
107+
public init() {}
108+
109+
public func generate(for tree: SourceFileSyntax) -> [Action] {
108110
let collector = ActionTokenCollector()
109111
let actions: [Action] = [.collectExpressionType] + collector
110112
.collect(from: tree)
@@ -153,8 +155,10 @@ final class RequestActionGenerator: ActionGenerator {
153155

154156
/// Walks through the provided source files token by token, editing each identifier to be misspelled, and
155157
/// unbalancing braces and brackets. Each misspelling or removed brace is restored before the next edit.
156-
final class TypoActionGenerator: ActionGenerator {
157-
func generate(for tree: SourceFileSyntax) -> [Action] {
158+
public final class TypoActionGenerator: ActionGenerator {
159+
public init() {}
160+
161+
public func generate(for tree: SourceFileSyntax) -> [Action] {
158162
let collector = ActionTokenCollector()
159163
return collector.collect(from: tree)
160164
.flatMap { generateActions(for: $0.token) }
@@ -206,9 +210,10 @@ final class TypoActionGenerator: ActionGenerator {
206210
/// Works through the provided source files generating actions to first remove their
207211
/// content, and then add it back again token by token. CursorInfo, RangeInfo and
208212
/// CodeComplete actions are also emitted at applicable locations.
209-
final class BasicRewriteActionGenerator: ActionGenerator {
213+
public final class BasicRewriteActionGenerator: ActionGenerator {
214+
public init() {}
210215

211-
func generate(for tree: SourceFileSyntax) -> [Action] {
216+
public func generate(for tree: SourceFileSyntax) -> [Action] {
212217
let collector = ActionTokenCollector()
213218
let tokens = collector.collect(from: tree)
214219
return [.replaceText(offset: 0, length: tree.endPosition.utf8Offset, text: "")] +
@@ -232,8 +237,10 @@ final class BasicRewriteActionGenerator: ActionGenerator {
232237
}
233238
}
234239

235-
final class ConcurrentRewriteActionGenerator: ActionGenerator {
236-
func generate(for tree: SourceFileSyntax) -> [Action] {
240+
public final class ConcurrentRewriteActionGenerator: ActionGenerator {
241+
public init() {}
242+
243+
public func generate(for tree: SourceFileSyntax) -> [Action] {
237244
var actions: [Action] = [.replaceText(offset: 0, length: tree.totalLength.utf8Length, text: "")]
238245
let groups = tree.statements.map { statement -> ActionTokenGroup in
239246
let collector = ActionTokenCollector()
@@ -296,9 +303,10 @@ final class ConcurrentRewriteActionGenerator: ActionGenerator {
296303
/// re-introducing it token by token, from the most deeply nested token to the
297304
/// least. Actions are emitted before and after each inserted token as it is
298305
/// inserted.
299-
final class InsideOutRewriteActionGenerator: ActionGenerator {
306+
public final class InsideOutRewriteActionGenerator: ActionGenerator {
307+
public init() {}
300308

301-
func generate(for tree: SourceFileSyntax) -> [Action] {
309+
public func generate(for tree: SourceFileSyntax) -> [Action] {
302310
var actions: [Action] = [.replaceText(offset: 0, length: tree.totalLength.utf8Length, text: "")]
303311
let collector = ActionTokenCollector()
304312
let actionTokens = collector.collect(from: tree)

SourceKitStressTester/Sources/StressTester/SourceKitDocument.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,20 @@ struct SourceKitDocument {
358358
}
359359

360360
/// Tracks the current state of a source file
361-
struct SourceState {
362-
let mode: RewriteMode
363-
var source: String
364-
var wasModified: Bool
361+
public struct SourceState {
362+
public let mode: RewriteMode
363+
public var source: String
364+
public var wasModified: Bool
365365

366-
init(rewriteMode: RewriteMode, content source: String, wasModified: Bool = false) {
366+
public init(rewriteMode: RewriteMode, content source: String, wasModified: Bool = false) {
367367
self.mode = rewriteMode
368368
self.source = source
369369
self.wasModified = wasModified
370370
}
371371

372372
/// - returns: true if source state changed
373373
@discardableResult
374-
mutating func replace(offset: Int, length: Int, with text: String) -> Bool {
374+
public mutating func replace(offset: Int, length: Int, with text: String) -> Bool {
375375
let bytes = source.utf8
376376
let prefix = bytes.prefix(upTo: bytes.index(bytes.startIndex, offsetBy: offset))
377377
let suffix = bytes.suffix(from: bytes.index(bytes.startIndex, offsetBy: offset + length))

SourceKitStressTester/Sources/StressTester/StressTester.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import SwiftLang
1515
import SwiftSyntax
1616
import Common
1717

18-
struct StressTester {
18+
public struct StressTester {
1919
let file: URL
2020
let source: String
2121
let compilerArgs: [String]
2222
let options: StressTesterOptions
2323
let connection: SourceKitdService
2424

25-
init(for file: URL, compilerArgs: [String], options: StressTesterOptions) {
25+
public init(for file: URL, compilerArgs: [String], options: StressTesterOptions) {
2626
self.source = try! String(contentsOf: file, encoding: .utf8)
2727
self.file = file
2828
self.compilerArgs = compilerArgs.flatMap { DriverFileList(at: $0)?.paths ?? [$0] }
@@ -99,7 +99,7 @@ struct StressTester {
9999
return (state, page)
100100
}
101101

102-
func run() throws {
102+
public func run() throws {
103103
var document = SourceKitDocument(file.path, args: compilerArgs, connection: connection, containsErrors: true)
104104

105105
// compute the actions for the entire tree
@@ -176,13 +176,15 @@ private extension SourceKitdUID {
176176
static let kind_CompletionContextThisModule = SourceKitdUID(string: "source.codecompletion.context.thismodule")
177177
}
178178

179-
struct StressTesterOptions {
180-
var astBuildLimit: Int? = nil
181-
var requests: RequestSet = .all
182-
var rewriteMode: RewriteMode = .none
183-
var conformingMethodsTypeList = ["s:SQ", "s:SH"] // Equatable and Hashable
184-
var responseHandler: ((SourceKitResponseData) throws -> Void)? = nil
185-
var page = Page(1, of: 1)
179+
public struct StressTesterOptions {
180+
public init() {}
181+
182+
public var astBuildLimit: Int? = nil
183+
public var requests: RequestSet = .all
184+
public var rewriteMode: RewriteMode = .none
185+
public var conformingMethodsTypeList = ["s:SQ", "s:SH"] // Equatable and Hashable
186+
public var responseHandler: ((SourceKitResponseData) throws -> Void)? = nil
187+
public var page = Page(1, of: 1)
186188
}
187189

188190
public struct RequestSet: OptionSet {

SourceKitStressTester/Sources/StressTester/StressTesterTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public struct StressTesterTool {
8282
return try process(results)
8383
}
8484

85-
func parse() throws -> ArgumentParser.Result {
85+
public func parse() throws -> ArgumentParser.Result {
8686
let result = try parser.parse(arguments)
8787

8888
// validate arguments

SourceKitStressTester/Sources/SwiftCWrapper/ExpectedIssue.swift

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@
1212

1313
import Common
1414

15-
struct ExpectedIssue: Equatable, Codable {
16-
let applicableConfigs: Set<String>
17-
let issueUrl: String
18-
let path: String
19-
let modification: String?
20-
let issueDetail: IssueDetail
15+
public struct ExpectedIssue: Equatable, Codable {
16+
public let applicableConfigs: Set<String>
17+
public let issueUrl: String
18+
public let path: String
19+
public let modification: String?
20+
public let issueDetail: IssueDetail
21+
22+
public init(applicableConfigs: Set<String>, issueUrl: String, path: String,
23+
modification: String?, issueDetail: IssueDetail) {
24+
self.applicableConfigs = applicableConfigs
25+
self.issueUrl = issueUrl
26+
self.path = path
27+
self.modification = modification
28+
self.issueDetail = issueDetail
29+
}
2130

2231
/// Checks if this expected issue matches the given issue
2332
///
2433
/// - parameters:
2534
/// - issue: the issue to match against
2635
/// - returns: true if the issue matches
27-
func matches(_ issue: StressTesterIssue) -> Bool {
36+
public func matches(_ issue: StressTesterIssue) -> Bool {
2837
switch issue {
2938
case .failed(let sourceKitError):
3039
return matches(sourceKitError.request)
@@ -132,7 +141,7 @@ struct ExpectedIssue: Equatable, Codable {
132141
}
133142
}
134143

135-
extension ExpectedIssue {
144+
public extension ExpectedIssue {
136145

137146
init(matching stressTesterIssue: StressTesterIssue, issueUrl: String, config: String) {
138147
self.issueUrl = issueUrl
@@ -202,7 +211,7 @@ extension ExpectedIssue {
202211
case semanticRefactoring(offset: Int?, refactoring: String?)
203212
case stressTesterCrash(status: Int32?, arguments: String?)
204213

205-
init(from decoder: Decoder) throws {
214+
public init(from decoder: Decoder) throws {
206215
let container = try decoder.container(keyedBy: CodingKeys.self)
207216
switch try container.decode(RequestBase.self, forKey: .kind) {
208217
case .editorOpen:
@@ -250,7 +259,7 @@ extension ExpectedIssue {
250259
}
251260
}
252261

253-
func encode(to encoder: Encoder) throws {
262+
public func encode(to encoder: Encoder) throws {
254263
var container = encoder.container(keyedBy: CodingKeys.self)
255264
switch self {
256265
case .editorOpen:

SourceKitStressTester/Sources/SwiftCWrapper/FailFastOperationQueue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class FailFastOperationQueue<Item: Operation> {
1818
private let operations: [Item]
1919
private let completionHandler: (Int, Item, Int, Int) -> Bool
2020

21-
init(operations: [Item], maxWorkers: Int? = nil,
21+
public init(operations: [Item], maxWorkers: Int? = nil,
2222
completionHandler: @escaping (Int, Item, Int, Int) -> Bool) {
2323
self.operations = operations
2424
self.completionHandler = completionHandler
@@ -30,7 +30,7 @@ public final class FailFastOperationQueue<Item: Operation> {
3030
}
3131
}
3232

33-
func waitUntilFinished() {
33+
public func waitUntilFinished() {
3434
let group = DispatchGroup()
3535
var completed = 0
3636

SourceKitStressTester/Sources/SwiftCWrapper/IssueManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Foundation
1515

1616
/// Keeps track of the detected failures and their status (expected/unexpected)
1717
/// across multiple wrapper invocations
18-
struct IssueManager {
18+
public struct IssueManager {
1919
let activeConfig: String
2020
let expectedIssuesFile: URL
2121
let resultsFile: URL

SourceKitStressTester/Sources/SwiftCWrapper/SwiftCWrapper.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import class TSCUtility.PercentProgressAnimation
1616
import protocol TSCUtility.ProgressAnimationProtocol
1717
import TSCBasic
1818

19-
struct SwiftCWrapper {
19+
public struct SwiftCWrapper {
2020
let arguments: [String]
2121
let swiftcPath: String
2222
let stressTesterPath: String
@@ -31,7 +31,7 @@ struct SwiftCWrapper {
3131
let failFast: Bool
3232
let suppressOutput: Bool
3333

34-
init(swiftcArgs: [String], swiftcPath: String, stressTesterPath: String, astBuildLimit: Int?, rewriteModes: [RewriteMode]?, requestKinds: [RequestKind]?, conformingMethodTypes: [String]?, ignoreIssues: Bool, issueManager: IssueManager?, maxJobs: Int?, dumpResponsesPath: String?, failFast: Bool, suppressOutput: Bool) {
34+
public init(swiftcArgs: [String], swiftcPath: String, stressTesterPath: String, astBuildLimit: Int?, rewriteModes: [RewriteMode]?, requestKinds: [RequestKind]?, conformingMethodTypes: [String]?, ignoreIssues: Bool, issueManager: IssueManager?, maxJobs: Int?, dumpResponsesPath: String?, failFast: Bool, suppressOutput: Bool) {
3535
self.arguments = swiftcArgs
3636
self.swiftcPath = swiftcPath
3737
self.stressTesterPath = stressTesterPath
@@ -47,7 +47,7 @@ struct SwiftCWrapper {
4747
self.dumpResponsesPath = dumpResponsesPath
4848
}
4949

50-
var swiftFiles: [(String, size: Int)] {
50+
public var swiftFiles: [(String, size: Int)] {
5151
let dependencyPaths = ["/.build/checkouts/", "/Pods/", "/Carthage/Checkouts"]
5252
return arguments
5353
.flatMap { DriverFileList(at: $0)?.paths ?? [$0] }
@@ -233,7 +233,7 @@ private struct OrderingBuffer<T> {
233233
}
234234
}
235235

236-
enum RequestKind: String, CaseIterable {
236+
public enum RequestKind: String, CaseIterable {
237237
case cursorInfo = "CursorInfo"
238238
case rangeInfo = "RangeInfo"
239239
case codeComplete = "CodeComplete"
@@ -278,11 +278,11 @@ fileprivate extension TimeInterval {
278278
}
279279
}
280280

281-
enum StressTesterIssue: CustomStringConvertible {
281+
public enum StressTesterIssue: CustomStringConvertible {
282282
case failed(SourceKitError)
283283
case errored(status: Int32, file: String, arguments: String)
284284

285-
var description: String {
285+
public var description: String {
286286
switch self {
287287
case .failed(let error):
288288
return String(describing: error)

SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import Foundation
1414
import XCTest
15-
@testable import StressTester
15+
import StressTester
1616
import SwiftLang
1717
import Common
1818

0 commit comments

Comments
 (0)