Mercurial > hg > octave-jordi
annotate test/fntests.m @ 9967:75503ecdac32
ChangeLog fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 11 Dec 2009 13:46:24 -0500 |
parents | 9f8ff01abc65 |
children | 9b3a100922a6 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2005, 2006, 2007, 2008, 2009 David Bateman |
7016 | 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 | |
5590 | 19 clear all; |
20 | |
5840 | 21 global files_with_no_tests = {}; |
5845 | 22 global files_with_tests = {}; |
5590 | 23 global topsrcdir; |
6257 | 24 global topbuilddir; |
5590 | 25 |
26 currdir = canonicalize_file_name ("."); | |
27 | |
28 if (nargin == 1) | |
5781 | 29 xdir = argv(){1}; |
5590 | 30 else |
31 xdir = "."; | |
32 endif | |
33 | |
34 srcdir = canonicalize_file_name (xdir); | |
35 topsrcdir = canonicalize_file_name (fullfile (xdir, "..")); | |
6257 | 36 topbuilddir = canonicalize_file_name (fullfile (currdir, "..")); |
5590 | 37 |
38 if (strcmp (currdir, srcdir)) | |
39 testdirs = {srcdir}; | |
40 else | |
41 testdirs = {currdir, srcdir}; | |
42 endif | |
43 | |
44 src_tree = canonicalize_file_name (fullfile (topsrcdir, "src")); | |
6257 | 45 liboctave_tree = canonicalize_file_name (fullfile (topsrcdir, "liboctave")); |
5590 | 46 script_tree = canonicalize_file_name (fullfile (topsrcdir, "scripts")); |
6257 | 47 local_script_tree = canonicalize_file_name (fullfile (currdir, "../scripts")); |
48 | |
6162 | 49 fundirs = {src_tree, liboctave_tree, script_tree}; |
5590 | 50 |
6257 | 51 if (! strcmp (currdir, srcdir)) |
52 fundirs{end+1} = local_script_tree; | |
53 endif | |
54 | |
5836 | 55 function print_test_file_name (nm) |
56 filler = repmat (".", 1, 55-length (nm)); | |
57 printf (" %s %s", nm, filler); | |
58 endfunction | |
59 | |
60 function print_pass_fail (n, p) | |
61 if (n > 0) | |
62 printf (" PASS %4d/%-4d", p, n); | |
63 nfail = n - p; | |
64 if (nfail > 0) | |
65 printf (" FAIL %d", nfail); | |
66 endif | |
67 endif | |
7762 | 68 puts ("\n"); |
5836 | 69 endfunction |
70 | |
9742
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
71 function y = hasfunctions (f) |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
72 fid = fopen (f); |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
73 if (fid < 0) |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
74 error ("fopen failed: %s", f); |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
75 else |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
76 str = fread (fid, "*char")'; |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
77 fclose (fid); |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
78 y = regexp (str,'^(DEFUN|DEFUN_DLD)\b', "lineanchors"); |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
79 endif |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
80 endfunction |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
81 |
8423
869e4213d5d9
fntests.m: use fread instead of fscanf to preserve whitespace
John W. Eaton <jwe@octave.org>
parents:
7762
diff
changeset
|
82 ## FIXME -- should we only try match the keyword at the start of a line? |
5840 | 83 function y = hastests (f) |
84 fid = fopen (f); | |
8699
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
85 if (fid < 0) |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
86 error ("fopen failed: %s", f); |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
87 else |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
88 str = fread (fid, "*char")'; |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
89 fclose (fid); |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
90 y = (findstr (str, "%!test") || findstr (str, "%!assert") |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
91 || findstr (str, "%!error") || findstr (str, "%!warning")); |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
92 endif |
5840 | 93 endfunction |
94 | |
7243 | 95 function [dp, dn, dxf, dsk] = run_test_dir (fid, d); |
5845 | 96 global files_with_tests; |
5840 | 97 global files_with_no_tests; |
5836 | 98 lst = dir (d); |
7243 | 99 dp = dn = dxf = dsk = 0; |
5836 | 100 for i = 1:length (lst) |
5590 | 101 nm = lst(i).name; |
5836 | 102 if (length (nm) > 5 && strcmp (nm(1:5), "test_") |
103 && strcmp (nm((end-1):end), ".m")) | |
5840 | 104 p = n = 0; |
5845 | 105 ffnm = fullfile (d, nm); |
106 if (hastests (ffnm)) | |
5840 | 107 print_test_file_name (nm); |
7243 | 108 [p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid); |
5840 | 109 print_pass_fail (n, p); |
5845 | 110 files_with_tests(end+1) = ffnm; |
5840 | 111 else |
5845 | 112 files_with_no_tests(end+1) = ffnm; |
5840 | 113 endif |
5836 | 114 dp += p; |
5590 | 115 dn += n; |
6730 | 116 dxf += xf; |
7243 | 117 dsk += sk; |
5590 | 118 endif |
119 endfor | |
120 endfunction | |
121 | |
7243 | 122 function [dp, dn, dxf, dsk] = run_test_script (fid, d); |
5845 | 123 global files_with_tests; |
5840 | 124 global files_with_no_tests; |
5781 | 125 global topsrcdir; |
6257 | 126 global topbuilddir; |
5836 | 127 lst = dir (d); |
7243 | 128 dp = dn = dxf = dsk = 0; |
5836 | 129 for i = 1:length (lst) |
5590 | 130 nm = lst(i).name; |
5836 | 131 if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") |
9741
36840b4ebda6
Remove deprecated functions from list of functions for which it
Rik <rdrider0-list@yahoo.com>
parents:
9710
diff
changeset
|
132 && ! strcmp (nm, "CVS") && ! strcmp (nm, "deprecated") ) |
7243 | 133 [p, n, xf, sk] = run_test_script (fid, [d, "/", nm]); |
5590 | 134 dp += p; |
135 dn += n; | |
6730 | 136 dxf += xf; |
7243 | 137 dsk += sk; |
5590 | 138 endif |
139 endfor | |
5836 | 140 for i = 1:length (lst) |
5590 | 141 nm = lst(i).name; |
9742
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
142 f = fullfile (d, nm); |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
143 if ((length (nm) > 2 && strcmp (nm((end-1):end), ".m")) || |
9f8ff01abc65
.cc files are now included in the list of files requiring
Rik <rdrider0-list@yahoo.com>
parents:
9741
diff
changeset
|
144 (length (nm) > 3 && strcmp (nm((end-2):end), ".cc") && hasfunctions(f))) |
6730 | 145 p = n = xf = 0; |
5590 | 146 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836 | 147 if (hastests (f)) |
6257 | 148 tmp = strrep (f, [topsrcdir, "/"], ""); |
149 tmp = strrep (tmp, [topbuilddir, "/"], "../"); | |
150 print_test_file_name (tmp); | |
7243 | 151 [p, n, xf, sk] = test (f, "quiet", fid); |
5840 | 152 print_pass_fail (n, p); |
5590 | 153 dp += p; |
154 dn += n; | |
6730 | 155 dxf += xf; |
7243 | 156 dsk += sk; |
5845 | 157 files_with_tests(end+1) = f; |
5840 | 158 else |
159 files_with_no_tests(end+1) = f; | |
5590 | 160 endif |
161 endif | |
162 endfor | |
5667 | 163 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590 | 164 endfunction |
165 | |
5836 | 166 function printf_assert (varargin) |
5590 | 167 global _assert_printf; |
5836 | 168 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590 | 169 endfunction |
170 | |
5836 | 171 function ret = prog_output_assert (str) |
5590 | 172 global _assert_printf; |
5836 | 173 if (isempty (_assert_printf)) |
174 ret = isempty (str); | |
5590 | 175 elseif (_assert_printf(end) == "\n") |
5836 | 176 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590 | 177 else |
5836 | 178 ret = strcmp (_assert_printf, str); |
5590 | 179 endif |
180 _assert_printf = ""; | |
181 endfunction | |
182 | |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
183 function n = num_elts_matching_pattern (lst, pat) |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
184 n = 0; |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
185 for i = 1:length (lst) |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
186 if (! isempty (regexp (lst{i}, pat))) |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
187 n++; |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
188 endif |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
189 endfor |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
190 endfunction |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
191 |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
192 function report_files_with_no_tests (with, without, typ) |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
193 pat = cstrcat ("\\", typ, "$"); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
194 n_with = num_elts_matching_pattern (with, pat); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
195 n_without = num_elts_matching_pattern (without, pat); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
196 n_tot = n_with + n_without; |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
197 printf ("\n%d (of %d) %s files have no tests.\n", n_without, n_tot, typ); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
198 endfunction |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
199 |
5836 | 200 pso = page_screen_output (); |
201 warn_state = warning ("query", "quiet"); | |
202 warning ("on", "quiet"); | |
5590 | 203 try |
5836 | 204 page_screen_output (0); |
205 fid = fopen ("fntests.log", "wt"); | |
5590 | 206 if (fid < 0) |
5836 | 207 error ("could not open fntests.log for writing"); |
5590 | 208 endif |
5836 | 209 test ("", "explain", fid); |
7243 | 210 dp = dn = dxf = dsk = 0; |
7762 | 211 puts ("\nIntegrated test scripts:\n\n"); |
5836 | 212 for i = 1:length (fundirs) |
7243 | 213 [p, n, xf, sk] = run_test_script (fid, fundirs{i}); |
5836 | 214 dp += p; |
215 dn += n; | |
6730 | 216 dxf += xf; |
7243 | 217 dsk += sk; |
5590 | 218 endfor |
7762 | 219 puts ("\nFixed test scripts:\n\n"); |
5836 | 220 for i = 1:length (testdirs) |
7243 | 221 [p, n, xf, sk] = run_test_dir (fid, testdirs{i}); |
5836 | 222 dp += p; |
223 dn += n; | |
6730 | 224 dxf += xf; |
7243 | 225 dsk += sk; |
5590 | 226 endfor |
5836 | 227 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667 | 228 nfail = dn - dp; |
229 printf (" FAIL %6d\n", nfail); | |
6730 | 230 if (dxf > 0) |
7291 | 231 if (dxf > 1) |
7300 | 232 t1 = "were"; |
233 t2 = "failures"; | |
7291 | 234 else |
235 t1 = "was"; | |
236 t2 = "failure"; | |
237 endif | |
238 printf ("\nThere %s %d expected %s (see fntests.log for details).\n", | |
239 t1, dxf, t2); | |
7762 | 240 puts ("\nExpected failures are known bugs. Please help improve\n"); |
241 puts ("Octave by contributing fixes for them.\n"); | |
6730 | 242 endif |
7243 | 243 if (dsk > 0) |
9696
01a1fd9167e0
Fix typo directing users to the wrong log file
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
244 printf ("\nThere were %d skipped tests (see fntests.log for details).\n", dsk); |
7762 | 245 puts ("Skipped tests are features that are disabled in this version\n"); |
246 puts ("of Octave as the needed libraries were not present when Octave\n"); | |
247 puts ("was built\n"); | |
7243 | 248 endif |
249 | |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
250 report_files_with_no_tests (files_with_tests, files_with_no_tests, ".m"); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
251 report_files_with_no_tests (files_with_tests, files_with_no_tests, ".cc"); |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
252 |
9710
519e164dde1e
Fix typo of an extra space in instructions to user
Rik <rdrider0-list@yahoo.com>
parents:
9696
diff
changeset
|
253 puts ("\nPlease help improve Octave by contributing tests for\n"); |
7762 | 254 puts ("these files (see the list in the file fntests.log).\n"); |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
255 |
5840 | 256 fprintf (fid, "\nFiles with no tests:\n\n%s", |
257 list_in_columns (files_with_no_tests, 80)); | |
5836 | 258 fclose (fid); |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
259 |
5836 | 260 page_screen_output (pso); |
261 warning (warn_state.state, "quiet"); | |
5590 | 262 catch |
5836 | 263 page_screen_output (pso); |
264 warning (warn_state.state, "quiet"); | |
265 disp (lasterr ()); | |
5590 | 266 end_try_catch |