@@ -61,28 +61,31 @@ struct PackageToJS {
61
61
var testJsArguments : [ String ] = [ ]
62
62
var testLibraryArguments : [ String ] = [ ]
63
63
if testOptions. listTests {
64
- testLibraryArguments += [ " --list-tests " ]
64
+ testLibraryArguments. append ( " --list-tests " )
65
65
}
66
66
if let prelude = testOptions. prelude {
67
67
let preludeURL = URL ( fileURLWithPath: prelude, relativeTo: URL ( fileURLWithPath: FileManager . default. currentDirectoryPath) )
68
- testJsArguments += [ " --prelude " , preludeURL. path]
68
+ testJsArguments. append ( " --prelude " )
69
+ testJsArguments. append ( preludeURL. path)
69
70
}
70
71
if let environment = testOptions. environment {
71
- testJsArguments += [ " --environment " , environment]
72
+ testJsArguments. append ( " --environment " )
73
+ testJsArguments. append ( environment)
72
74
}
73
75
if testOptions. inspect {
74
- testJsArguments += [ " --inspect " ]
76
+ testJsArguments. append ( " --inspect " )
75
77
}
76
78
77
79
let xctestCoverageFile = outputDir. appending ( path: " XCTest.profraw " )
78
80
do {
79
81
var extraArguments = testJsArguments
80
82
if testOptions. packageOptions. enableCodeCoverage {
81
- extraArguments += [ " --coverage-file " , xctestCoverageFile. path]
83
+ extraArguments. append ( " --coverage-file " )
84
+ extraArguments. append ( xctestCoverageFile. path)
82
85
}
83
- extraArguments += [ " -- " ]
84
- extraArguments += testLibraryArguments
85
- extraArguments += testOptions. filter
86
+ extraArguments. append ( " -- " )
87
+ extraArguments. append ( contentsOf : testLibraryArguments)
88
+ extraArguments. append ( contentsOf : testOptions. filter)
86
89
87
90
try PackageToJS . runSingleTestingLibrary (
88
91
testRunner: testRunner, currentDirectoryURL: currentDirectoryURL,
@@ -95,11 +98,17 @@ struct PackageToJS {
95
98
do {
96
99
var extraArguments = testJsArguments
97
100
if testOptions. packageOptions. enableCodeCoverage {
98
- extraArguments += [ " --coverage-file " , swiftTestingCoverageFile. path]
101
+ extraArguments. append ( " --coverage-file " )
102
+ extraArguments. append ( swiftTestingCoverageFile. path)
103
+ }
104
+ extraArguments. append ( " -- " )
105
+ extraArguments. append ( " --testing-library " )
106
+ extraArguments. append ( " swift-testing " )
107
+ extraArguments. append ( contentsOf: testLibraryArguments)
108
+ for filter in testOptions. filter {
109
+ extraArguments. append ( " --filter " )
110
+ extraArguments. append ( filter)
99
111
}
100
- extraArguments += [ " -- " , " --testing-library " , " swift-testing " ]
101
- extraArguments += testLibraryArguments
102
- extraArguments += testOptions. filter. flatMap { [ " --filter " , $0] }
103
112
104
113
try PackageToJS . runSingleTestingLibrary (
105
114
testRunner: testRunner, currentDirectoryURL: currentDirectoryURL,
@@ -109,7 +118,7 @@ struct PackageToJS {
109
118
}
110
119
111
120
if testOptions. packageOptions. enableCodeCoverage {
112
- let profrawFiles = [ xctestCoverageFile, swiftTestingCoverageFile] . filter { FileManager . default. fileExists ( atPath: $0. path ) }
121
+ let profrawFiles = [ xctestCoverageFile. path , swiftTestingCoverageFile. path ] . filter { FileManager . default. fileExists ( atPath: $0) }
113
122
do {
114
123
try PackageToJS . postProcessCoverageFiles ( outputDir: outputDir, profrawFiles: profrawFiles)
115
124
} catch {
@@ -126,7 +135,11 @@ struct PackageToJS {
126
135
testOptions: TestOptions
127
136
) throws {
128
137
let node = try which ( " node " )
129
- let arguments = [ " --experimental-wasi-unstable-preview1 " ] + testOptions. extraNodeArguments + [ testRunner. path] + extraArguments
138
+ var arguments = [ " --experimental-wasi-unstable-preview1 " ]
139
+ arguments. append ( contentsOf: testOptions. extraNodeArguments)
140
+ arguments. append ( testRunner. path)
141
+ arguments. append ( contentsOf: extraArguments)
142
+
130
143
print ( " Running test... " )
131
144
logCommandExecution ( node. path, arguments)
132
145
@@ -160,16 +173,16 @@ struct PackageToJS {
160
173
}
161
174
finalize ( )
162
175
// swift-testing returns EX_UNAVAILABLE (which is 69 in wasi-libc) for "no tests found"
163
- guard task . terminationStatus == 0 || task. terminationStatus == 69 else {
176
+ guard [ 0 , 69 ] . contains ( task. terminationStatus) else {
164
177
throw PackageToJSError ( " Test failed with status \( task. terminationStatus) " )
165
178
}
166
179
}
167
180
168
- static func postProcessCoverageFiles( outputDir: URL , profrawFiles: [ URL ] ) throws {
181
+ static func postProcessCoverageFiles( outputDir: URL , profrawFiles: [ String ] ) throws {
169
182
let mergedCoverageFile = outputDir. appending ( path: " default.profdata " )
170
183
do {
171
184
// Merge the coverage files by llvm-profdata
172
- let arguments = [ " merge " , " -sparse " , " -output " , mergedCoverageFile. path] + profrawFiles. map { $0 . path }
185
+ let arguments = [ " merge " , " -sparse " , " -output " , mergedCoverageFile. path] + profrawFiles
173
186
let llvmProfdata = try which ( " llvm-profdata " )
174
187
logCommandExecution ( llvmProfdata. path, arguments)
175
188
try runCommand ( llvmProfdata, arguments)
@@ -194,7 +207,7 @@ struct PackageToJS {
194
207
func append( _ data: String ) {
195
208
lock. lock ( )
196
209
defer { lock. unlock ( ) }
197
- buffer += data
210
+ buffer. append ( data)
198
211
let lines = buffer. split ( separator: " \n " , omittingEmptySubsequences: false )
199
212
for line in lines. dropLast ( ) {
200
213
handler ( String ( line) )
@@ -567,12 +580,12 @@ struct PackagingPlanner {
567
580
}
568
581
569
582
let inputPath = selfPackageDir. appending ( path: file)
570
- let conditions = [
583
+ let conditions : [ String : Bool ] = [
571
584
" USE_SHARED_MEMORY " : triple == " wasm32-unknown-wasip1-threads " ,
572
585
" IS_WASI " : triple. hasPrefix ( " wasm32-unknown-wasi " ) ,
573
586
" USE_WASI_CDN " : options. useCDN,
574
587
]
575
- let constantSubstitutions = [
588
+ let constantSubstitutions : [ String : String ] = [
576
589
" PACKAGE_TO_JS_MODULE_PATH " : wasmFilename,
577
590
" PACKAGE_TO_JS_PACKAGE_NAME " : options. packageName ?? packageId. lowercased ( ) ,
578
591
]
@@ -587,11 +600,13 @@ struct PackagingPlanner {
587
600
if let wasmImportsPath = wasmImportsPath {
588
601
let wasmImportsPath = $1. resolve ( path: wasmImportsPath)
589
602
let importEntries = try JSONDecoder ( ) . decode ( [ ImportEntry ] . self, from: Data ( contentsOf: wasmImportsPath) )
590
- let memoryImport = importEntries. first { $0. module == " env " && $0. name == " memory " }
603
+ let memoryImport = importEntries. first {
604
+ $0. module == " env " && $0. name == " memory "
605
+ }
591
606
if case . memory( let type) = memoryImport? . kind {
592
- substitutions [ " PACKAGE_TO_JS_MEMORY_INITIAL " ] = " \( type. minimum) "
593
- substitutions [ " PACKAGE_TO_JS_MEMORY_MAXIMUM " ] = " \ ( type. maximum ?? type. minimum) "
594
- substitutions [ " PACKAGE_TO_JS_MEMORY_SHARED " ] = " \( type. shared) "
607
+ substitutions [ " PACKAGE_TO_JS_MEMORY_INITIAL " ] = type. minimum. description
608
+ substitutions [ " PACKAGE_TO_JS_MEMORY_MAXIMUM " ] = ( type. maximum ?? type. minimum) . description
609
+ substitutions [ " PACKAGE_TO_JS_MEMORY_SHARED " ] = type. shared. description
595
610
}
596
611
}
597
612
0 commit comments