annotate scripts/testfun/rundemos.m @ 13065:1ca3cde15b18

codepsprint: tests for testfun functions * demo.m, rundemos.m: Trivial tests. * speed.m: New tests.
author John W. Eaton <jwe@octave.org>
date Sat, 03 Sep 2011 14:57:12 -0400
parents 64193afe93d8
children 8782d41893c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
1 ## Copyright (C) 2008-2011 John W. Eaton
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
12668
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
20 ## @deftypefn {Function File} {} rundemos ()
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
21 ## @deftypefnx {Function File} {} rundemos (@var{directory})
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
22 ## Execute built-in demos for all function files in the specified directory.
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
23 ## If no directory is specified, operate on all directories in Octave's
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## search path for functions.
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
25 ## @seealso{runtests, path}
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ## @end deftypefn
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 ## Author: jwe
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 function rundemos (directory)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 if (nargin == 0)
8877
2c8b2399247b implement strsplit; deprecate split
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
33 dirs = strsplit (path (), pathsep ());
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 elseif (nargin == 1)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 if (is_absolute_filename (directory))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 dirs = {directory};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 else
12673
64193afe93d8 runtests.m, rundemos.m: Remove final filesep() character from directory name
Rik <octave@nomad.inbox5.com>
parents: 12668
diff changeset
38 directory = regexprep (directory, ['\',filesep(),'$'], "");
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 fullname = find_dir_in_path (directory);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 if (! isempty (fullname))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
41 dirs = {fullname};
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 else
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
43 error ("rundemos: DIRECTORY argument must be a valid pathname");
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 else
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 print_usage ();
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
8231
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
50 for i = 1:numel (dirs)
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
51 d = dirs{i};
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
52 run_all_demos (d);
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
53 endfor
df28b55d03c0 make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents: 8230
diff changeset
54
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 function run_all_demos (directory)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 dirinfo = dir (directory);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 flist = {dirinfo.name};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 for i = 1:numel (flist)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 f = flist{i};
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 f = fullfile (directory, f);
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if (has_demos (f))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
65 demo (f);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
66 if (i != numel (flist))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
67 input ("Press <enter> to continue: ", "s");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 8920
diff changeset
68 endif
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 endif
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 endfor
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 endfunction
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 function retval = has_demos (f)
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 fid = fopen (f);
8699
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
76 if (f < 0)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
77 error ("rundemos: fopen failed: %s", f);
8699
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
78 else
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
79 str = fscanf (fid, "%s");
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
80 fclose (fid);
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
81 retval = findstr (str, "%!demo");
6e764b7317bd test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents: 8245
diff changeset
82 endif
8229
1bf51192fa1d imported patch rundemos
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 endfunction
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 12673
diff changeset
84
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 12673
diff changeset
85 %!error rundemos ("foo", 1);