1
1
/*
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
3
3
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
6
6
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
+ */
10
10
11
11
import XCTest
12
12
import TSCBasic
@@ -20,35 +20,35 @@ final class BasicTests: XCTestCase {
20
20
func testExamplePackageDealer( ) throws {
21
21
try XCTSkipIf ( isSelfHosted, " These packages don't use the latest runtime library, which doesn't work with self-hosted builds. " )
22
22
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
27
27
// Check the build log.
28
28
XCTAssertMatch ( build1Output, . contains( " Build complete " ) )
29
29
30
30
// 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
32
32
XCTAssertEqual ( dealerOutput. filter ( \. isPlayingCardSuit) . count, 10 )
33
33
34
34
// Verify that the 'git status' is clean after a build.
35
- try localFileSystem. changeCurrentWorkingDirectory ( to: dealerDir )
35
+ try localFileSystem. changeCurrentWorkingDirectory ( to: packagePath )
36
36
let gitOutput = try sh ( " git " , " status " ) . stdout
37
37
XCTAssertMatch ( gitOutput, . contains( " nothing to commit, working tree clean " ) )
38
38
39
39
// 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
41
41
XCTAssertMatch ( build2Output, . contains( " Build complete " ) )
42
42
XCTAssertNoMatch ( build2Output, . contains( " Compiling " ) )
43
43
}
44
44
}
45
45
46
46
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 )
50
50
try localFileSystem. writeFileContents (
51
- toolDir . appending ( component: " Package.swift " ) ,
51
+ packagePath . appending ( component: " Package.swift " ) ,
52
52
bytes: ByteString ( encodingAsUTF8: """
53
53
// swift-tools-version:4.2
54
54
import PackageDescription
@@ -61,26 +61,26 @@ final class BasicTests: XCTestCase {
61
61
)
62
62
""" ) )
63
63
try localFileSystem. writeFileContents (
64
- toolDir . appending ( component: " main.swift " ) ,
64
+ packagePath . appending ( component: " main.swift " ) ,
65
65
bytes: ByteString ( encodingAsUTF8: #"print("HI")"# ) )
66
66
67
67
// 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
69
69
XCTAssertMatch ( buildOutput, . regex( " swiftc.* -module-name tool " ) )
70
70
71
71
// 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
73
73
XCTAssertEqual ( toolOutput, " HI \n " )
74
74
}
75
75
}
76
76
77
77
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 " )
80
80
try localFileSystem. writeFileContents (
81
81
helloSourcePath,
82
82
bytes: ByteString ( encodingAsUTF8: #"print("hello")"# ) )
83
- let helloBinaryPath = dir . appending ( component: " hello " )
83
+ let helloBinaryPath = tempDir . appending ( component: " hello " )
84
84
try sh ( swiftc, helloSourcePath, " -o " , helloBinaryPath)
85
85
86
86
// Check the file exists.
@@ -96,13 +96,13 @@ final class BasicTests: XCTestCase {
96
96
#if swift(<5.5)
97
97
try XCTSkipIf ( true , " skipping because host compiler doesn't support '-entry-point-function-name' " )
98
98
#endif
99
-
100
- try withTemporaryDirectory { dir in
99
+
100
+ try withTemporaryDirectory { tempDir in
101
101
// 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
106
106
107
107
// Check the build log.
108
108
XCTAssertContents ( buildOutput) { checker in
@@ -112,7 +112,7 @@ final class BasicTests: XCTestCase {
112
112
}
113
113
114
114
// 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
116
116
XCTAssertMatch ( toolOutput. lowercased ( ) , . contains( " hello, world! " ) )
117
117
118
118
// Check there were no compile errors or warnings.
@@ -128,12 +128,12 @@ final class BasicTests: XCTestCase {
128
128
129
129
try XCTSkip ( " FIXME: swift-test invocations are timing out in Xcode and self-hosted CI " )
130
130
131
- try withTemporaryDirectory { dir in
131
+ try withTemporaryDirectory { tempDir in
132
132
// 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
137
137
138
138
// Check the test log.
139
139
XCTAssertContents ( testOutput) { checker in
@@ -149,12 +149,12 @@ final class BasicTests: XCTestCase {
149
149
}
150
150
151
151
func testSwiftPackageInitLib( ) throws {
152
- try withTemporaryDirectory { dir in
152
+ try withTemporaryDirectory { tempDir in
153
153
// 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
158
158
159
159
// Check the build log.
160
160
XCTAssertMatch ( buildOutput, . regex( " Compiling .*Project.* " ) )
@@ -169,12 +169,12 @@ final class BasicTests: XCTestCase {
169
169
func testSwiftPackageLibsTests( ) throws {
170
170
try XCTSkip ( " FIXME: swift-test invocations are timing out in Xcode and self-hosted CI " )
171
171
172
- try withTemporaryDirectory { dir in
172
+ try withTemporaryDirectory { tempDir in
173
173
// 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
178
178
179
179
// Check the test log.
180
180
XCTAssertContents ( testOutput) { checker in
@@ -190,11 +190,11 @@ final class BasicTests: XCTestCase {
190
190
}
191
191
192
192
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 )
196
196
try localFileSystem. writeFileContents (
197
- toolDir . appending ( component: " Package.swift " ) ,
197
+ packagePath . appending ( component: " Package.swift " ) ,
198
198
bytes: ByteString ( encodingAsUTF8: """
199
199
// swift-tools-version:4.2
200
200
import PackageDescription
@@ -207,19 +207,19 @@ final class BasicTests: XCTestCase {
207
207
)
208
208
""" ) )
209
209
try localFileSystem. writeFileContents (
210
- toolDir . appending ( component: " main.swift " ) ,
210
+ packagePath . appending ( component: " main.swift " ) ,
211
211
bytes: ByteString ( encodingAsUTF8: #"foo()"# ) )
212
212
try localFileSystem. writeFileContents (
213
- toolDir . appending ( component: " some file.swift " ) ,
213
+ packagePath . appending ( component: " some file.swift " ) ,
214
214
bytes: ByteString ( encodingAsUTF8: #"func foo() { print("HI") }"# ) )
215
215
216
216
// 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
218
218
XCTAssertMatch ( buildOutput, . regex( #"swiftc.* -module-name special_tool .* ".*/more spaces/special tool/some file.swift""# ) )
219
219
XCTAssertMatch ( buildOutput, . contains( " Build complete " ) )
220
220
221
221
// 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
223
223
XCTAssertEqual ( toolOutput, " HI \n " )
224
224
}
225
225
}
@@ -229,21 +229,21 @@ final class BasicTests: XCTestCase {
229
229
try XCTSkipIf ( true , " skipping because host compiler doesn't support '-entry-point-function-name' " )
230
230
#endif
231
231
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 " )
236
236
// 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) )
239
239
}
240
240
try localFileSystem. writeFileContents (
241
- toolDir . appending ( components: " Sources " , " secho " , " main.swift " ) ,
241
+ packagePath . appending ( components: " Sources " , " secho " , " main.swift " ) ,
242
242
bytes: ByteString ( encodingAsUTF8: """
243
243
import Foundation
244
244
print(CommandLine.arguments.dropFirst().joined(separator: " " ))
245
245
""" ) )
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""# )
247
247
248
248
// Check the run log.
249
249
XCTAssertContents ( runError) { checker in
@@ -258,12 +258,12 @@ final class BasicTests: XCTestCase {
258
258
func testSwiftTest( ) throws {
259
259
try XCTSkip ( " FIXME: swift-test invocations are timing out in Xcode and self-hosted CI " )
260
260
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 " )
265
265
try localFileSystem. writeFileContents (
266
- toolDir . appending ( components: " Tests " , " swiftTestTests " , " MyTests.swift " ) ,
266
+ packagePath . appending ( components: " Tests " , " swiftTestTests " , " MyTests.swift " ) ,
267
267
bytes: ByteString ( encodingAsUTF8: """
268
268
import XCTest
269
269
@@ -277,7 +277,7 @@ final class BasicTests: XCTestCase {
277
277
func testBaz() { }
278
278
}
279
279
""" ) )
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
281
281
282
282
// Check the test log.
283
283
XCTAssertContents ( testOutput) { checker in
@@ -287,16 +287,16 @@ final class BasicTests: XCTestCase {
287
287
}
288
288
}
289
289
}
290
-
290
+
291
291
func testSwiftTestWithResources( ) throws {
292
292
try XCTSkip ( " FIXME: swift-test invocations are timing out in Xcode and self-hosted CI " )
293
293
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 )
297
297
try localFileSystem. writeFileContents (
298
- toolDir . appending ( component: " Package.swift " ) ,
299
- bytes: ByteString ( encodingAsUTF8: """
298
+ packagePath . appending ( component: " Package.swift " ) ,
299
+ bytes: ByteString ( encodingAsUTF8: """
300
300
// swift-tools-version:5.3
301
301
import PackageDescription
302
302
@@ -309,11 +309,11 @@ final class BasicTests: XCTestCase {
309
309
)
310
310
""" )
311
311
)
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 " ) )
314
314
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: """
317
317
import Foundation
318
318
319
319
public struct AwesomeResource {
@@ -325,20 +325,20 @@ final class BasicTests: XCTestCase {
325
325
)
326
326
327
327
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 " )
330
330
)
331
331
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 " ) )
334
334
335
335
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 " )
338
338
)
339
339
340
340
try localFileSystem. writeFileContents (
341
- toolDir . appending ( components: " Tests " , " AwesomeResourcesTest " , " MyTests.swift " ) ,
341
+ packagePath . appending ( components: " Tests " , " AwesomeResourcesTest " , " MyTests.swift " ) ,
342
342
bytes: ByteString ( encodingAsUTF8: """
343
343
import XCTest
344
344
import Foundation
@@ -354,8 +354,8 @@ final class BasicTests: XCTestCase {
354
354
}
355
355
}
356
356
""" ) )
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
359
359
360
360
// Check the test log.
361
361
XCTAssertContents ( testOutput) { checker in
0 commit comments