Skip to content

Commit

Permalink
Merge pull request #132 from fitzgen/invalid-if-with-no-else
Browse files Browse the repository at this point in the history
Add a test for an invalid, result-producing `if` with no `else`
  • Loading branch information
fitzgen committed Sep 26, 2019
2 parents 6bc4740 + e683578 commit 102c133
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crates/tests/tests/invalid.rs
Expand Up @@ -10,8 +10,14 @@ fn run(wat: &Path) -> Result<(), failure::Error> {
let wasm = walrus_tests_utils::wat2wasm(wat, &["--no-check"])?;

// NB: reading the module will do the validation.
if let Ok(_) = walrus::Module::from_buffer(&wasm) {
failure::bail!("expected {} to be invalid, but it was valid", wat.display());
match walrus::Module::from_buffer(&wasm) {
Err(e) => {
eprintln!("Got error, as expected:");
for c in e.iter_chain() {
eprintln!(" - {}", c);
}
}
Ok(_) => failure::bail!("expected {} to be invalid, but it was valid", wat.display()),
}

Ok(())
Expand Down
12 changes: 12 additions & 0 deletions crates/tests/tests/invalid/if-with-no-else.wat
@@ -0,0 +1,12 @@
(module
(func (export "f") (param i32) (result i32)
(local.get 0)
(if (result i32)
(then (i32.const 1))
;; Note: since the `if` block is supposed to produce a result, we need an
;; `else` here to produce that result if the condition is false.
;;
;; (else (i32.const 2))
)
)
)

0 comments on commit 102c133

Please sign in to comment.