annotate scripts/testfun/runtests.m @ 12668:e3dc23f7dd54 stable

doc: Improve a few docstrings related to test functions and directories. * what.m, rundemos.m, runtests.m, dirfns.cc (filesep), utils.cc (find_dir_in_path): Improve docstrings.
author Rik <octave@nomad.inbox5.com>
date Sat, 14 May 2011 21:17:20 -0700
parents 0ee8d7d60c82
children 64193afe93d8
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) 2010-2011 John W. Eaton
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
3b77db443cc0 scripts/testfun/runtests.m: new function
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: 12469
diff changeset
20 ## @deftypefn {Function File} {} runtests ()
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 12469
diff changeset
21 ## @deftypefnx {Function File} {} runtests (@var{directory})
11024
fa56fd98c0c5 Remove requirement for PCRE in Octave. (Bug #31025)
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
22 ## Execute built-in tests for all function files in the specified directory.
12668
e3dc23f7dd54 doc: Improve a few docstrings related to test functions and directories.
Rik <octave@nomad.inbox5.com>
parents: 12469
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: 12469
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: 12469
diff changeset
25 ## @seealso{rundemos, path}
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ## @end deftypefn
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 ## Author: jwe
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 function runtests (directory)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 if (nargin == 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 dirs = strsplit (path (), pathsep ());
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 elseif (nargin == 1)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 if (is_absolute_filename (directory))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 dirs = {directory};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 fullname = find_dir_in_path (directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 if (! isempty (fullname))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10496
diff changeset
40 dirs = {fullname};
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 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: 11032
diff changeset
42 error ("runtests: DIRECTORY argument must be a valid pathname");
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 print_usage ();
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 for i = 1:numel (dirs)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 d = dirs{i};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 run_all_tests (d);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 endfor
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 function run_all_tests (directory)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 dirinfo = dir (directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 flist = {dirinfo.name};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 no_tests = {};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 printf ("Processing files in %s:\n\n", directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 fflush (stdout);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 for i = 1:numel (flist)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 f = flist{i};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 ff = fullfile (directory, f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 if (has_tests (ff))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 print_test_file_name (f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 [p, n, xf, sk] = test (ff, "quiet");
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
69 print_pass_fail (n, p);
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 fflush (stdout);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 no_tests{end+1} = f;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 endfor
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (! isempty (no_tests))
11024
fa56fd98c0c5 Remove requirement for PCRE in Octave. (Bug #31025)
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
77 printf ("\nThe following files in %s have no tests:\n\n", directory);
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 printf ("%s", list_in_columns (no_tests));
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 function retval = has_tests (f)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 fid = fopen (f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 if (fid >= 0)
11024
fa56fd98c0c5 Remove requirement for PCRE in Octave. (Bug #31025)
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
85 str = fread (fid, "*char")';
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 fclose (fid);
12469
0ee8d7d60c82 Use single quotes around regexp patterns.
Rik <octave@nomad.inbox5.com>
parents: 12462
diff changeset
87 retval = ! isempty (regexp (str, '^%!(test|assert|error|warning)', "lineanchors"));
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
89 error ("runtests: fopen failed: %s", f);
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 function print_pass_fail (n, p)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 if (n > 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 printf (" PASS %4d/%-4d", p, n);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 nfail = n - p;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 if (nfail > 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 printf (" FAIL %d", nfail);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 puts ("\n");
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 function print_test_file_name (nm)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 filler = repmat (".", 1, 55-length (nm));
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 printf (" %s %s", nm, filler);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 endfunction