@@ -7,6 +7,41 @@ private func loadStringArrayFromEnvironment(_ key: String) -> [String] {
77 ProcessInfo . processInfo. environment [ key] ? . split ( separator: " , " ) . map ( String . init) ?? [ ]
88}
99
10+ public struct SpectestResult {
11+ var passed = 0
12+ var skipped = 0
13+ var failed = 0
14+ var total : Int { passed + skipped + failed }
15+ var failedCases : Set < String > = [ ]
16+
17+ mutating func append( _ testCase: TestCase , _ result: Result ) {
18+ switch result {
19+ case . passed:
20+ passed += 1
21+ case . skipped:
22+ skipped += 1
23+ case . failed:
24+ failed += 1
25+ failedCases. insert ( testCase. path)
26+ }
27+ }
28+
29+ func percentage( _ numerator: Int , _ denominator: Int ) -> String {
30+ " \( Int ( Double ( numerator) / Double( denominator) * 100 ) ) % "
31+ }
32+
33+ func dump( ) {
34+ print (
35+ " \( passed) / \( total) ( \( percentage ( passed, total) ) passing, \( percentage ( skipped, total) ) skipped, \( percentage ( failed, total) ) failed) "
36+ )
37+ guard !failedCases. isEmpty else { return }
38+ print ( " Failed cases: " )
39+ for testCase in failedCases. sorted ( ) {
40+ print ( " \( testCase) " )
41+ }
42+ }
43+ }
44+
1045@available ( macOS 11 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * )
1146public func spectest(
1247 path: [ String ] ,
@@ -16,6 +51,18 @@ public func spectest(
1651 parallel: Bool = true ,
1752 configuration: EngineConfiguration = . init( )
1853) async throws -> Bool {
54+ try await spectestResult ( path: path, include: include, exclude: exclude, verbose: verbose, parallel: parallel, configuration: configuration) . failed == 0
55+ }
56+
57+ @available ( macOS 11 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * )
58+ public func spectestResult(
59+ path: [ String ] ,
60+ include: [ String ] ? = nil ,
61+ exclude: [ String ] ? = nil ,
62+ verbose: Bool = false ,
63+ parallel: Bool = true ,
64+ configuration: EngineConfiguration = . init( )
65+ ) async throws -> SpectestResult {
1966 let printVerbose = verbose
2067 @Sendable func log( _ message: String , verbose: Bool = false ) {
2168 if !verbose || printVerbose {
@@ -28,10 +75,6 @@ public func spectest(
2875 fputs ( " \( path) : \( line) : " + message + " \n " , stderr)
2976 }
3077 }
31- func percentage( _ numerator: Int , _ denominator: Int ) -> String {
32- " \( Int ( Double ( numerator) / Double( denominator) * 100 ) ) % "
33- }
34-
3578 let include = include ?? loadStringArrayFromEnvironment ( " WASMKIT_SPECTEST_INCLUDE " )
3679 let exclude = exclude ?? loadStringArrayFromEnvironment ( " WASMKIT_SPECTEST_EXCLUDE " )
3780
@@ -44,7 +87,7 @@ public func spectest(
4487
4588 guard !testCases. isEmpty else {
4689 log ( " No test found " )
47- return true
90+ return SpectestResult ( )
4891 }
4992
5093 // https://github.com/WebAssembly/spec/tree/8a352708cffeb71206ca49a0f743bdc57269fb1a/interpreter#spectest-host-module
@@ -103,37 +146,6 @@ public func spectest(
103146 return testCaseResults
104147 }
105148
106- struct SpectestResult {
107- var passed = 0
108- var skipped = 0
109- var failed = 0
110- var total : Int { passed + skipped + failed }
111- var failedCases : Set < String > = [ ]
112-
113- mutating func append( _ testCase: TestCase , _ result: Result ) {
114- switch result {
115- case . passed:
116- passed += 1
117- case . skipped:
118- skipped += 1
119- case . failed:
120- failed += 1
121- failedCases. insert ( testCase. path)
122- }
123- }
124-
125- func dump( ) {
126- print (
127- " \( passed) / \( total) ( \( percentage ( passed, total) ) passing, \( percentage ( skipped, total) ) skipped, \( percentage ( failed, total) ) failed) "
128- )
129- guard !failedCases. isEmpty else { return }
130- print ( " Failed cases: " )
131- for testCase in failedCases. sorted ( ) {
132- print ( " \( testCase) " )
133- }
134- }
135- }
136-
137149 let result : SpectestResult
138150
139151 if parallel {
@@ -168,5 +180,5 @@ public func spectest(
168180
169181 result. dump ( )
170182
171- return result. failed == 0
183+ return result
172184}
0 commit comments