Re-use of interpreter tests for the wasm parser
Following on from our conversations on slack ...
- it would be ideal to re-use some of the existing tests for the wasm decoder / gen
- binary wasm files are not great test cases
- the wat files in the
wast-parser/test/fixturesare fragments, and are not valid wat files (perhaps rename to something like.watfto make this clear?)
To test the wasm-parser I'd like to re-use of the wast (i.e. wat) files within packages/webassemblyjs/test/fixtures/, using wat2wasm to convert them to wasm, then using the wasm-parser to convert the wasm into AST, this can then be compared with the AST generated by wast-parser.
I've had a go at this ... here is what happens to far. For 36 test files ...
A number are not actually valid wat files:
'packages/webassemblyjs/test/fixtures/parsing-invalid-index/module.wast',
'packages/webassemblyjs/test/fixtures/instantiate-data-section/global-offset/module.wast',
'packages/webassemblyjs/test/fixtures/importObject/module.wast',
'packages/webassemblyjs/test/fixtures/if-type-inference-incorrect-result/module.wast',
'packages/webassemblyjs/test/fixtures/if-type-inference-incorrect-branches/module.wast',
'packages/webassemblyjs/test/fixtures/global-type-mismatch/module.wast',
'packages/webassemblyjs/test/fixtures/export-global-i32-mut/module.wast',
'packages/webassemblyjs/test/fixtures/duplicate-export-name/module.wast',
'packages/webassemblyjs/test/fixtures/call-func-with-i64-result/module.wast',
'packages/webassemblyjs/test/fixtures/validate-func-result-type/module.wast',
'packages/webassemblyjs/test/fixtures/trap-throws-runtime-error/module.wast' ]
There are a couple of issues here.
- Ones where the wat has simple validation errors, e.g. elements in the wrong order.
- Ones that are not valid because that is the nature of the test.
For (1) I'd propose fixing the wat file, and updating wast-parser with additional validation. For (2) I think these should be moved into wast-parser.
Of the remaining, comparing wast => AST vs. wasm => AST, shows some metadata differences, e.g. loc and other metadata. This should be easy to strip out allowing a comparison.