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 |
|
68 printf ("\n"); |
|
69 endfunction |
|
70 |
5840
|
71 function y = hastests (f) |
|
72 fid = fopen (f); |
|
73 str = fscanf (fid, "%s"); |
|
74 fclose (fid); |
|
75 y = (findstr (str, "%!test") || findstr (str, "%!assert") |
|
76 || findstr (str, "%!error") || findstr (str, "%!warning")); |
|
77 endfunction |
|
78 |
7243
|
79 function [dp, dn, dxf, dsk] = run_test_dir (fid, d); |
5845
|
80 global files_with_tests; |
5840
|
81 global files_with_no_tests; |
5836
|
82 lst = dir (d); |
7243
|
83 dp = dn = dxf = dsk = 0; |
5836
|
84 for i = 1:length (lst) |
5590
|
85 nm = lst(i).name; |
5836
|
86 if (length (nm) > 5 && strcmp (nm(1:5), "test_") |
|
87 && strcmp (nm((end-1):end), ".m")) |
5840
|
88 p = n = 0; |
5845
|
89 ffnm = fullfile (d, nm); |
|
90 if (hastests (ffnm)) |
5840
|
91 print_test_file_name (nm); |
7243
|
92 [p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid); |
5840
|
93 print_pass_fail (n, p); |
5845
|
94 files_with_tests(end+1) = ffnm; |
5840
|
95 else |
5845
|
96 files_with_no_tests(end+1) = ffnm; |
5840
|
97 endif |
5836
|
98 dp += p; |
5590
|
99 dn += n; |
6730
|
100 dxf += xf; |
7243
|
101 dsk += sk; |
5590
|
102 endif |
|
103 endfor |
|
104 endfunction |
|
105 |
7243
|
106 function [dp, dn, dxf, dsk] = run_test_script (fid, d); |
5845
|
107 global files_with_tests; |
5840
|
108 global files_with_no_tests; |
5781
|
109 global topsrcdir; |
6257
|
110 global topbuilddir; |
5836
|
111 lst = dir (d); |
7243
|
112 dp = dn = dxf = dsk = 0; |
5836
|
113 for i = 1:length (lst) |
5590
|
114 nm = lst(i).name; |
5836
|
115 if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") |
|
116 && ! strcmp (nm, "CVS")) |
7243
|
117 [p, n, xf, sk] = run_test_script (fid, [d, "/", nm]); |
5590
|
118 dp += p; |
|
119 dn += n; |
6730
|
120 dxf += xf; |
7243
|
121 dsk += sk; |
5590
|
122 endif |
|
123 endfor |
5836
|
124 for i = 1:length (lst) |
5590
|
125 nm = lst(i).name; |
5836
|
126 if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) |
|
127 || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) |
5590
|
128 f = fullfile (d, nm); |
6730
|
129 p = n = xf = 0; |
5590
|
130 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836
|
131 if (hastests (f)) |
6257
|
132 tmp = strrep (f, [topsrcdir, "/"], ""); |
|
133 tmp = strrep (tmp, [topbuilddir, "/"], "../"); |
|
134 print_test_file_name (tmp); |
7243
|
135 [p, n, xf, sk] = test (f, "quiet", fid); |
5840
|
136 print_pass_fail (n, p); |
5590
|
137 dp += p; |
|
138 dn += n; |
6730
|
139 dxf += xf; |
7243
|
140 dsk += sk; |
5845
|
141 files_with_tests(end+1) = f; |
5840
|
142 else |
|
143 files_with_no_tests(end+1) = f; |
5590
|
144 endif |
|
145 endif |
|
146 endfor |
5667
|
147 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590
|
148 endfunction |
|
149 |
5836
|
150 function printf_assert (varargin) |
5590
|
151 global _assert_printf; |
5836
|
152 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590
|
153 endfunction |
|
154 |
5836
|
155 function ret = prog_output_assert (str) |
5590
|
156 global _assert_printf; |
5836
|
157 if (isempty (_assert_printf)) |
|
158 ret = isempty (str); |
5590
|
159 elseif (_assert_printf(end) == "\n") |
5836
|
160 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590
|
161 else |
5836
|
162 ret = strcmp (_assert_printf, str); |
5590
|
163 endif |
|
164 _assert_printf = ""; |
|
165 endfunction |
|
166 |
5836
|
167 pso = page_screen_output (); |
|
168 warn_state = warning ("query", "quiet"); |
|
169 warning ("on", "quiet"); |
5590
|
170 try |
5836
|
171 page_screen_output (0); |
|
172 fid = fopen ("fntests.log", "wt"); |
5590
|
173 if (fid < 0) |
5836
|
174 error ("could not open fntests.log for writing"); |
5590
|
175 endif |
5836
|
176 test ("", "explain", fid); |
7243
|
177 dp = dn = dxf = dsk = 0; |
5836
|
178 printf ("\nIntegrated test scripts:\n\n"); |
|
179 for i = 1:length (fundirs) |
7243
|
180 [p, n, xf, sk] = run_test_script (fid, fundirs{i}); |
5836
|
181 dp += p; |
|
182 dn += n; |
6730
|
183 dxf += xf; |
7243
|
184 dsk += sk; |
5590
|
185 endfor |
5836
|
186 printf ("\nFixed test scripts:\n\n"); |
|
187 for i = 1:length (testdirs) |
7243
|
188 [p, n, xf, sk] = run_test_dir (fid, testdirs{i}); |
5836
|
189 dp += p; |
|
190 dn += n; |
6730
|
191 dxf += xf; |
7243
|
192 dsk += sk; |
5590
|
193 endfor |
5836
|
194 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667
|
195 nfail = dn - dp; |
|
196 printf (" FAIL %6d\n", nfail); |
6730
|
197 if (dxf > 0) |
7291
|
198 if (dxf > 1) |
7300
|
199 t1 = "were"; |
|
200 t2 = "failures"; |
7291
|
201 else |
|
202 t1 = "was"; |
|
203 t2 = "failure"; |
|
204 endif |
|
205 printf ("\nThere %s %d expected %s (see fntests.log for details).\n", |
|
206 t1, dxf, t2); |
6731
|
207 printf ("\nExpected failures are known bugs. Please help improve\n"); |
|
208 printf ("Octave by contributing fixes for them.\n"); |
6730
|
209 endif |
7243
|
210 if (dsk > 0) |
|
211 printf ("\nThere were %d skipped tests (see fntest.log for details).\n", dsk); |
|
212 printf ("Skipped tests are features that are disabled in this version\n"); |
|
213 printf ("of Octave as the needed libraries were not present when Octave\n"); |
|
214 printf ("was built\n"); |
|
215 endif |
|
216 |
5845
|
217 n_files_with_no_tests = length (files_with_no_tests); |
|
218 n_files = n_files_with_no_tests + length (files_with_tests); |
6277
|
219 printf ("\n%d (of %d) files have no tests. Please help improve Octave by\n", |
|
220 n_files_with_no_tests, n_files); |
|
221 printf ("contributing tests for these files (see the list in the file fntests.log).\n"); |
5840
|
222 fprintf (fid, "\nFiles with no tests:\n\n%s", |
|
223 list_in_columns (files_with_no_tests, 80)); |
5836
|
224 fclose (fid); |
|
225 page_screen_output (pso); |
|
226 warning (warn_state.state, "quiet"); |
5590
|
227 catch |
5836
|
228 page_screen_output (pso); |
|
229 warning (warn_state.state, "quiet"); |
|
230 disp (lasterr ()); |
5590
|
231 end_try_catch |