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

 
 

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

Submitted by:  John Hunt <huntj>
Submitted on:  Sun 10 Mar 2013 01:45:56 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: Wont FixAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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:

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

Rik <rik5>
Project 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>
Project 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 :

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 File(s):
   
   
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
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by godfrey (Posted a comment)
  • -unavailable- added by huntj (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 11 Mar 2013 06:09:05 PM UTCrik5Open/ClosedOpen=>Closed
    Sun 10 Mar 2013 09:08:35 PM UTChuntjAttached File-=>Added testfun_block.patch, #27594
    Sun 10 Mar 2013 05:13:44 PM UTCrik5StatusNone=>Wont Fix
    Sun 10 Mar 2013 01:45:56 PM UTChuntjAttached File-=>Added test_test.m, #27588

    Back to the top


    Powered by Savane 3.1-cleanup1