octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #38495] remainder of test discarded after %!en


From: Rik
Subject: [Octave-bug-tracker] [bug #38495] remainder of test discarded after %!endfunction
Date: Sun, 10 Mar 2013 17:13:45 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0

Update of bug #38495 (project octave):

                  Status:                    None => Wont Fix               

    _______________________________________________________

Follow-up 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.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?38495>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]