1 ## Copyright (C) 2010-2012 John W. Eaton
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} runtests ()
21 ## @deftypefnx {Function File} {} runtests (@var{directory})
22 ## Execute built-in tests for all function files in the specified directory.
23 ## If no directory is specified, operate on all directories in Octave's
24 ## search path for functions.
25 ## @seealso{rundemos, path}
30 function runtests (directory)
33 dirs = strsplit (path (), pathsep ());
35 if (is_absolute_filename (directory))
38 directory = regexprep (directory, ['\',filesep(),'$'], "");
39 fullname = find_dir_in_path (directory);
40 if (! isempty (fullname))
43 error ("runtests: DIRECTORY argument must be a valid pathname");
50 for i = 1:numel (dirs)
57 function run_all_tests (directory)
58 dirinfo = dir (directory);
59 flist = {dirinfo.name};
61 printf ("Processing files in %s:\n\n", directory);
63 for i = 1:numel (flist)
65 if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
66 ff = fullfile (directory, f);
68 print_test_file_name (f);
69 [p, n, xf, sk] = test (ff, "quiet");
70 print_pass_fail (n, p);
77 if (! isempty (no_tests))
78 printf ("\nThe following files in %s have no tests:\n\n", directory);
79 printf ("%s", list_in_columns (no_tests));
83 function retval = has_tests (f)
86 str = fread (fid, "*char")';
88 retval = ! isempty (regexp (str, '^%!(test|assert|error|warning)', "lineanchors"));
90 error ("runtests: fopen failed: %s", f);
94 function print_pass_fail (n, p)
96 printf (" PASS %4d/%-4d", p, n);
99 printf (" FAIL %d", nfail);
105 function print_test_file_name (nm)
106 filler = repmat (".", 1, 55-length (nm));
107 printf (" %s %s", nm, filler);