Sun 10 Mar 2013 09:08:35 PM UTC, comment #3:
Thank you for the explanation, very clear.
After reading (again) the documentation (Test Functions),
the meaning of "block" seems to be undefined.
I wrongly assumed that "block" meant consecutive lines beginning with '%!', and that the block separators were blank lines.
Please find an attached patch trying to complete the docs.
Applies against hg id
2a81ce01c383 tip
But it would be better if these lines were not discarded silently. This is quite dangerous. For instance I have been going on changing code for hours, thinking that some tests were still passing nicely...
(file #27594)
|
Sun 10 Mar 2013 05:13:44 PM UTC, comment #2:
The syntax you are using for the tests is unsupported. It happens that your code manages to neatly squirm through the parser without generating an error, but I'm not sure there is a reason to fix this.
The troublesome bit is the first test:
'%' introduces a comment. The test.m function looks beyond the comment to find '%!BLOCK_NAME' where BLOCK_NAME is something like 'test', 'function', 'assert', 'fail', etc. Like Python, a block is indicated by indentation. '%!<SPACE>' is treated as a comment by the main parser and as part of the preceeding BLOCK by test.m.
So, running through your example:
'%!test' defines a test block
'%!function x = fn(z)' There is no indentation, so this line is not part of the %!test block above. The %!test block above is empty, and so it passes. '%!function' defines the start of a block which will define a function.
'%! x = z;' is indented so it is part of the most recent block, which is '%!function x= fn(z)'
'%!endfunction' has no indentation and ends the function definition
'%! assert(0,1) begins with a '%' so is a comment to the main parser. Because of the indentation, it should belong to the most recent BLOCK, whatever it is. But there is no BLOCK operating at this point so this line is ignored.
There are several ways that you might get around this. Below is the preferred style which defines shared functions ahead of their usage.
In this case, the space has been removed before assert and '%!assert' is now a valid block by itself.
|
Sun 10 Mar 2013 01:45:56 PM UTC, original submission:
testing test_test.m (attached)
The first test ought to fail,
but we get an incorrect "PASSED".
The second is fine,
Besides, according to the manual, it seems that
the third should fail, with "fn" undefined, since the test does not belong to the same block ?
Instead of that, all 3 tests passed :
It happens under 3.6.3, 3.6.4 and dev
hg id
2a81ce01c383 tip
|