[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: testing error messages with functions needing a file id
From: |
John W. Eaton |
Subject: |
Re: testing error messages with functions needing a file id |
Date: |
Sun, 17 Mar 2013 07:07:04 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 |
On 03/17/2013 06:37 AM, PhilipNienhuis wrote:
Daniel Sebald wrote
On 03/16/2013 06:07 PM, PhilipNienhuis wrote:
In textscan.m I'd like to have a test like:
%!error
<missing or illegal value for>
textscan (fid, "%s", "headerlines")
but there are a few stumbling blocks:
1. I wouldn't know how to supply a valid file identifier to textscan so
that
the test can be made to work (apparently the error message test is
self-contained (left-adjusted against "%!") and cannot comprise multiple
lines).
I'm not completely understanding what the issue is.
Sorry to be so vague. Another try:
1. Octave's error message tests seem to be exclusively one-liners only. See
the last 3 lines in textscan's test suite.
2. I want to check an error message that textscan.m only emits when reading
from file.
3. textscan.m doesn't accept file names but rather file identifiers
previously made with fopen()
4. I wouldn't know how to squeeze an fopen and an fclose statement plus a
call to textscan in one line.
Or does the error message test accept<statement> ;<statement> ;
constructs? (with semicolons) (hmm didn't try that)
However, the second
last sample test in that file creates a temporary file, writes some data
to it, then rewinds the file and passes the FID onto the textscan test.
Yes, I wrote that test myself a few days ago:-)
I think you should be able to do something like this:
%!shared fid, d, A, msg
%! [fid, name] = mkstemp ("oct-XXXXXX", true);
%! d = rand (1, 4);
%! fprintf (fid, " %f %f %f %f ", d);
%! fseek (fid, 0, "bof");
%! A = textscan (fid, "%f %f");
%! frewind (fid);
%! msg = "foo error"
%!assert (A{1}, [d(1); d(3)], 1e-6);
%!assert (A{2}, [d(2); d(4)], 1e-6);
%!error <foo error> error (msg)
jwe