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