[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Converting DejaGNU tests to Paul's test/assert infrastructure
From: |
David Bateman |
Subject: |
Re: Converting DejaGNU tests to Paul's test/assert infrastructure |
Date: |
Tue, 25 Oct 2005 09:27:12 +0200 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040923) |
Paul Kienzle wrote:
On Oct 24, 2005, at 9:20 AM, David Bateman wrote:
However, nested functions are not permitted with Paul's test
infrastructure. I haven't looked at test.m yet to see, but how
complicated would it be to include nested functions in test.m?
You should now be able to build test function blocks with the function
name being the name of a shared variable which will last until the end
of the test or until the next 'shared' block.
Another issue I have is that although "%!error" exists there is no
equivalent "%!warning" for the warning conditions. Again how
complicated would it be to add this?
Octave can only test the first warning since lastwarn isn't updated
after the first warning. Presumably it resets itself after returning
to the prompt. Also the warnings will be displayed during the test.
Regardless, I've added a warning block similar to the error block:
%!warning warning("message text")
If you want to check the contents of the warning or error message,
then use the new syntax '%!error <pattern> code'. For example:
%!error <nonconformant> [1,2,3]*[4,5,6]
%!warning <division by zero> 5/0
Pattern can be any regular expression on the string with leading
'error: ' and trailing '\n' stripped off.
I first extended the 'fail' command to allow
fail(code,'warning',pattern) which will check the value of lastwarn
against the pattern, but I decided the tests looked too ugly.
- Paul
I was thinking along the lines of a warn.m similar to fail.m as
attached. But as you noticed, the new warning doesn't clear the old one
and so we can only use the code once!
I think there needs to be a change to lastwarn in octave to clear the
old warnings and also to suppress the warning messages. I have about 40
warning tests in the DejaGNU code to convert and so if I can only test
one of them, this won't work.
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
## PKG_ADD mark_as_command warn
function ret=warn(code,pattern)
if nargin < 1 || nargin > 2
usage("warn('code' [, 'pattern'])");
end
## allow assert(warn())
if nargout, ret=1; end
## don't test warning if evalin doesn't exist
if !exist('evalin'), return; end
## perform the test
try
evalin("caller",[code,";"]);
err = lastwarn;
if (isempty(err))
msg = "expected warning but got none.";
else
## allow warn('code')
if (nargin<2 || isempty(pattern))
return;
endif
msg = sprintf("expected message <%s>\nbut got <%s>",
pattern,err(1:end-1));
if (!isempty(regexp(pattern,err(1:end-1))))
return;
endif
endif
catch
err=lasterr;
msg = ["expected warning but got error: ", err];
end
## if we get here, then code didn't fail or error didn't match
error(msg);
end
%!test
%! wdz = warn_divide_by_zero;
%! warn_divide_by_zero = 1;
%! warn('1/0','division by zero')
%! warn_divide_by_zero = wdz;
%!test
%! wfi = warn_fortran_indexing;
%! warn_fortran_indexing = 1;
%! m = [1,2;3,4];
%! warn('m(1:4)','single index used for matrix')
%! warn_fortran_indexing = wfi;