@@ -7,6 +7,41 @@ private func loadStringArrayFromEnvironment(_ key: String) -> [String] {
7
7
ProcessInfo . processInfo. environment [ key] ? . split ( separator: " , " ) . map ( String . init) ?? [ ]
8
8
}
9
9
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
+
10
45
@available ( macOS 11 , iOS 14 . 0 , watchOS 7 . 0 , tvOS 14 . 0 , * )
11
46
public func spectest(
12
47
path: [ String ] ,
@@ -16,6 +51,18 @@ public func spectest(
16
51
parallel: Bool = true ,
17
52
configuration: EngineConfiguration = . init( )
18
53
) 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 {
19
66
let printVerbose = verbose
20
67
@Sendable func log( _ message: String , verbose: Bool = false ) {
21
68
if !verbose || printVerbose {
@@ -28,10 +75,6 @@ public func spectest(
28
75
fputs ( " \( path) : \( line) : " + message + " \n " , stderr)
29
76
}
30
77
}
31
- func percentage( _ numerator: Int , _ denominator: Int ) -> String {
32
- " \( Int ( Double ( numerator) / Double( denominator) * 100 ) ) % "
33
- }
34
-
35
78
let include = include ?? loadStringArrayFromEnvironment ( " WASMKIT_SPECTEST_INCLUDE " )
36
79
let exclude = exclude ?? loadStringArrayFromEnvironment ( " WASMKIT_SPECTEST_EXCLUDE " )
37
80
@@ -44,7 +87,7 @@ public func spectest(
44
87
45
88
guard !testCases. isEmpty else {
46
89
log ( " No test found " )
47
- return true
90
+ return SpectestResult ( )
48
91
}
49
92
50
93
// https://github.com/WebAssembly/spec/tree/8a352708cffeb71206ca49a0f743bdc57269fb1a/interpreter#spectest-host-module
@@ -103,37 +146,6 @@ public func spectest(
103
146
return testCaseResults
104
147
}
105
148
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
-
137
149
let result : SpectestResult
138
150
139
151
if parallel {
@@ -168,5 +180,5 @@ public func spectest(
168
180
169
181
result. dump ( )
170
182
171
- return result. failed == 0
183
+ return result
172
184
}
0 commit comments