Skip to content

Commit 0958026

Browse files
committed
moaooor integration tests fixes
1 parent aed87a8 commit 0958026

File tree

4 files changed

+125
-123
lines changed

4 files changed

+125
-123
lines changed

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
This source file is part of the Swift.org open source project
2+
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5-
Licensed under Apache License v2.0 with Runtime Library Exception
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
66

7-
See http://swift.org/LICENSE.txt for license information
8-
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
1010

1111
import XCTest
1212
import TSCBasic
@@ -20,35 +20,35 @@ final class BasicTests: XCTestCase {
2020
func testExamplePackageDealer() throws {
2121
try XCTSkipIf(isSelfHosted, "These packages don't use the latest runtime library, which doesn't work with self-hosted builds.")
2222

23-
try withTemporaryDirectory { dir in
24-
let dealerDir = dir.appending(component: "dealer")
25-
try sh("git", "clone", "https://github.com/apple/example-package-dealer", dealerDir)
26-
let build1Output = try sh(swiftBuild, "--package-path", dealerDir).stdout
23+
try withTemporaryDirectory { tempDir in
24+
let packagePath = tempDir.appending(component: "dealer")
25+
try sh("git", "clone", "https://github.com/apple/example-package-dealer", packagePath)
26+
let build1Output = try sh(swiftBuild, "--package-path", packagePath).stdout
2727
// Check the build log.
2828
XCTAssertMatch(build1Output, .contains("Build complete"))
2929

3030
// Verify that the app works.
31-
let dealerOutput = try sh(dealerDir.appending(RelativePath(".build/debug/dealer")), "10").stdout
31+
let dealerOutput = try sh(packagePath.appending(RelativePath(".build/debug/dealer")), "10").stdout
3232
XCTAssertEqual(dealerOutput.filter(\.isPlayingCardSuit).count, 10)
3333

3434
// Verify that the 'git status' is clean after a build.
35-
try localFileSystem.changeCurrentWorkingDirectory(to: dealerDir)
35+
try localFileSystem.changeCurrentWorkingDirectory(to: packagePath)
3636
let gitOutput = try sh("git", "status").stdout
3737
XCTAssertMatch(gitOutput, .contains("nothing to commit, working tree clean"))
3838

3939
// Verify that another 'swift build' does nothing.
40-
let build2Output = try sh(swiftBuild, "--package-path", dealerDir).stdout
40+
let build2Output = try sh(swiftBuild, "--package-path", packagePath).stdout
4141
XCTAssertMatch(build2Output, .contains("Build complete"))
4242
XCTAssertNoMatch(build2Output, .contains("Compiling"))
4343
}
4444
}
4545

4646
func testSwiftBuild() throws {
47-
try withTemporaryDirectory { dir in
48-
let toolDir = dir.appending(component: "tool")
49-
try localFileSystem.createDirectory(toolDir)
47+
try withTemporaryDirectory { tempDir in
48+
let packagePath = tempDir.appending(component: "tool")
49+
try localFileSystem.createDirectory(packagePath)
5050
try localFileSystem.writeFileContents(
51-
toolDir.appending(component: "Package.swift"),
51+
packagePath.appending(component: "Package.swift"),
5252
bytes: ByteString(encodingAsUTF8: """
5353
// swift-tools-version:4.2
5454
import PackageDescription
@@ -61,26 +61,26 @@ final class BasicTests: XCTestCase {
6161
)
6262
"""))
6363
try localFileSystem.writeFileContents(
64-
toolDir.appending(component: "main.swift"),
64+
packagePath.appending(component: "main.swift"),
6565
bytes: ByteString(encodingAsUTF8: #"print("HI")"#))
6666

6767
// Check the build.
68-
let buildOutput = try sh(swiftBuild, "--package-path", toolDir, "-v").stdout
68+
let buildOutput = try sh(swiftBuild, "--package-path", packagePath, "-v").stdout
6969
XCTAssertMatch(buildOutput, .regex("swiftc.* -module-name tool"))
7070

7171
// Verify that the tool exists and works.
72-
let toolOutput = try sh(toolDir.appending(components: ".build", "debug", "tool")).stdout
72+
let toolOutput = try sh(packagePath.appending(components: ".build", "debug", "tool")).stdout
7373
XCTAssertEqual(toolOutput, "HI\n")
7474
}
7575
}
7676

7777
func testSwiftCompiler() throws {
78-
try withTemporaryDirectory { dir in
79-
let helloSourcePath = dir.appending(component: "hello.swift")
78+
try withTemporaryDirectory { tempDir in
79+
let helloSourcePath = tempDir.appending(component: "hello.swift")
8080
try localFileSystem.writeFileContents(
8181
helloSourcePath,
8282
bytes: ByteString(encodingAsUTF8: #"print("hello")"#))
83-
let helloBinaryPath = dir.appending(component: "hello")
83+
let helloBinaryPath = tempDir.appending(component: "hello")
8484
try sh(swiftc, helloSourcePath, "-o", helloBinaryPath)
8585

8686
// Check the file exists.
@@ -96,13 +96,13 @@ final class BasicTests: XCTestCase {
9696
#if swift(<5.5)
9797
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
9898
#endif
99-
100-
try withTemporaryDirectory { dir in
99+
100+
try withTemporaryDirectory { tempDir in
101101
// Create a new package with an executable target.
102-
let projectDir = dir.appending(component: "Project")
103-
try localFileSystem.createDirectory(projectDir)
104-
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "executable")
105-
let buildOutput = try sh(swiftBuild, "--package-path", projectDir).stdout
102+
let packagePath = tempDir.appending(component: "Project")
103+
try localFileSystem.createDirectory(packagePath)
104+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
105+
let buildOutput = try sh(swiftBuild, "--package-path", packagePath).stdout
106106

107107
// Check the build log.
108108
XCTAssertContents(buildOutput) { checker in
@@ -112,7 +112,7 @@ final class BasicTests: XCTestCase {
112112
}
113113

114114
// Verify that the tool was built and works.
115-
let toolOutput = try sh(projectDir.appending(components: ".build", "debug", "Project")).stdout
115+
let toolOutput = try sh(packagePath.appending(components: ".build", "debug", "Project")).stdout
116116
XCTAssertMatch(toolOutput.lowercased(), .contains("hello, world!"))
117117

118118
// Check there were no compile errors or warnings.
@@ -128,12 +128,12 @@ final class BasicTests: XCTestCase {
128128

129129
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
130130

131-
try withTemporaryDirectory { dir in
131+
try withTemporaryDirectory { tempDir in
132132
// Create a new package with an executable target.
133-
let projectDir = dir.appending(component: "Project")
134-
try localFileSystem.createDirectory(projectDir)
135-
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "executable")
136-
let testOutput = try sh(swiftTest, "--package-path", projectDir).stdout
133+
let packagePath = tempDir.appending(component: "Project")
134+
try localFileSystem.createDirectory(packagePath)
135+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
136+
let testOutput = try sh(swiftTest, "--package-path", packagePath).stdout
137137

138138
// Check the test log.
139139
XCTAssertContents(testOutput) { checker in
@@ -149,12 +149,12 @@ final class BasicTests: XCTestCase {
149149
}
150150

151151
func testSwiftPackageInitLib() throws {
152-
try withTemporaryDirectory { dir in
152+
try withTemporaryDirectory { tempDir in
153153
// Create a new package with an executable target.
154-
let projectDir = dir.appending(component: "Project")
155-
try localFileSystem.createDirectory(projectDir)
156-
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "library")
157-
let buildOutput = try sh(swiftBuild, "--package-path", projectDir).stdout
154+
let packagePath = tempDir.appending(component: "Project")
155+
try localFileSystem.createDirectory(packagePath)
156+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
157+
let buildOutput = try sh(swiftBuild, "--package-path", packagePath).stdout
158158

159159
// Check the build log.
160160
XCTAssertMatch(buildOutput, .regex("Compiling .*Project.*"))
@@ -169,12 +169,12 @@ final class BasicTests: XCTestCase {
169169
func testSwiftPackageLibsTests() throws {
170170
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
171171

172-
try withTemporaryDirectory { dir in
172+
try withTemporaryDirectory { tempDir in
173173
// Create a new package with an executable target.
174-
let projectDir = dir.appending(component: "Project")
175-
try localFileSystem.createDirectory(projectDir)
176-
try sh(swiftPackage, "--package-path", projectDir, "init", "--type", "library")
177-
let testOutput = try sh(swiftTest, "--package-path", projectDir).stdout
174+
let packagePath = tempDir.appending(component: "Project")
175+
try localFileSystem.createDirectory(packagePath)
176+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
177+
let testOutput = try sh(swiftTest, "--package-path", packagePath).stdout
178178

179179
// Check the test log.
180180
XCTAssertContents(testOutput) { checker in
@@ -190,11 +190,11 @@ final class BasicTests: XCTestCase {
190190
}
191191

192192
func testSwiftPackageWithSpaces() throws {
193-
try withTemporaryDirectory { dir in
194-
let toolDir = dir.appending(components: "more spaces", "special tool")
195-
try localFileSystem.createDirectory(toolDir, recursive: true)
193+
try withTemporaryDirectory { tempDir in
194+
let packagePath = tempDir.appending(components: "more spaces", "special tool")
195+
try localFileSystem.createDirectory(packagePath, recursive: true)
196196
try localFileSystem.writeFileContents(
197-
toolDir.appending(component: "Package.swift"),
197+
packagePath.appending(component: "Package.swift"),
198198
bytes: ByteString(encodingAsUTF8: """
199199
// swift-tools-version:4.2
200200
import PackageDescription
@@ -207,19 +207,19 @@ final class BasicTests: XCTestCase {
207207
)
208208
"""))
209209
try localFileSystem.writeFileContents(
210-
toolDir.appending(component: "main.swift"),
210+
packagePath.appending(component: "main.swift"),
211211
bytes: ByteString(encodingAsUTF8: #"foo()"#))
212212
try localFileSystem.writeFileContents(
213-
toolDir.appending(component: "some file.swift"),
213+
packagePath.appending(component: "some file.swift"),
214214
bytes: ByteString(encodingAsUTF8: #"func foo() { print("HI") }"#))
215215

216216
// Check the build.
217-
let buildOutput = try sh(swiftBuild, "--package-path", toolDir, "-v").stdout
217+
let buildOutput = try sh(swiftBuild, "--package-path", packagePath, "-v").stdout
218218
XCTAssertMatch(buildOutput, .regex(#"swiftc.* -module-name special_tool .* ".*/more spaces/special tool/some file.swift""#))
219219
XCTAssertMatch(buildOutput, .contains("Build complete"))
220220

221221
// Verify that the tool exists and works.
222-
let toolOutput = try sh(toolDir.appending(components: ".build", "debug", "special tool")).stdout
222+
let toolOutput = try sh(packagePath.appending(components: ".build", "debug", "special tool")).stdout
223223
XCTAssertEqual(toolOutput, "HI\n")
224224
}
225225
}
@@ -229,21 +229,21 @@ final class BasicTests: XCTestCase {
229229
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
230230
#endif
231231

232-
try withTemporaryDirectory { dir in
233-
let toolDir = dir.appending(component: "secho")
234-
try localFileSystem.createDirectory(toolDir)
235-
try sh(swiftPackage, "--package-path", toolDir, "init", "--type", "executable")
232+
try withTemporaryDirectory { tempDir in
233+
let packagePath = tempDir.appending(component: "secho")
234+
try localFileSystem.createDirectory(packagePath)
235+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
236236
// delete any files generated
237-
for entry in try localFileSystem.getDirectoryContents(toolDir.appending(components: "Sources", "secho")) {
238-
try localFileSystem.removeFileTree(toolDir.appending(components: "Sources", "secho", entry))
237+
for entry in try localFileSystem.getDirectoryContents(packagePath.appending(components: "Sources", "secho")) {
238+
try localFileSystem.removeFileTree(packagePath.appending(components: "Sources", "secho", entry))
239239
}
240240
try localFileSystem.writeFileContents(
241-
toolDir.appending(components: "Sources", "secho", "main.swift"),
241+
packagePath.appending(components: "Sources", "secho", "main.swift"),
242242
bytes: ByteString(encodingAsUTF8: """
243243
import Foundation
244244
print(CommandLine.arguments.dropFirst().joined(separator: " "))
245245
"""))
246-
let (runOutput, runError) = try sh(swiftRun, "--package-path", toolDir, "secho", "1", #""two""#)
246+
let (runOutput, runError) = try sh(swiftRun, "--package-path", packagePath, "secho", "1", #""two""#)
247247

248248
// Check the run log.
249249
XCTAssertContents(runError) { checker in
@@ -258,12 +258,12 @@ final class BasicTests: XCTestCase {
258258
func testSwiftTest() throws {
259259
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
260260

261-
try withTemporaryDirectory { dir in
262-
let toolDir = dir.appending(component: "swiftTest")
263-
try localFileSystem.createDirectory(toolDir)
264-
try sh(swiftPackage, "--package-path", toolDir, "init", "--type", "library")
261+
try withTemporaryDirectory { tempDir in
262+
let packagePath = tempDir.appending(component: "swiftTest")
263+
try localFileSystem.createDirectory(packagePath)
264+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
265265
try localFileSystem.writeFileContents(
266-
toolDir.appending(components: "Tests", "swiftTestTests", "MyTests.swift"),
266+
packagePath.appending(components: "Tests", "swiftTestTests", "MyTests.swift"),
267267
bytes: ByteString(encodingAsUTF8: """
268268
import XCTest
269269
@@ -277,7 +277,7 @@ final class BasicTests: XCTestCase {
277277
func testBaz() { }
278278
}
279279
"""))
280-
let testOutput = try sh(swiftTest, "--package-path", toolDir, "--filter", "MyTests.*", "--skip", "testBaz").stderr
280+
let testOutput = try sh(swiftTest, "--package-path", packagePath, "--filter", "MyTests.*", "--skip", "testBaz").stderr
281281

282282
// Check the test log.
283283
XCTAssertContents(testOutput) { checker in
@@ -287,16 +287,16 @@ final class BasicTests: XCTestCase {
287287
}
288288
}
289289
}
290-
290+
291291
func testSwiftTestWithResources() throws {
292292
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
293293

294-
try withTemporaryDirectory { dir in
295-
let toolDir = dir.appending(component: "swiftTestResources")
296-
try localFileSystem.createDirectory(toolDir)
294+
try withTemporaryDirectory { tempDir in
295+
let packagePath = tempDir.appending(component: "swiftTestResources")
296+
try localFileSystem.createDirectory(packagePath)
297297
try localFileSystem.writeFileContents(
298-
toolDir.appending(component: "Package.swift"),
299-
bytes: ByteString(encodingAsUTF8: """
298+
packagePath.appending(component: "Package.swift"),
299+
bytes: ByteString(encodingAsUTF8: """
300300
// swift-tools-version:5.3
301301
import PackageDescription
302302
@@ -309,11 +309,11 @@ final class BasicTests: XCTestCase {
309309
)
310310
""")
311311
)
312-
try localFileSystem.createDirectory(toolDir.appending(component: "Sources"))
313-
try localFileSystem.createDirectory(toolDir.appending(components: "Sources", "AwesomeResources"))
312+
try localFileSystem.createDirectory(packagePath.appending(component: "Sources"))
313+
try localFileSystem.createDirectory(packagePath.appending(components: "Sources", "AwesomeResources"))
314314
try localFileSystem.writeFileContents(
315-
toolDir.appending(components: "Sources", "AwesomeResources", "AwesomeResource.swift"),
316-
bytes: ByteString(encodingAsUTF8: """
315+
packagePath.appending(components: "Sources", "AwesomeResources", "AwesomeResource.swift"),
316+
bytes: ByteString(encodingAsUTF8: """
317317
import Foundation
318318
319319
public struct AwesomeResource {
@@ -325,20 +325,20 @@ final class BasicTests: XCTestCase {
325325
)
326326

327327
try localFileSystem.writeFileContents(
328-
toolDir.appending(components: "Sources", "AwesomeResources", "hello.txt"),
329-
bytes: ByteString(encodingAsUTF8: "hello")
328+
packagePath.appending(components: "Sources", "AwesomeResources", "hello.txt"),
329+
bytes: ByteString(encodingAsUTF8: "hello")
330330
)
331331

332-
try localFileSystem.createDirectory(toolDir.appending(component: "Tests"))
333-
try localFileSystem.createDirectory(toolDir.appending(components: "Tests", "AwesomeResourcesTest"))
332+
try localFileSystem.createDirectory(packagePath.appending(component: "Tests"))
333+
try localFileSystem.createDirectory(packagePath.appending(components: "Tests", "AwesomeResourcesTest"))
334334

335335
try localFileSystem.writeFileContents(
336-
toolDir.appending(components: "Tests", "AwesomeResourcesTest", "world.txt"),
337-
bytes: ByteString(encodingAsUTF8: "world")
336+
packagePath.appending(components: "Tests", "AwesomeResourcesTest", "world.txt"),
337+
bytes: ByteString(encodingAsUTF8: "world")
338338
)
339339

340340
try localFileSystem.writeFileContents(
341-
toolDir.appending(components: "Tests", "AwesomeResourcesTest", "MyTests.swift"),
341+
packagePath.appending(components: "Tests", "AwesomeResourcesTest", "MyTests.swift"),
342342
bytes: ByteString(encodingAsUTF8: """
343343
import XCTest
344344
import Foundation
@@ -354,8 +354,8 @@ final class BasicTests: XCTestCase {
354354
}
355355
}
356356
"""))
357-
358-
let testOutput = try sh(swiftTest, "--package-path", toolDir, "--filter", "MyTests.*").stderr
357+
358+
let testOutput = try sh(swiftTest, "--package-path", packagePath, "--filter", "MyTests.*").stderr
359359

360360
// Check the test log.
361361
XCTAssertContents(testOutput) { checker in

IntegrationTests/Tests/IntegrationTests/Helpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ func initGitRepo(
286286
}
287287

288288
func binaryTargetsFixture(_ closure: (AbsolutePath) throws -> Void) throws {
289-
fixture(name: "BinaryTargets") { prefix in
290-
let inputsPath = prefix.appending(component: "Inputs")
291-
let packagePath = prefix.appending(component: "TestBinary")
289+
fixture(name: "BinaryTargets") { fixturePath in
290+
let inputsPath = fixturePath.appending(component: "Inputs")
291+
let packagePath = fixturePath.appending(component: "TestBinary")
292292

293293
// Generating StaticLibrary.xcframework.
294294
try withTemporaryDirectory { tmpDir in

0 commit comments

Comments
 (0)