bugGNU Octave - Bugs: bug #38495, remainder of test discarded after...

 
 

bug #38495: remainder of test discarded after %!endfunction

Submitter:  John Hunt <huntj>
Submitted:  Sun 10 Mar 2013 01:45:56 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 11 Mar 2013 06:09:05 PM UTC, comment #4: 

I used some of your verbiage and added an example to illustrate the issue.  The changeset is here (http://hg.savannah.gnu.org/hgweb/octave/rev/4dc4da5970e5).

Rik <rik5>
Group administrator
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)

John Hunt <huntj>
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:


%!test
%!function x = fn(z)
%!  x = z;
%!endfunction
%! assert(0, 1)


'%' 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. 


%!function x = fn(z)
%!  x = z;
%!endfunction
%!
%!test
%! assert(0, 1)



%!test
%!function x = fn(z)
%!  x = z;
%!endfunction

%!assert(0, 1)


In this case, the space has been removed before assert and '%!assert' is now a valid block by itself.

Rik <rik5>
Group administrator
Sun 10 Mar 2013 02:37:44 PM UTC, comment #1: 

This could be related to bug # 38455 which
shows some interaction between the current test and
previous ones.

Michael Godfrey <godfrey>
Group Member
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 :

  ***** test
  ***** function x = fn(z)
  x = z;
  ***** endfunction
 assert(0, 1)
  ***** function x = fn(z)
  x = z;
  ***** endfunction
  ***** test
 assert(fn(1), 1)
  ***** test
 assert(fn(2), 2)
PASSES 3 out of 3 tests


It happens under 3.6.3, 3.6.4 and dev
hg id
2a81ce01c383 tip

John Hunt <huntj>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #27594:  testfun_block.patch added by huntj (1KiB - text/x-patch)
file #27588:  test_test.m added by huntj (218B - text/x-matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by huntj (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-03-11 rik5 Open/ClosedOpen Closed
    2013-03-10 huntj Attached File- Added testfun_block.patch, #27594
    2013-03-10 rik5 StatusNone Wont Fix
    2013-03-10 huntj Attached File- Added test_test.m, #27588

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code