Skip to content

Commit 6574d35

Browse files
committed
Change unit test fixture to not fetch packages (such as swift-argument-parser) while running.
1 parent 4b19539 commit 6574d35

File tree

4 files changed

+21
-33
lines changed

4 files changed

+21
-33
lines changed

Fixtures/Miscellaneous/Extensions/MySourceGenExtension/Package.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ let package = Package(
1010
// target: "MySourceGenExt"
1111
// )
1212
],
13-
dependencies: [
14-
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")),
15-
],
1613
targets: [
1714
// A local tool that uses an extension.
1815
.executableTarget(
1916
name: "MyLocalTool",
2017
dependencies: [
2118
"MySourceGenExt",
22-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
2319
"MySourceGenTool"
2420
]
2521
),
@@ -36,7 +32,6 @@ let package = Package(
3632
name: "MySourceGenTool",
3733
dependencies: [
3834
"MySourceGenToolLib",
39-
.product(name: "ArgumentParser", package: "swift-argument-parser")
4035
]
4136
),
4237
// A library used by MySourceGenTool (not the client).

Fixtures/Miscellaneous/Extensions/MySourceGenExtension/Sources/MySourceGenExt/extension.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import PackageExtension
22

3-
43
for inputPath in targetBuildContext.otherFiles {
5-
guard inputPath.hasSuffix(".dat") else { continue }
6-
7-
let outputPath = targetBuildContext.outputDir.appending(inputPath.basename + ".swift")
8-
print("inputPath: \(inputPath)")
9-
print("outputPath: \(outputPath)")
10-
4+
guard inputPath.suffix == ".dat" else { continue }
5+
let outputName = inputPath.basename + ".swift"
6+
let outputPath = targetBuildContext.outputDir.appending(outputName)
117
commandConstructor.createCommand(
128
displayName:
13-
"MySourceGenTooling \(outputPath.string)",
9+
"MySourceGenTooling \(inputPath)",
1410
executable:
1511
try targetBuildContext.lookupTool(named: "MySourceGenTool"),
1612
arguments: [
17-
inputPath.string,
18-
outputPath.string
13+
"\(inputPath)",
14+
"\(outputPath)"
1915
],
2016
inputPaths: [
2117
inputPath,
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
import ArgumentParser
21
import Foundation
32
import MySourceGenToolLib
43

5-
// Sample source generator tool that just emits the hex representation of the contents of a file as a quoted string.
6-
struct MySourceGenTool: ParsableCommand {
7-
@Argument() var inputFile: String
8-
@Argument() var outputFile: String
9-
10-
func run() {
11-
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
12-
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
13-
let outputString = "public var data = \(dataAsHex.quotedForSourceCode)\n"
14-
let outputData = outputString.data(using: .utf8)
15-
FileManager.default.createFile(atPath: outputFile, contents: outputData)
16-
}
4+
// Sample source generator tool that just emits the hex representation of the contents of a file as a quoted string. The input file is the first argument and the output file is the second.
5+
if ProcessInfo.processInfo.arguments.count != 3 {
6+
print("usage: MySourceGenTool <input> <output>")
7+
exit(1)
178
}
9+
let inputFile = ProcessInfo.processInfo.arguments[1]
10+
let outputFile = ProcessInfo.processInfo.arguments[2]
1811

19-
MySourceGenTool.main()
12+
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
13+
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
14+
let outputString = "public var data = \(dataAsHex.quotedForSourceCode)\n"
15+
let outputData = outputString.data(using: .utf8)
16+
FileManager.default.createFile(atPath: outputFile, contents: outputData)

Tests/FunctionalTests/ExtensionTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class ExtensionTests: XCTestCase {
1919
fixture(name: "Miscellaneous/Extensions/MySourceGenExtension") { prefix in
2020
do {
2121
let (stdout, _) = try executeSwiftBuild(prefix, configuration: .Debug, env: ["SWIFTPM_ENABLE_EXTENSION_TARGETS": "1"])
22-
XCTAssert(stdout.contains("Linking MySourceGenTool"))
23-
XCTAssert(stdout.contains("MySourceGenTooling Foo.dat.swift"))
24-
XCTAssert(stdout.contains("Linking MyLocalTool"))
25-
XCTAssert(stdout.contains("Build Completed"))
22+
XCTAssert(stdout.contains("Linking MySourceGenTool"), "stdout:\n\(stdout)")
23+
XCTAssert(stdout.contains("MySourceGenTooling Foo.dat"), "stdout:\n\(stdout)")
24+
XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)")
25+
XCTAssert(stdout.contains("Build Completed"), "stdout:\n\(stdout)")
2626
}
2727
catch {
2828
print(error)

0 commit comments

Comments
 (0)