From fd8feedb5173d830fd7ee94e9df7f17220afdeb0 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 13 Nov 2018 17:41:29 -0800 Subject: [PATCH] Added token spectests --- spectests/README.md | 2 +- spectests/token.wast | 10 ++++++++++ src/build_spectests.rs | 3 ++- src/spectests/mod.rs | 1 + src/spectests/token.rs | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 spectests/token.wast create mode 100644 src/spectests/token.rs diff --git a/spectests/README.md b/spectests/README.md index 97bf4ca80..2e3142b63 100644 --- a/spectests/README.md +++ b/spectests/README.md @@ -93,7 +93,7 @@ This spectests are currently covered: - store_retval.wast ✅ - switch.wast ✅ - tee_local.wast ✅ -- token.wast +- token.wast ✅ - traps.wast ✅ - type.wast ✅ - typecheck.wast ✅ diff --git a/spectests/token.wast b/spectests/token.wast new file mode 100644 index 000000000..1dcd32e7f --- /dev/null +++ b/spectests/token.wast @@ -0,0 +1,10 @@ +;; Test tokenization + +(assert_malformed + (module quote "(func (drop (i32.const0)))") + "unknown operator" +) +(assert_malformed + (module quote "(func br 0drop)") + "unknown operator" +) diff --git a/src/build_spectests.rs b/src/build_spectests.rs index aaa9a23fc..eb2998228 100644 --- a/src/build_spectests.rs +++ b/src/build_spectests.rs @@ -13,7 +13,7 @@ static ENV_VAR: &str = "WASM_GENERATE_SPECTESTS"; static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs). // Please do NOT modify it by hand, as it will be reseted on next build.\n"; -const TESTS: [&str; 55] = [ +const TESTS: [&str; 56] = [ "spectests/address.wast", "spectests/align.wast", "spectests/binary.wast", @@ -67,6 +67,7 @@ const TESTS: [&str; 55] = [ "spectests/store_retval.wast", "spectests/switch.wast", "spectests/tee_local.wast", + "spectests/token.wast", "spectests/traps.wast", "spectests/typecheck.wast", "spectests/types.wast", diff --git a/src/spectests/mod.rs b/src/spectests/mod.rs index 463226ee7..3882469e3 100644 --- a/src/spectests/mod.rs +++ b/src/spectests/mod.rs @@ -68,6 +68,7 @@ mod start; mod store_retval; mod switch; mod tee_local; +mod token; mod traps; mod typecheck; mod types; diff --git a/src/spectests/token.rs b/src/spectests/token.rs new file mode 100644 index 000000000..e234d8b3d --- /dev/null +++ b/src/spectests/token.rs @@ -0,0 +1,32 @@ +// Rust test file autogenerated with cargo build (src/build_spectests.rs). +// Please do NOT modify it by hand, as it will be reseted on next build. +// Test based on spectests/token.wast +#![allow( + warnings, + dead_code +)] +use std::panic; +use wabt::wat2wasm; + +use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, Instance, Export}; +use super::_common::{ + spectest_importobject, + NaNCheck, +}; + + +// Line 4 +#[test] +fn c0_l4_assert_malformed() { + let wasm_binary = [40, 102, 117, 110, 99, 32, 40, 100, 114, 111, 112, 32, 40, 105, 51, 50, 46, 99, 111, 110, 115, 116, 48, 41, 41, 41]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is malformed"); +} + +// Line 8 +#[test] +fn c1_l8_assert_malformed() { + let wasm_binary = [40, 102, 117, 110, 99, 32, 98, 114, 32, 48, 100, 114, 111, 112, 41]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is malformed"); +}