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 |
6730
|
79 function [dp, dn, dxf] = run_test_dir (fid, d); |
5845
|
80 global files_with_tests; |
5840
|
81 global files_with_no_tests; |
5836
|
82 lst = dir (d); |
6730
|
83 dp = dn = dxf = 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); |
6730
|
92 [p, n, xf] = 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; |
5590
|
101 endif |
|
102 endfor |
|
103 endfunction |
|
104 |
6730
|
105 function [dp, dn, dxf] = run_test_script (fid, d); |
5845
|
106 global files_with_tests; |
5840
|
107 global files_with_no_tests; |
5781
|
108 global topsrcdir; |
6257
|
109 global topbuilddir; |
5836
|
110 lst = dir (d); |
6730
|
111 dp = dn = dxf = 0; |
5836
|
112 for i = 1:length (lst) |
5590
|
113 nm = lst(i).name; |
5836
|
114 if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") |
|
115 && ! strcmp (nm, "CVS")) |
6730
|
116 [p, n, xf] = run_test_script (fid, [d, "/", nm]); |
5590
|
117 dp += p; |
|
118 dn += n; |
6730
|
119 dxf += xf; |
5590
|
120 endif |
|
121 endfor |
5836
|
122 for i = 1:length (lst) |
5590
|
123 nm = lst(i).name; |
5836
|
124 if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) |
|
125 || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) |
5590
|
126 f = fullfile (d, nm); |
6730
|
127 p = n = xf = 0; |
5590
|
128 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836
|
129 if (hastests (f)) |
6257
|
130 tmp = strrep (f, [topsrcdir, "/"], ""); |
|
131 tmp = strrep (tmp, [topbuilddir, "/"], "../"); |
|
132 print_test_file_name (tmp); |
6730
|
133 [p, n, xf] = test (f, "quiet", fid); |
5840
|
134 print_pass_fail (n, p); |
5590
|
135 dp += p; |
|
136 dn += n; |
6730
|
137 dxf += xf; |
5845
|
138 files_with_tests(end+1) = f; |
5840
|
139 else |
|
140 files_with_no_tests(end+1) = f; |
5590
|
141 endif |
|
142 endif |
|
143 endfor |
5667
|
144 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590
|
145 endfunction |
|
146 |
5836
|
147 function printf_assert (varargin) |
5590
|
148 global _assert_printf; |
5836
|
149 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590
|
150 endfunction |
|
151 |
5836
|
152 function ret = prog_output_assert (str) |
5590
|
153 global _assert_printf; |
5836
|
154 if (isempty (_assert_printf)) |
|
155 ret = isempty (str); |
5590
|
156 elseif (_assert_printf(end) == "\n") |
5836
|
157 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590
|
158 else |
5836
|
159 ret = strcmp (_assert_printf, str); |
5590
|
160 endif |
|
161 _assert_printf = ""; |
|
162 endfunction |
|
163 |
5836
|
164 pso = page_screen_output (); |
|
165 warn_state = warning ("query", "quiet"); |
|
166 warning ("on", "quiet"); |
5590
|
167 try |
5836
|
168 page_screen_output (0); |
|
169 fid = fopen ("fntests.log", "wt"); |
5590
|
170 if (fid < 0) |
5836
|
171 error ("could not open fntests.log for writing"); |
5590
|
172 endif |
5836
|
173 test ("", "explain", fid); |
6730
|
174 dp = dn = dxf = 0; |
5836
|
175 printf ("\nIntegrated test scripts:\n\n"); |
|
176 for i = 1:length (fundirs) |
6730
|
177 [p, n, xf] = run_test_script (fid, fundirs{i}); |
5836
|
178 dp += p; |
|
179 dn += n; |
6730
|
180 dxf += xf; |
5590
|
181 endfor |
5836
|
182 printf ("\nFixed test scripts:\n\n"); |
|
183 for i = 1:length (testdirs) |
6730
|
184 [p, n, xf] = run_test_dir (fid, testdirs{i}); |
5836
|
185 dp += p; |
|
186 dn += n; |
6730
|
187 dxf += xf; |
5590
|
188 endfor |
5836
|
189 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667
|
190 nfail = dn - dp; |
|
191 printf (" FAIL %6d\n", nfail); |
6730
|
192 if (dxf > 0) |
|
193 printf ("\nThere were %d expected failures (see fntests.log for details).\n", |
|
194 dxf); |
6731
|
195 printf ("\nExpected failures are known bugs. Please help improve\n"); |
|
196 printf ("Octave by contributing fixes for them.\n"); |
6730
|
197 endif |
5845
|
198 n_files_with_no_tests = length (files_with_no_tests); |
|
199 n_files = n_files_with_no_tests + length (files_with_tests); |
6277
|
200 printf ("\n%d (of %d) files have no tests. Please help improve Octave by\n", |
|
201 n_files_with_no_tests, n_files); |
|
202 printf ("contributing tests for these files (see the list in the file fntests.log).\n"); |
5840
|
203 fprintf (fid, "\nFiles with no tests:\n\n%s", |
|
204 list_in_columns (files_with_no_tests, 80)); |
5836
|
205 fclose (fid); |
|
206 page_screen_output (pso); |
|
207 warning (warn_state.state, "quiet"); |
5590
|
208 catch |
5836
|
209 page_screen_output (pso); |
|
210 warning (warn_state.state, "quiet"); |
|
211 disp (lasterr ()); |
5590
|
212 end_try_catch |