@@ -36,6 +36,10 @@ function verbose(...args) {
36
36
if ( false ) print ( ...args ) ;
37
37
}
38
38
39
+ let kTestValidate = true ;
40
+ let kTestSyncCompile = true ;
41
+ let kTestAsyncCompile = true ;
42
+
39
43
//=======================================================================
40
44
// HARNESS SNIPPET, DO NOT COMMIT
41
45
//=======================================================================
@@ -48,6 +52,8 @@ const known_failures = {
48
52
let failures = [ ] ;
49
53
let unexpected_successes = [ ] ;
50
54
55
+ let last_promise = new Promise ( ( resolve , reject ) => { resolve ( ) ; } ) ;
56
+
51
57
function test ( func , description ) {
52
58
let maybeErr ;
53
59
try { func ( ) ; }
@@ -66,6 +72,24 @@ function test(func, description) {
66
72
print ( `${ description } : PASS.` ) ;
67
73
}
68
74
}
75
+
76
+ function promise_test ( func , description ) {
77
+ last_promise = last_promise . then ( func )
78
+ . then ( _ => {
79
+ if ( known_failures [ description ] ) {
80
+ unexpected_successes . push ( description ) ;
81
+ }
82
+ print ( `${ description } : PASS.` ) ;
83
+ } )
84
+ . catch ( err => {
85
+ var known = "" ;
86
+ if ( known_failures [ description ] ) {
87
+ known = " (known)" ;
88
+ }
89
+ print ( `${ description } : FAIL${ known } . ${ err } ` ) ;
90
+ failures . push ( description ) ;
91
+ } ) ;
92
+ }
69
93
//=======================================================================
70
94
71
95
function testLimit ( name , min , limit , gen ) {
@@ -109,27 +133,67 @@ function testLimit(name, min, limit, gen) {
109
133
throw new Error ( msg ) ;
110
134
}
111
135
}
112
-
113
- test ( ( ) => {
114
- run_validate ( min ) ;
115
- } , `Validate ${ name } mininum` ) ;
116
- test ( ( ) => {
117
- run_validate ( limit ) ;
118
- } , `Validate ${ name } limit` ) ;
119
- test ( ( ) => {
120
- run_validate ( limit + 1 ) ;
121
- } , `Validate ${ name } over limit` ) ;
122
-
123
- test ( ( ) => {
124
- run_compile ( min ) ;
125
- } , `Compile ${ name } mininum` ) ;
126
- test ( ( ) => {
127
- run_compile ( limit ) ;
128
- } , `Compile ${ name } limit` ) ;
129
- test ( ( ) => {
130
- run_compile ( limit + 1 ) ;
131
- } , `Compile ${ name } over limit` ) ;
132
-
136
+
137
+ function run_async_compile ( count ) {
138
+ let expected = count <= limit ;
139
+ verbose ( ` ${ expected ? "(expect ok) " : "(expect fail)" } = ${ count } ...` ) ;
140
+
141
+ // TODO(titzer): builder is slow for large modules; make manual?
142
+ let builder = new WasmModuleBuilder ( ) ;
143
+ gen ( builder , count ) ;
144
+ let buffer = builder . toBuffer ( ) ;
145
+ WebAssembly . compile ( buffer )
146
+ . then ( result => {
147
+ if ( ! expected ) {
148
+ let msg = `UNEXPECTED PASS: ${ name } == ${ count } ` ;
149
+ verbose ( `=====> UNEXPECTED ${ msg } ` ) ;
150
+ throw new Error ( msg ) ;
151
+ }
152
+ } )
153
+ . catch ( err => {
154
+ if ( expected ) {
155
+ let msg = `UNEXPECTED FAIL: ${ name } == ${ count } (${ e } )` ;
156
+ verbose ( `=====> UNEXPECTED ${ msg } ` ) ;
157
+ throw new Error ( msg ) ;
158
+ }
159
+ } )
160
+ }
161
+
162
+ if ( kTestValidate ) {
163
+ test ( ( ) => {
164
+ run_validate ( min ) ;
165
+ } , `Validate ${ name } mininum` ) ;
166
+ test ( ( ) => {
167
+ run_validate ( limit ) ;
168
+ } , `Validate ${ name } limit` ) ;
169
+ test ( ( ) => {
170
+ run_validate ( limit + 1 ) ;
171
+ } , `Validate ${ name } over limit` ) ;
172
+ }
173
+
174
+ if ( kTestSyncCompile ) {
175
+ test ( ( ) => {
176
+ run_compile ( min ) ;
177
+ } , `Compile ${ name } mininum` ) ;
178
+ test ( ( ) => {
179
+ run_compile ( limit ) ;
180
+ } , `Compile ${ name } limit` ) ;
181
+ test ( ( ) => {
182
+ run_compile ( limit + 1 ) ;
183
+ } , `Compile ${ name } over limit` ) ;
184
+ }
185
+
186
+ if ( kTestAsyncCompile ) {
187
+ promise_test ( ( ) => {
188
+ run_async_compile ( min ) ;
189
+ } , `Async compile ${ name } mininum` ) ;
190
+ promise_test ( ( ) => {
191
+ run_async_compile ( limit ) ;
192
+ } , `Async compile ${ name } limit` ) ;
193
+ promise_test ( ( ) => {
194
+ run_async_compile ( limit + 1 ) ;
195
+ } , `Async compile ${ name } over limit` ) ;
196
+ }
133
197
}
134
198
135
199
// A little doodad to disable a test easily
0 commit comments