Mercurial > hg > octave-nkf
annotate test/fntests.m @ 9741:36840b4ebda6
Remove deprecated functions from list of functions for which it
is necessary to write new tests
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Mon, 19 Oct 2009 19:13:57 -0700 |
parents | 519e164dde1e |
children | 9f8ff01abc65 |
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 | |
8423
869e4213d5d9
fntests.m: use fread instead of fscanf to preserve whitespace
John W. Eaton <jwe@octave.org>
parents:
7762
diff
changeset
|
71 ## FIXME -- should we only try match the keyword at the start of a line? |
5840 | 72 function y = hastests (f) |
73 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
|
74 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
|
75 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
|
76 else |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
77 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
|
78 fclose (fid); |
6e764b7317bd
test/fntests.m, scripts/test/demo.m: error on fopen failures
John W. Eaton <jwe@octave.org>
parents:
8423
diff
changeset
|
79 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
|
80 || 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
|
81 endif |
5840 | 82 endfunction |
83 | |
7243 | 84 function [dp, dn, dxf, dsk] = run_test_dir (fid, d); |
5845 | 85 global files_with_tests; |
5840 | 86 global files_with_no_tests; |
5836 | 87 lst = dir (d); |
7243 | 88 dp = dn = dxf = dsk = 0; |
5836 | 89 for i = 1:length (lst) |
5590 | 90 nm = lst(i).name; |
5836 | 91 if (length (nm) > 5 && strcmp (nm(1:5), "test_") |
92 && strcmp (nm((end-1):end), ".m")) | |
5840 | 93 p = n = 0; |
5845 | 94 ffnm = fullfile (d, nm); |
95 if (hastests (ffnm)) | |
5840 | 96 print_test_file_name (nm); |
7243 | 97 [p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid); |
5840 | 98 print_pass_fail (n, p); |
5845 | 99 files_with_tests(end+1) = ffnm; |
5840 | 100 else |
5845 | 101 files_with_no_tests(end+1) = ffnm; |
5840 | 102 endif |
5836 | 103 dp += p; |
5590 | 104 dn += n; |
6730 | 105 dxf += xf; |
7243 | 106 dsk += sk; |
5590 | 107 endif |
108 endfor | |
109 endfunction | |
110 | |
7243 | 111 function [dp, dn, dxf, dsk] = run_test_script (fid, d); |
5845 | 112 global files_with_tests; |
5840 | 113 global files_with_no_tests; |
5781 | 114 global topsrcdir; |
6257 | 115 global topbuilddir; |
5836 | 116 lst = dir (d); |
7243 | 117 dp = dn = dxf = dsk = 0; |
5836 | 118 for i = 1:length (lst) |
5590 | 119 nm = lst(i).name; |
5836 | 120 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
|
121 && ! strcmp (nm, "CVS") && ! strcmp (nm, "deprecated") ) |
7243 | 122 [p, n, xf, sk] = run_test_script (fid, [d, "/", nm]); |
5590 | 123 dp += p; |
124 dn += n; | |
6730 | 125 dxf += xf; |
7243 | 126 dsk += sk; |
5590 | 127 endif |
128 endfor | |
5836 | 129 for i = 1:length (lst) |
5590 | 130 nm = lst(i).name; |
5836 | 131 if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) |
132 || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) | |
5590 | 133 f = fullfile (d, nm); |
6730 | 134 p = n = xf = 0; |
5590 | 135 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836 | 136 if (hastests (f)) |
6257 | 137 tmp = strrep (f, [topsrcdir, "/"], ""); |
138 tmp = strrep (tmp, [topbuilddir, "/"], "../"); | |
139 print_test_file_name (tmp); | |
7243 | 140 [p, n, xf, sk] = test (f, "quiet", fid); |
5840 | 141 print_pass_fail (n, p); |
5590 | 142 dp += p; |
143 dn += n; | |
6730 | 144 dxf += xf; |
7243 | 145 dsk += sk; |
5845 | 146 files_with_tests(end+1) = f; |
5840 | 147 else |
148 files_with_no_tests(end+1) = f; | |
5590 | 149 endif |
150 endif | |
151 endfor | |
5667 | 152 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590 | 153 endfunction |
154 | |
5836 | 155 function printf_assert (varargin) |
5590 | 156 global _assert_printf; |
5836 | 157 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590 | 158 endfunction |
159 | |
5836 | 160 function ret = prog_output_assert (str) |
5590 | 161 global _assert_printf; |
5836 | 162 if (isempty (_assert_printf)) |
163 ret = isempty (str); | |
5590 | 164 elseif (_assert_printf(end) == "\n") |
5836 | 165 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590 | 166 else |
5836 | 167 ret = strcmp (_assert_printf, str); |
5590 | 168 endif |
169 _assert_printf = ""; | |
170 endfunction | |
171 | |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
172 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
|
173 n = 0; |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
174 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
|
175 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
|
176 n++; |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
177 endif |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
178 endfor |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
179 endfunction |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
180 |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 endfunction |
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
188 |
5836 | 189 pso = page_screen_output (); |
190 warn_state = warning ("query", "quiet"); | |
191 warning ("on", "quiet"); | |
5590 | 192 try |
5836 | 193 page_screen_output (0); |
194 fid = fopen ("fntests.log", "wt"); | |
5590 | 195 if (fid < 0) |
5836 | 196 error ("could not open fntests.log for writing"); |
5590 | 197 endif |
5836 | 198 test ("", "explain", fid); |
7243 | 199 dp = dn = dxf = dsk = 0; |
7762 | 200 puts ("\nIntegrated test scripts:\n\n"); |
5836 | 201 for i = 1:length (fundirs) |
7243 | 202 [p, n, xf, sk] = run_test_script (fid, fundirs{i}); |
5836 | 203 dp += p; |
204 dn += n; | |
6730 | 205 dxf += xf; |
7243 | 206 dsk += sk; |
5590 | 207 endfor |
7762 | 208 puts ("\nFixed test scripts:\n\n"); |
5836 | 209 for i = 1:length (testdirs) |
7243 | 210 [p, n, xf, sk] = run_test_dir (fid, testdirs{i}); |
5836 | 211 dp += p; |
212 dn += n; | |
6730 | 213 dxf += xf; |
7243 | 214 dsk += sk; |
5590 | 215 endfor |
5836 | 216 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667 | 217 nfail = dn - dp; |
218 printf (" FAIL %6d\n", nfail); | |
6730 | 219 if (dxf > 0) |
7291 | 220 if (dxf > 1) |
7300 | 221 t1 = "were"; |
222 t2 = "failures"; | |
7291 | 223 else |
224 t1 = "was"; | |
225 t2 = "failure"; | |
226 endif | |
227 printf ("\nThere %s %d expected %s (see fntests.log for details).\n", | |
228 t1, dxf, t2); | |
7762 | 229 puts ("\nExpected failures are known bugs. Please help improve\n"); |
230 puts ("Octave by contributing fixes for them.\n"); | |
6730 | 231 endif |
7243 | 232 if (dsk > 0) |
9696
01a1fd9167e0
Fix typo directing users to the wrong log file
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
233 printf ("\nThere were %d skipped tests (see fntests.log for details).\n", dsk); |
7762 | 234 puts ("Skipped tests are features that are disabled in this version\n"); |
235 puts ("of Octave as the needed libraries were not present when Octave\n"); | |
236 puts ("was built\n"); | |
7243 | 237 endif |
238 | |
7645
734854f21c94
fntests.m: report number .m and .cc files without tests separately
John W. Eaton <jwe@octave.org>
parents:
7300
diff
changeset
|
239 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
|
240 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
|
241 |
9710
519e164dde1e
Fix typo of an extra space in instructions to user
Rik <rdrider0-list@yahoo.com>
parents:
9696
diff
changeset
|
242 puts ("\nPlease help improve Octave by contributing tests for\n"); |
7762 | 243 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
|
244 |
5840 | 245 fprintf (fid, "\nFiles with no tests:\n\n%s", |
246 list_in_columns (files_with_no_tests, 80)); | |
5836 | 247 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
|
248 |
5836 | 249 page_screen_output (pso); |
250 warning (warn_state.state, "quiet"); | |
5590 | 251 catch |
5836 | 252 page_screen_output (pso); |
253 warning (warn_state.state, "quiet"); | |
254 disp (lasterr ()); | |
5590 | 255 end_try_catch |