@@ -40,7 +40,7 @@ struct PackageToJS: CommandPlugin {
40
40
41
41
OPTIONS:
42
42
--product <product> Product to build (default: executable target if there's only one)
43
- --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
43
+ --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
44
44
--package-name <name> Name of the package (default: lowercased Package.swift name)
45
45
--explain Whether to explain the build plan
46
46
@@ -75,22 +75,26 @@ struct PackageToJS: CommandPlugin {
75
75
let testLibrary = extractor. extractOption ( named: " test-library " ) . last
76
76
let filter = extractor. extractOption ( named: " filter " )
77
77
let options = Options . parse ( from: & extractor)
78
- return TestOptions ( buildOnly: buildOnly != 0 , listTests: listTests != 0 , testLibrary: testLibrary, filter: filter, options: options)
78
+ return TestOptions (
79
+ buildOnly: buildOnly != 0 , listTests: listTests != 0 , testLibrary: testLibrary,
80
+ filter: filter, options: options
81
+ )
79
82
}
80
83
81
84
static func help( ) -> String {
82
85
return """
83
86
OVERVIEW: Builds and runs tests
84
87
85
88
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] PackageToJS test [options]
86
-
89
+
87
90
OPTIONS:
88
91
--build-only Whether to build only (default: false)
89
92
90
93
EXAMPLES:
91
94
$ swift package --swift-sdk wasm32-unknown-wasi plugin js test
92
95
# Just build tests, don't run them
93
96
$ swift package --swift-sdk wasm32-unknown-wasi plugin js test --build-only
97
+ $ node .build/plugins/PackageToJS/outputs/PackageTests/bin/test.js
94
98
"""
95
99
}
96
100
}
@@ -174,7 +178,8 @@ struct PackageToJS: CommandPlugin {
174
178
175
179
// Build products
176
180
let productName = try buildOptions. product ?? deriveDefaultProduct ( package : context. package )
177
- let build = try buildWasm ( productName: productName, context: context)
181
+ let build = try buildWasm (
182
+ productName: productName, context: context, options: buildOptions. options)
178
183
guard build. succeeded else {
179
184
Self . reportBuildFailure ( build, arguments)
180
185
exit ( 1 )
@@ -214,13 +219,15 @@ struct PackageToJS: CommandPlugin {
214
219
let testOptions = TestOptions . parse ( from: & extractor)
215
220
216
221
if extractor. remainingArguments. count > 0 {
217
- printStderr ( " Unexpected arguments: \( extractor. remainingArguments. joined ( separator: " " ) ) " )
222
+ printStderr (
223
+ " Unexpected arguments: \( extractor. remainingArguments. joined ( separator: " " ) ) " )
218
224
printStderr ( TestOptions . help ( ) )
219
225
exit ( 1 )
220
226
}
221
227
222
228
let productName = " \( context. package . displayName) PackageTests "
223
- let build = try buildWasm ( productName: productName, context: context)
229
+ let build = try buildWasm (
230
+ productName: productName, context: context, options: testOptions. options)
224
231
guard build. succeeded else {
225
232
Self . reportBuildFailure ( build, arguments)
226
233
exit ( 1 )
@@ -274,9 +281,15 @@ struct PackageToJS: CommandPlugin {
274
281
if testOptions. listTests {
275
282
extraArguments += [ " --list-tests " ]
276
283
}
277
- try runTest ( testRunner: testRunner, context: context, extraArguments: extraArguments + testOptions. filter)
278
- try runTest ( testRunner: testRunner, context: context,
279
- extraArguments: [ " --testing-library " , " swift-testing " ] + extraArguments + testOptions. filter. flatMap { [ " --filter " , $0] } )
284
+ try runTest (
285
+ testRunner: testRunner, context: context,
286
+ extraArguments: extraArguments + testOptions. filter
287
+ )
288
+ try runTest (
289
+ testRunner: testRunner, context: context,
290
+ extraArguments: [ " --testing-library " , " swift-testing " ] + extraArguments
291
+ + testOptions. filter. flatMap { [ " --filter " , $0] }
292
+ )
280
293
}
281
294
}
282
295
@@ -292,12 +305,13 @@ struct PackageToJS: CommandPlugin {
292
305
task. currentDirectoryURL = context. pluginWorkDirectoryURL
293
306
try task. run ( )
294
307
task. waitUntilExit ( )
295
- guard task. terminationStatus == 0 else {
308
+ // swift-testing returns EX_UNAVAILABLE (which is 69 in wasi-libc) for "no tests found"
309
+ guard task. terminationStatus == 0 || task. terminationStatus == 69 else {
296
310
throw PackageToJSError ( " Test failed with status \( task. terminationStatus) " )
297
311
}
298
312
}
299
313
300
- private func buildWasm( productName: String , context: PluginContext ) throws
314
+ private func buildWasm( productName: String , context: PluginContext , options : Options ) throws
301
315
-> PackageManager . BuildResult
302
316
{
303
317
var parameters = PackageManager . BuildParameters (
@@ -385,12 +399,7 @@ private func findPackageInDependencies(package: Package, id: Package.ID) -> Pack
385
399
func visit( package : Package ) -> Package ? {
386
400
if visited. contains ( package . id) { return nil }
387
401
visited. insert ( package . id)
388
- for dependency in package . dependencies {
389
- let dependencyPackage = dependency. package
390
- if dependencyPackage. id == id {
391
- return dependencyPackage
392
- }
393
- }
402
+ if package . id == id { return package }
394
403
for dependency in package . dependencies {
395
404
if let found = visit ( package : dependency. package ) {
396
405
return found
0 commit comments