Skip to content

Add wast source information to JS-converted test cases #1919

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

Open
wants to merge 4 commits into
base: wasm-3.0
Choose a base branch
from

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented Jun 14, 2025

Currently the JS/HTML test conversion outputs a test name for each test, but each name is generic
(such as "#2 Test that WebAssembly compilation succeeds", where the only thing unique is a
prepended number. In the async version, the order of these tests doesn't even correspond
simply to the order of tests in the wast file because each test generates multiple assertions
as promises which do not all resolve together for the same tests. The result is hard to
interpret and debug. This is related to #1860 although this particular issue isn't in the
list there.

This PR adds a "source" argument to various functions and passes the information from
the interpreter's AST through the various conversions into the JS files. The result is test
names such as "#2 Test that WebAssembly compilation succeeds (address.wast:3)".
There are still a few non-unique names. "Reinitialize the default imports" and the wrapper
modules that are used when values can't be passed cleanly to JS aren't updated; but
those modules are not directly part of the feature under test and are less likely to fail,
so it didn't seem worth it.

Comment on lines 791 to 793
let source = Filename.basename ass.at.left.file ^
":" ^ string_of_int ass.at.left.line in
let source_as_arg = ", \"" ^ source ^ "\"" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to use String.escaped source, otherwise the string literal will be broken if odd characters appear in the name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, although if any non-ascii chars show up in an input filename, the interpreter fails to load it entirely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was alluding to backslash or quote characters, but you are right, Unicode is mishandled. I just pushed a fix, and the culprit was: String.escaped. :) Because that produces C-style octal escapes.

But I realised that there already is a proper JS-escaping function in this module: avoid String.escaped and just use the local of_name (which also adds the surrounding quotes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants