Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for an invalid, result-producing if with no else #132

Merged
merged 1 commit into from Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))
)
)
)