annotate scripts/testfun/runtests.m @ 10635:d1978e7364ad

Print name of function in error() string messages.
author Rik <octave@nomad.inbox5.com>
date Sun, 16 May 2010 22:26:54 -0700
parents 95c3e38098bf
children fa56fd98c0c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ## Copyright (C) 2010 John W. Eaton
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 -*-
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## @deftypefn {Function File} {} rundtests (@var{directory})
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 ## @end deftypefn
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ## Author: jwe
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 function runtests (directory)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 if (nargin == 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 dirs = strsplit (path (), pathsep ());
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 elseif (nargin == 1)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 if (is_absolute_filename (directory))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 dirs = {directory};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 fullname = find_dir_in_path (directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 if (! isempty (fullname))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10496
diff changeset
35 dirs = {fullname};
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10496
diff changeset
37 error ("runtests: expecting argument to be a directory name");
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 print_usage ();
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 for i = 1:numel (dirs)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 d = dirs{i};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 run_all_tests (d);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 endfor
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 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 function run_all_tests (directory)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 dirinfo = dir (directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 flist = {dirinfo.name};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 no_tests = {};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 printf ("Processing files in %s:\n\n", directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 fflush (stdout);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 for i = 1:numel (flist)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 f = flist{i};
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 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
60 ff = fullfile (directory, f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 if (has_tests (ff))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 print_test_file_name (f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 [p, n, xf, sk] = test (ff, "quiet");
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 print_pass_fail (n, p)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 fflush (stdout);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 else
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 no_tests{end+1} = f;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 endfor
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 if (! isempty (no_tests))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 printf ("\nThe following files in have no tests:\n\n", directory);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 printf ("%s", list_in_columns (no_tests));
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 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 function retval = has_tests (f)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 retval = false;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 fid = fopen (f);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 if (fid >= 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 while (! feof (fid))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 ln = fgetl (fid);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 if (! isempty (regexp (ln, "%!(assert|error|test)", "lineanchors")))
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 retval = true;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 break;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 endwhile
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 fclose (fid);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
90 error ("runtests: fopen failed: %s", f);
10496
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 function print_pass_fail (n, p)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 if (n > 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 printf (" PASS %4d/%-4d", p, n);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 nfail = n - p;
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 if (nfail > 0)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 printf (" FAIL %d", nfail);
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 endif
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 puts ("\n");
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 endfunction
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 function print_test_file_name (nm)
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 filler = repmat (".", 1, 55-length (nm));
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 printf (" %s %s", nm, filler);
3b77db443cc0 scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 endfunction