Add tests for if/then/else with indices + unknown label;#284
Add tests for if/then/else with indices + unknown label;#284rossberg merged 2 commits intoWebAssembly:masterfrom
Conversation
|
The current behaviour is correct: the body of each if-branch is (implicitly) a block, and the labels name these respective blocks. Not sure why you expect a label to be in scope in a sibling block? It's no different from which likewise is an error. The other test look good. |
|
@rossberg-chromium I think it's not meant to be in scope, it should be an error - it's an assert_invalid test. |
|
Oh, sorry, totally missed that. Yeah, that's definitely a bug, I'll look into it. |
|
Okay, I now see what's going on. The problem is that labels (and identifiers in general) are resolved in the parser, because the AST doesn't have them. An unbound name hence is a syntax error, rejecting the script before you ever get to run it. So it's not really a bug but a limitation of scripts -- a script can't check for this kind of error, just like it can't check other syntax errors. You'll need to check externally against expected-output instead. |
|
@rossberg-chromium I actually ran an issue in sexpr-wasm because of this; prior to having binary modules, I could assume that |
Thank you for the explanation, I can do this, however I wonder how https://github.com/WebAssembly/spec/blob/master/ml-proto/test/switch.wast#L155 doesn't trigger the exact same issue? |
|
@bnjbvr, that test uses a raw numeric index. What's resolved in the parser is the use of symbolic labels, and their translation into numeric ones (because they are purely syntactic sugar, not a part of the Wasm AST). I certainly won't argue that this difference is nice. :) |
|
I've updated the PR. The code wasn't accepting non-zero exit codes, so I had to refactor this, by adding a way to specify that a test is expected to fail. Also, there were issues with redirecting stderr to stdout with a |
a0c3403 to
080aa4e
Compare
ml-proto/runtests.py
Outdated
|
|
||
| if headers[0] == ';;;': | ||
| for h in headers[1:]: | ||
| if h.strip() == 'expected-fail': |
There was a problem hiding this comment.
Instead of instrumenting comments in the file, what do you think about simply using a file name convention? Say, <test>.fail.wast for tests that ought to fail? That's easier and cheaper to process (including for other test harnesses).
|
Thanks! Looks good modulo a few comments. |
080aa4e to
e5e2123
Compare
|
Updated the latest patch, thank you for the review! |
ml-proto/runtests.py
Outdated
|
|
||
| def _runTestFile(self, shortName, fileName, interpreterPath): | ||
|
|
||
| expectedExitCode = 1 if "fail" in fileName else 0 |
There was a problem hiding this comment.
Can we make this a bit narrower? ".fail." should be good.
e5e2123 to
561169f
Compare
|
Hm, Travis still barfs at the .fail test, although I can't immediately say why. |
ml-proto/runtests.py
Outdated
| self.assertEqual(expectedExitCode, exitCode, "test runner failed with exit code %i, expected %i" % (exitCode, expectedExitCode)) | ||
|
|
||
| if logPath is not None: | ||
| out.close() |
There was a problem hiding this comment.
One further style nit I just noted: inconsistent indentation, rest of the file uses 2
…ects output to the right places in all cases;
561169f to
9223278
Compare
|
Right, the test was failing because we are now very tied to line numbers, which is unfortunate. Addressed the two styles nits and updated the expected output to match line numbers. |
|
Cool, thanks! LGTM and landing. |
Hi! I'd like to add test cases we ran into in our implementation and which could be useful for others:
brin theelseis the label of thethenblock.Unfortunately, the second test (at the end of the file) doesn't work: the parser complains that the label
$lis unknown, which is exactly what we are testing here. The correct behavior would be to silently swallow the error and consider the test as passed. Am I missing something here?