Skip to content

Commit

Permalink
Support running tests from wasm proposals (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored May 14, 2024
1 parent d1537cd commit 589bfce
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crates/interpreter/tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use wast::lexer::Lexer;
use wast::token::Id;
use wast::{parser, QuoteWat, Wast, WastArg, WastDirective, WastExecute, WastInvoke, WastRet, Wat};

fn test(name: &str) {
let path = format!("../../third_party/WebAssembly/spec/test/core/{}.wast", name);
fn test(repo: &str, name: &str) {
let path = format!("../../third_party/WebAssembly/{repo}/test/core/{name}.wast");
let content = std::fs::read_to_string(path).unwrap();
let mut lexer = Lexer::new(&content);
lexer.allow_confusing_unicode(true);
Expand Down Expand Up @@ -372,10 +372,17 @@ fn wast_arg_core(core: WastArgCore) -> Val {
}

macro_rules! test {
($(#[$m:meta])* $name: ident) => { test!([1] $(#[$m])* $name [$name]); };
($(#[$m:meta])* $name: ident, $file: literal) => { test!([1] $(#[$m])* $name [$file]); };
([1] $(#[$m:meta])* $name: ident [$($file: tt)*]) => {
#[test] $(#[$m])* fn $name() { test(test!([2] $($file)*)); }
($(#[$m:meta])* $name: ident$(, $file: literal)?) => {
test!($(#[$m])* "spec", $name$(, $file)?);
};
($(#[$m:meta])* $repo: literal, $name: ident) => {
test!([1] $(#[$m])* $name [$repo $name]);
};
($(#[$m:meta])* $repo: literal, $name: ident, $file: literal) => {
test!([1] $(#[$m])* $name [$repo $file]);
};
([1] $(#[$m:meta])* $name: ident [$repo: literal $($file: tt)*]) => {
#[test] $(#[$m])* fn $name() { test($repo, test!([2] $($file)*)); }
};
([2] $file: ident) => { stringify!($file) };
([2] $file: literal) => { $file };
Expand Down

0 comments on commit 589bfce

Please sign in to comment.