@@ -61,28 +61,31 @@ struct PackageToJS {
6161 var testJsArguments : [ String ] = [ ]
6262 var testLibraryArguments : [ String ] = [ ]
6363 if testOptions. listTests {
64- testLibraryArguments += [ " --list-tests " ]
64+ testLibraryArguments. append ( " --list-tests " )
6565 }
6666 if let prelude = testOptions. prelude {
6767 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)
6970 }
7071 if let environment = testOptions. environment {
71- testJsArguments += [ " --environment " , environment]
72+ testJsArguments. append ( " --environment " )
73+ testJsArguments. append ( environment)
7274 }
7375 if testOptions. inspect {
74- testJsArguments += [ " --inspect " ]
76+ testJsArguments. append ( " --inspect " )
7577 }
7678
7779 let xctestCoverageFile = outputDir. appending ( path: " XCTest.profraw " )
7880 do {
7981 var extraArguments = testJsArguments
8082 if testOptions. packageOptions. enableCodeCoverage {
81- extraArguments += [ " --coverage-file " , xctestCoverageFile. path]
83+ extraArguments. append ( " --coverage-file " )
84+ extraArguments. append ( xctestCoverageFile. path)
8285 }
83- extraArguments += [ " -- " ]
84- extraArguments += testLibraryArguments
85- extraArguments += testOptions. filter
86+ extraArguments. append ( " -- " )
87+ extraArguments. append ( contentsOf : testLibraryArguments)
88+ extraArguments. append ( contentsOf : testOptions. filter)
8689
8790 try PackageToJS . runSingleTestingLibrary (
8891 testRunner: testRunner, currentDirectoryURL: currentDirectoryURL,
@@ -95,11 +98,17 @@ struct PackageToJS {
9598 do {
9699 var extraArguments = testJsArguments
97100 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)
99111 }
100- extraArguments += [ " -- " , " --testing-library " , " swift-testing " ]
101- extraArguments += testLibraryArguments
102- extraArguments += testOptions. filter. flatMap { [ " --filter " , $0] }
103112
104113 try PackageToJS . runSingleTestingLibrary (
105114 testRunner: testRunner, currentDirectoryURL: currentDirectoryURL,
@@ -109,7 +118,7 @@ struct PackageToJS {
109118 }
110119
111120 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) }
113122 do {
114123 try PackageToJS . postProcessCoverageFiles ( outputDir: outputDir, profrawFiles: profrawFiles)
115124 } catch {
@@ -126,7 +135,11 @@ struct PackageToJS {
126135 testOptions: TestOptions
127136 ) throws {
128137 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+
130143 print ( " Running test... " )
131144 logCommandExecution ( node. path, arguments)
132145
@@ -160,16 +173,16 @@ struct PackageToJS {
160173 }
161174 finalize ( )
162175 // 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 {
164177 throw PackageToJSError ( " Test failed with status \( task. terminationStatus) " )
165178 }
166179 }
167180
168- static func postProcessCoverageFiles( outputDir: URL , profrawFiles: [ URL ] ) throws {
181+ static func postProcessCoverageFiles( outputDir: URL , profrawFiles: [ String ] ) throws {
169182 let mergedCoverageFile = outputDir. appending ( path: " default.profdata " )
170183 do {
171184 // 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
173186 let llvmProfdata = try which ( " llvm-profdata " )
174187 logCommandExecution ( llvmProfdata. path, arguments)
175188 try runCommand ( llvmProfdata, arguments)
@@ -194,7 +207,7 @@ struct PackageToJS {
194207 func append( _ data: String ) {
195208 lock. lock ( )
196209 defer { lock. unlock ( ) }
197- buffer += data
210+ buffer. append ( data)
198211 let lines = buffer. split ( separator: " \n " , omittingEmptySubsequences: false )
199212 for line in lines. dropLast ( ) {
200213 handler ( String ( line) )
@@ -567,12 +580,12 @@ struct PackagingPlanner {
567580 }
568581
569582 let inputPath = selfPackageDir. appending ( path: file)
570- let conditions = [
583+ let conditions : [ String : Bool ] = [
571584 " USE_SHARED_MEMORY " : triple == " wasm32-unknown-wasip1-threads " ,
572585 " IS_WASI " : triple. hasPrefix ( " wasm32-unknown-wasi " ) ,
573586 " USE_WASI_CDN " : options. useCDN,
574587 ]
575- let constantSubstitutions = [
588+ let constantSubstitutions : [ String : String ] = [
576589 " PACKAGE_TO_JS_MODULE_PATH " : wasmFilename,
577590 " PACKAGE_TO_JS_PACKAGE_NAME " : options. packageName ?? packageId. lowercased ( ) ,
578591 ]
@@ -587,11 +600,13 @@ struct PackagingPlanner {
587600 if let wasmImportsPath = wasmImportsPath {
588601 let wasmImportsPath = $1. resolve ( path: wasmImportsPath)
589602 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+ }
591606 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
595610 }
596611 }
597612
0 commit comments