Mercurial > hg > octave-nkf
annotate scripts/testfun/runtests.m @ 16724:b7667fcb9fbc
Substitute ostrsplit() for strsplit().
The function ostrsplit() is Octave's original strsplit(), and strsplit()
has been modified to be compatible with Matlab's version. Bug #39010.
* scripts/deprecated/javafields.m: Change call to ostrsplit().
* scripts/deprecated/javamethods.m: ditto
* scripts/general/fieldnames.m: ditto
* scripts/general/int2str.m: ditto
* scripts/general/methods.m: ditto
* scripts/general/num2str.m: ditto
* scripts/help/gen_doc_cache.m: ditto
* scripts/help/help.m: ditto
* scripts/help/lookfor.m: ditto
* scripts/io/strread.m: ditto
* scripts/java/javaclasspath.m: ditto
* scripts/miscellaneous/compare_versions.m: ditto
* scripts/miscellaneous/computer.m: ditto
* scripts/miscellaneous/fact.m: ditto
* scripts/miscellaneous/tar.m: ditto
* scripts/miscellaneous/unpack.m: ditto
* scripts/miscellaneous/what.m: ditto
* scripts/miscellaneous/zip.m: ditto
* scripts/pkg/private/configure_make.m: ditto
* scripts/pkg/private/fix_depends.m: ditto
* scripts/pkg/private/generate_lookfor_cache.m: ditto
* scripts/pkg/private/list_forge_packages.m: ditto
* scripts/pkg/private/unload_packages.m: ditto
* scripts/pkg/private/write_index.m: ditto
* scripts/plot/private/__file_filter__.m: ditto
* scripts/plot/private/__fltk_file_filter__.m: ditto
* scripts/plot/private/__go_draw_axes__.m: ditto
* scripts/plot/private/__next_line_style__.m: ditto
* scripts/testfun/rundemos.m: ditto
* scripts/testfun/runtests.m: ditto
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 06 Jun 2013 10:06:12 +0800 |
parents | 1de4ec2a856d |
children | fa14aa77b514 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12673
diff
changeset
|
1 ## Copyright (C) 2010-2012 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) |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
33 dirs = ostrsplit (path (), pathsep ()); |
10496
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 |
12673
64193afe93d8
runtests.m, rundemos.m: Remove final filesep() character from directory name
Rik <octave@nomad.inbox5.com>
parents:
12668
diff
changeset
|
38 directory = regexprep (directory, ['\',filesep(),'$'], ""); |
10496
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 fullname = find_dir_in_path (directory); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 if (! isempty (fullname)) |
10549 | 41 dirs = {fullname}; |
10496
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 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
|
43 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
|
44 endif |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 endif |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 else |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 print_usage (); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 endif |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 for i = 1:numel (dirs) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 d = dirs{i}; |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 run_all_tests (d); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 endfor |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 endfunction |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 function run_all_tests (directory) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 dirinfo = dir (directory); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 flist = {dirinfo.name}; |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 no_tests = {}; |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 printf ("Processing files in %s:\n\n", directory); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 fflush (stdout); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 for i = 1:numel (flist) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 f = flist{i}; |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 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
|
66 ff = fullfile (directory, f); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 if (has_tests (ff)) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 print_test_file_name (f); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 [p, n, xf, sk] = test (ff, "quiet"); |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
70 print_pass_fail (n, p); |
10496
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 fflush (stdout); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 else |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 no_tests{end+1} = f; |
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 endif |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 endfor |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 if (! isempty (no_tests)) |
11024
fa56fd98c0c5
Remove requirement for PCRE in Octave. (Bug #31025)
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
78 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
|
79 printf ("%s", list_in_columns (no_tests)); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 endif |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 endfunction |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 function retval = has_tests (f) |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 fid = fopen (f); |
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 if (fid >= 0) |
11024
fa56fd98c0c5
Remove requirement for PCRE in Octave. (Bug #31025)
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
86 str = fread (fid, "*char")'; |
10496
3b77db443cc0
scripts/testfun/runtests.m: new function
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 fclose (fid); |
12469
0ee8d7d60c82
Use single quotes around regexp patterns.
Rik <octave@nomad.inbox5.com>
parents:
12462
diff
changeset
|
88 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
|
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 |