Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit ad0da92

Browse files
committed
[interpreter] Improve core tests
* Adds additional validation tests * Changes some tests back to checking traps rather than exceptions * Add tests checking tag address use
1 parent 8c32eae commit ad0da92

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

test/core/rethrow.wast

+4
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@
8181
(assert_return (invoke "rethrow-recatch" (i32.const 0)) (i32.const 23))
8282
(assert_return (invoke "rethrow-recatch" (i32.const 1)) (i32.const 42))
8383

84+
(assert_invalid (module (func (rethrow 0))) "invalid rethrow label")
85+
(assert_invalid (module (func (block (rethrow 0)))) "invalid rethrow label")
86+
(assert_invalid (module (func (try (do (rethrow 0)) (delegate 0))))
87+
"invalid rethrow label")

test/core/throw.wast

+6
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@
4343
(assert_exception (invoke "throw-param-f64" (f64.const 5.0)))
4444

4545
(assert_return (invoke "test-throw-1-2"))
46+
47+
(assert_invalid (module (func (throw 0))) "unknown tag 0")
48+
(assert_invalid (module (tag (param i32)) (func (throw 0)))
49+
"type mismatch: instruction requires [i32] but stack has []")
50+
(assert_invalid (module (tag (param i32)) (func (i64.const 5) (throw 0)))
51+
"type mismatch: instruction requires [i32] but stack has [i64]")

test/core/try_catch.wast

+38-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@
154154
(assert_return (invoke "simple-throw-catch" (i32.const 0)) (i32.const 23))
155155
(assert_return (invoke "simple-throw-catch" (i32.const 1)) (i32.const 42))
156156

157-
(assert_exception (invoke "unreachable-not-caught"))
157+
(assert_trap (invoke "unreachable-not-caught") "unreachable")
158158

159159
(assert_return (invoke "trap-in-callee" (i32.const 7) (i32.const 2)) (i32.const 3))
160-
(assert_exception (invoke "trap-in-callee" (i32.const 1) (i32.const 0)))
160+
(assert_trap (invoke "trap-in-callee" (i32.const 1) (i32.const 0)) "integer divide by zero")
161161

162162
(assert_return (invoke "catch-complex-1" (i32.const 0)) (i32.const 3))
163163
(assert_return (invoke "catch-complex-1" (i32.const 1)) (i32.const 4))
@@ -188,6 +188,28 @@
188188
(assert_return (invoke "catchless-try" (i32.const 0)) (i32.const 0))
189189
(assert_return (invoke "catchless-try" (i32.const 1)) (i32.const 1))
190190

191+
(module
192+
(func $imported-throw (import "test" "throw"))
193+
(tag $e0)
194+
195+
(func (export "imported-mismatch") (result i32)
196+
(try (result i32)
197+
(do
198+
(try (result i32)
199+
(do
200+
(i32.const 1)
201+
(call $imported-throw)
202+
)
203+
(catch $e0 (i32.const 2))
204+
)
205+
)
206+
(catch_all (i32.const 3))
207+
)
208+
)
209+
)
210+
211+
(assert_return (invoke "imported-mismatch") (i32.const 3))
212+
191213
(assert_malformed
192214
(module quote "(module (func (catch_all)))")
193215
"unexpected token"
@@ -204,3 +226,17 @@
204226
)
205227
"unexpected token"
206228
)
229+
230+
(assert_invalid (module (func (result i32) (try (result i32) (do))))
231+
"type mismatch: instruction requires [i32] but stack has []")
232+
(assert_invalid (module (func (result i32) (try (result i32) (do (i64.const 42)))))
233+
"type mismatch: instruction requires [i32] but stack has [i64]")
234+
(assert_invalid (module (tag) (func (try (do) (catch 0 (i32.const 42)))))
235+
"type mismatch: block requires [] but stack has [i32]")
236+
(assert_invalid (module
237+
(tag (param i64))
238+
(func (result i32)
239+
(try (result i32) (do (i32.const 42)) (catch 0))))
240+
"type mismatch: instruction requires [i32] but stack has [i64]")
241+
(assert_invalid (module (func (try (do) (catch_all (i32.const 42)))))
242+
"type mismatch: block requires [] but stack has [i32]")

test/core/try_delegate.wast

+10
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,13 @@
113113
(module quote "(module (func (try (do) (delegate) (delegate 0))))")
114114
"unexpected token"
115115
)
116+
117+
(assert_invalid
118+
(module (func (try (do) (delegate 1))))
119+
"unknown label"
120+
)
121+
122+
(assert_invalid
123+
(module (func (block (try (do) (delegate 0)))))
124+
"invalid delegate label"
125+
)

0 commit comments

Comments
 (0)