Mercurial > octave-antonio
annotate scripts/testfun/rundemos.m @ 20162:2645f9ef8c88 stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed specfun, special-matrix, testfun, and time script directories.
* scripts/specfun/expint.m, scripts/specfun/isprime.m,
scripts/specfun/legendre.m, scripts/specfun/primes.m,
scripts/specfun/reallog.m, scripts/specfun/realsqrt.m,
scripts/special-matrix/gallery.m, scripts/special-matrix/hadamard.m,
scripts/special-matrix/hankel.m, scripts/special-matrix/hilb.m,
scripts/special-matrix/invhilb.m, scripts/special-matrix/magic.m,
scripts/special-matrix/pascal.m, scripts/special-matrix/rosser.m,
scripts/special-matrix/toeplitz.m, scripts/special-matrix/vander.m,
scripts/special-matrix/wilkinson.m, scripts/testfun/assert.m,
scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/fail.m,
scripts/testfun/rundemos.m, scripts/testfun/runtests.m,
scripts/testfun/speed.m, scripts/time/asctime.m, scripts/time/calendar.m,
scripts/time/clock.m, scripts/time/ctime.m, scripts/time/datenum.m,
scripts/time/datestr.m, scripts/time/datevec.m, scripts/time/etime.m,
scripts/time/is_leap_year.m, scripts/time/now.m, scripts/time/weekday.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 May 2015 17:00:11 -0700 |
parents | e9f89866074c |
children |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19025
diff
changeset
|
1 ## Copyright (C) 2008-2015 John W. Eaton |
8229 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
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}) |
19025
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
22 ## Execute built-in demos for all m-files in the specified @var{directory}. |
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
23 ## |
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
24 ## Demo blocks in any C++ source files (@file{*.cc}) will also be executed |
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
25 ## for use with dynamically linked oct-file functions. |
17456
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
26 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
27 ## If no directory is specified, operate on all directories in Octave's search |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
28 ## path for functions. |
19025
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
29 ## @seealso{demo, runtests, path} |
8229 | 30 ## @end deftypefn |
31 | |
32 ## Author: jwe | |
33 | |
34 function rundemos (directory) | |
35 | |
36 if (nargin == 0) | |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
37 dirs = ostrsplit (path (), pathsep ()); |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
38 do_class_dirs = true; |
8229 | 39 elseif (nargin == 1) |
18059
b675665ce328
Simplify directory testing code for rundemos, runtests.
Rik <rik@octave.org>
parents:
18054
diff
changeset
|
40 dirs = {canonicalize_file_name(directory)}; |
b675665ce328
Simplify directory testing code for rundemos, runtests.
Rik <rik@octave.org>
parents:
18054
diff
changeset
|
41 if (isempty (dirs{1})) |
b675665ce328
Simplify directory testing code for rundemos, runtests.
Rik <rik@octave.org>
parents:
18054
diff
changeset
|
42 ## Search for directory name in path |
b675665ce328
Simplify directory testing code for rundemos, runtests.
Rik <rik@octave.org>
parents:
18054
diff
changeset
|
43 if (directory(end) == '/' || directory(end) == '\') |
b675665ce328
Simplify directory testing code for rundemos, runtests.
Rik <rik@octave.org>
parents:
18054
diff
changeset
|
44 directory(end) = []; |
17148
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
45 endif |
18110
2217bc116aa9
maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
18105
diff
changeset
|
46 fullname = dir_in_loadpath (directory); |
18054
70e83c641b48
Accept a bare directory name for rundemos and runtests.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
47 if (isempty (fullname)) |
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
|
48 error ("rundemos: DIRECTORY argument must be a valid pathname"); |
8229 | 49 endif |
18054
70e83c641b48
Accept a bare directory name for rundemos and runtests.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 dirs = {fullname}; |
8229 | 51 endif |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
52 do_class_dirs = false; |
8229 | 53 else |
54 print_usage (); | |
55 endif | |
56 | |
8231
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
57 for i = 1:numel (dirs) |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
58 d = dirs{i}; |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
59 run_all_demos (d, do_class_dirs); |
8231
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
60 endfor |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
61 |
8229 | 62 endfunction |
63 | |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
64 function run_all_demos (directory, do_class_dirs) |
17459
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
65 flist = readdir (directory); |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
66 dirs = {}; |
8229 | 67 for i = 1:numel (flist) |
17459
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
68 f = flist{i}; |
19865
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
69 if ((length (f) > 2 && strcmpi (f((end-1):end), ".m")) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
70 || (length (f) > 3 && strcmpi (f((end-2):end), ".cc"))) |
8229 | 71 f = fullfile (directory, f); |
72 if (has_demos (f)) | |
14087
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
73 try |
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
74 demo (f); |
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
75 catch |
19025
f27140dd13a6
doc: Update documentation for assert, rundemos, runtests.
Rik <rik@octave.org>
parents:
18110
diff
changeset
|
76 printf ("error: %s\n\n", lasterror ().message); |
14087
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
77 end_try_catch |
10549 | 78 if (i != numel (flist)) |
79 input ("Press <enter> to continue: ", "s"); | |
80 endif | |
8229 | 81 endif |
17459
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
82 elseif (f(1) == "@") |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
83 f = fullfile (directory, f); |
17459
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
84 if (isdir (f)) |
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
85 dirs(end+1) = f; |
f271fa40074d
runtests.m, rundemos.m: Use readdir, rather than dir, for ~700X speed-up.
Rik <rik@octave.org>
parents:
17457
diff
changeset
|
86 endif |
8229 | 87 endif |
88 endfor | |
17457
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
89 |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
90 ## Recurse into class directories since they are implied in the path |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
91 if (do_class_dirs) |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
92 for i = 1:numel (dirs) |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
93 d = dirs{i}; |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
94 run_all_demos (d, false); |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
95 endfor |
a4f86f459744
rundemos.m, runtests.m: Include class directories in path (bug #40053)
Mike Miller <mtmiller@ieee.org>
parents:
17456
diff
changeset
|
96 endif |
8229 | 97 endfunction |
98 | |
99 function retval = has_demos (f) | |
100 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
|
101 if (f < 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
102 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
|
103 else |
17460
9411ad1afa84
rundemos.m: Use regexp, instead of strfind, to report whether a file has_demos.
Rik <rik@octave.org>
parents:
17459
diff
changeset
|
104 str = fread (fid, "*char").'; |
8699
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8245
diff
changeset
|
105 fclose (fid); |
17460
9411ad1afa84
rundemos.m: Use regexp, instead of strfind, to report whether a file has_demos.
Rik <rik@octave.org>
parents:
17459
diff
changeset
|
106 retval = ! isempty (regexp (str, '^%!demo', 'lineanchors', 'once')); |
8699
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8245
diff
changeset
|
107 endif |
8229 | 108 endfunction |
13065
1ca3cde15b18
codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents:
12673
diff
changeset
|
109 |
14214
2fe0f5fa8cc3
Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
110 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
111 %!error rundemos ("foo", 1) |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
112 %!error <DIRECTORY argument> rundemos ("#_TOTALLY_/_INVALID_/_PATHNAME_#") |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
113 |