Mercurial > octave-antonio
annotate scripts/testfun/rundemos.m @ 17456:2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
* rundemos.m, runtests.m: Copy logic from a previous version of fntests
to operate on C++ source files for development use. Update docstrings.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sat, 21 Sep 2013 07:33:49 -0400 |
parents | fa14aa77b514 |
children | a4f86f459744 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14087
diff
changeset
|
1 ## Copyright (C) 2008-2012 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}) |
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. |
17456
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
23 ## Also executes demos in any C++ source files found in the directory, for |
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
24 ## use with dynamically linked functions. |
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
25 ## |
12668
e3dc23f7dd54
doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 ## 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
|
27 ## 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
|
28 ## @seealso{runtests, path} |
8229 | 29 ## @end deftypefn |
30 | |
31 ## Author: jwe | |
32 | |
33 function rundemos (directory) | |
34 | |
35 if (nargin == 0) | |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
36 dirs = ostrsplit (path (), pathsep ()); |
8229 | 37 elseif (nargin == 1) |
38 if (is_absolute_filename (directory)) | |
39 dirs = {directory}; | |
17148
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
40 elseif (is_rooted_relative_filename (directory)) |
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
41 dirs = {canonicalize_file_name(directory)}; |
8229 | 42 else |
17148
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
43 if (directory(end) == filesep ()) |
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
44 directory = directory(1:end-1); |
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
45 endif |
8229 | 46 fullname = find_dir_in_path (directory); |
47 if (! isempty (fullname)) | |
10549 | 48 dirs = {fullname}; |
8229 | 49 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
|
50 error ("rundemos: DIRECTORY argument must be a valid pathname"); |
8229 | 51 endif |
52 endif | |
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}; |
df28b55d03c0
make rundemos with no arguments work
John W. Eaton <jwe@octave.org>
parents:
8230
diff
changeset
|
59 run_all_demos (d); |
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 | |
64 function run_all_demos (directory) | |
17148
fa14aa77b514
Allow relative directory name for rundemos/runtests.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
65 flist = readdir (directory); |
8229 | 66 for i = 1:numel (flist) |
67 f = flist{i}; | |
17456
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
68 if ((length (f) > 2 && strcmpi (f((end-1):end), ".m")) || |
2c2a6801cb57
rundemos.m, runtests.m: Operate on .cc files (bug #40052)
Mike Miller <mtmiller@ieee.org>
parents:
17148
diff
changeset
|
69 (length (f) > 3 && strcmpi (f((end-2):end), ".cc"))) |
8229 | 70 f = fullfile (directory, f); |
71 if (has_demos (f)) | |
14087
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
72 try |
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
73 demo (f); |
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
74 catch |
15202
f3b5cadfd6d5
fix missing semicolons in various .m files
John W. Eaton <jwe@octave.org>
parents:
14237
diff
changeset
|
75 printf ("error: %s\n\n", lasterror().message); |
14087
8782d41893c6
Add try-catch block to rundemos.
Ben Abbott <bpabbott@mac.com>
parents:
13065
diff
changeset
|
76 end_try_catch |
10549 | 77 if (i != numel (flist)) |
78 input ("Press <enter> to continue: ", "s"); | |
79 endif | |
8229 | 80 endif |
81 endif | |
82 endfor | |
83 endfunction | |
84 | |
85 function retval = has_demos (f) | |
86 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
|
87 if (f < 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
88 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
|
89 else |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8245
diff
changeset
|
90 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
|
91 fclose (fid); |
14214
2fe0f5fa8cc3
Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 retval = strfind (str, "%!demo"); |
8699
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8245
diff
changeset
|
93 endif |
8229 | 94 endfunction |
13065
1ca3cde15b18
codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents:
12673
diff
changeset
|
95 |
14214
2fe0f5fa8cc3
Replace to-be-deprecated findstr occurrences with strfind.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
96 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14214
diff
changeset
|
97 %!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
|
98 %!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
|
99 |