5590
|
1 clear all; |
|
2 |
5840
|
3 global files_with_no_tests = {}; |
5845
|
4 global files_with_tests = {}; |
5590
|
5 global topsrcdir; |
6257
|
6 global topbuilddir; |
5590
|
7 |
|
8 currdir = canonicalize_file_name ("."); |
|
9 |
|
10 if (nargin == 1) |
5781
|
11 xdir = argv(){1}; |
5590
|
12 else |
|
13 xdir = "."; |
|
14 endif |
|
15 |
|
16 srcdir = canonicalize_file_name (xdir); |
|
17 topsrcdir = canonicalize_file_name (fullfile (xdir, "..")); |
6257
|
18 topbuilddir = canonicalize_file_name (fullfile (currdir, "..")); |
5590
|
19 |
|
20 if (strcmp (currdir, srcdir)) |
|
21 testdirs = {srcdir}; |
|
22 else |
|
23 testdirs = {currdir, srcdir}; |
|
24 endif |
|
25 |
|
26 src_tree = canonicalize_file_name (fullfile (topsrcdir, "src")); |
6257
|
27 liboctave_tree = canonicalize_file_name (fullfile (topsrcdir, "liboctave")); |
5590
|
28 script_tree = canonicalize_file_name (fullfile (topsrcdir, "scripts")); |
6257
|
29 local_script_tree = canonicalize_file_name (fullfile (currdir, "../scripts")); |
|
30 |
6162
|
31 fundirs = {src_tree, liboctave_tree, script_tree}; |
5590
|
32 |
6257
|
33 if (! strcmp (currdir, srcdir)) |
|
34 fundirs{end+1} = local_script_tree; |
|
35 endif |
|
36 |
5836
|
37 function print_test_file_name (nm) |
|
38 filler = repmat (".", 1, 55-length (nm)); |
|
39 printf (" %s %s", nm, filler); |
|
40 endfunction |
|
41 |
|
42 function print_pass_fail (n, p) |
|
43 if (n > 0) |
|
44 printf (" PASS %4d/%-4d", p, n); |
|
45 nfail = n - p; |
|
46 if (nfail > 0) |
|
47 printf (" FAIL %d", nfail); |
|
48 endif |
|
49 endif |
|
50 printf ("\n"); |
|
51 endfunction |
|
52 |
5840
|
53 function y = hastests (f) |
|
54 fid = fopen (f); |
|
55 str = fscanf (fid, "%s"); |
|
56 fclose (fid); |
|
57 y = (findstr (str, "%!test") || findstr (str, "%!assert") |
|
58 || findstr (str, "%!error") || findstr (str, "%!warning")); |
|
59 endfunction |
|
60 |
6730
|
61 function [dp, dn, dxf] = run_test_dir (fid, d); |
5845
|
62 global files_with_tests; |
5840
|
63 global files_with_no_tests; |
5836
|
64 lst = dir (d); |
6730
|
65 dp = dn = dxf = 0; |
5836
|
66 for i = 1:length (lst) |
5590
|
67 nm = lst(i).name; |
5836
|
68 if (length (nm) > 5 && strcmp (nm(1:5), "test_") |
|
69 && strcmp (nm((end-1):end), ".m")) |
5840
|
70 p = n = 0; |
5845
|
71 ffnm = fullfile (d, nm); |
|
72 if (hastests (ffnm)) |
5840
|
73 print_test_file_name (nm); |
6730
|
74 [p, n, xf] = test (nm(1:(end-2)), "quiet", fid); |
5840
|
75 print_pass_fail (n, p); |
5845
|
76 files_with_tests(end+1) = ffnm; |
5840
|
77 else |
5845
|
78 files_with_no_tests(end+1) = ffnm; |
5840
|
79 endif |
5836
|
80 dp += p; |
5590
|
81 dn += n; |
6730
|
82 dxf += xf; |
5590
|
83 endif |
|
84 endfor |
|
85 endfunction |
|
86 |
6730
|
87 function [dp, dn, dxf] = run_test_script (fid, d); |
5845
|
88 global files_with_tests; |
5840
|
89 global files_with_no_tests; |
5781
|
90 global topsrcdir; |
6257
|
91 global topbuilddir; |
5836
|
92 lst = dir (d); |
6730
|
93 dp = dn = dxf = 0; |
5836
|
94 for i = 1:length (lst) |
5590
|
95 nm = lst(i).name; |
5836
|
96 if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") |
|
97 && ! strcmp (nm, "CVS")) |
6730
|
98 [p, n, xf] = run_test_script (fid, [d, "/", nm]); |
5590
|
99 dp += p; |
|
100 dn += n; |
6730
|
101 dxf += xf; |
5590
|
102 endif |
|
103 endfor |
5836
|
104 for i = 1:length (lst) |
5590
|
105 nm = lst(i).name; |
5836
|
106 if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) |
|
107 || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) |
5590
|
108 f = fullfile (d, nm); |
6730
|
109 p = n = xf = 0; |
5590
|
110 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836
|
111 if (hastests (f)) |
6257
|
112 tmp = strrep (f, [topsrcdir, "/"], ""); |
|
113 tmp = strrep (tmp, [topbuilddir, "/"], "../"); |
|
114 print_test_file_name (tmp); |
6730
|
115 [p, n, xf] = test (f, "quiet", fid); |
5840
|
116 print_pass_fail (n, p); |
5590
|
117 dp += p; |
|
118 dn += n; |
6730
|
119 dxf += xf; |
5845
|
120 files_with_tests(end+1) = f; |
5840
|
121 else |
|
122 files_with_no_tests(end+1) = f; |
5590
|
123 endif |
|
124 endif |
|
125 endfor |
5667
|
126 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590
|
127 endfunction |
|
128 |
5836
|
129 function printf_assert (varargin) |
5590
|
130 global _assert_printf; |
5836
|
131 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590
|
132 endfunction |
|
133 |
5836
|
134 function ret = prog_output_assert (str) |
5590
|
135 global _assert_printf; |
5836
|
136 if (isempty (_assert_printf)) |
|
137 ret = isempty (str); |
5590
|
138 elseif (_assert_printf(end) == "\n") |
5836
|
139 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590
|
140 else |
5836
|
141 ret = strcmp (_assert_printf, str); |
5590
|
142 endif |
|
143 _assert_printf = ""; |
|
144 endfunction |
|
145 |
5836
|
146 pso = page_screen_output (); |
|
147 warn_state = warning ("query", "quiet"); |
|
148 warning ("on", "quiet"); |
5590
|
149 try |
5836
|
150 page_screen_output (0); |
|
151 fid = fopen ("fntests.log", "wt"); |
5590
|
152 if (fid < 0) |
5836
|
153 error ("could not open fntests.log for writing"); |
5590
|
154 endif |
5836
|
155 test ("", "explain", fid); |
6730
|
156 dp = dn = dxf = 0; |
5836
|
157 printf ("\nIntegrated test scripts:\n\n"); |
|
158 for i = 1:length (fundirs) |
6730
|
159 [p, n, xf] = run_test_script (fid, fundirs{i}); |
5836
|
160 dp += p; |
|
161 dn += n; |
6730
|
162 dxf += xf; |
5590
|
163 endfor |
5836
|
164 printf ("\nFixed test scripts:\n\n"); |
|
165 for i = 1:length (testdirs) |
6730
|
166 [p, n, xf] = run_test_dir (fid, testdirs{i}); |
5836
|
167 dp += p; |
|
168 dn += n; |
6730
|
169 dxf += xf; |
5590
|
170 endfor |
5836
|
171 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667
|
172 nfail = dn - dp; |
|
173 printf (" FAIL %6d\n", nfail); |
6730
|
174 if (dxf > 0) |
|
175 printf ("\nThere were %d expected failures (see fntests.log for details).\n", |
|
176 dxf); |
|
177 endif |
5845
|
178 n_files_with_no_tests = length (files_with_no_tests); |
|
179 n_files = n_files_with_no_tests + length (files_with_tests); |
6277
|
180 printf ("\n%d (of %d) files have no tests. Please help improve Octave by\n", |
|
181 n_files_with_no_tests, n_files); |
|
182 printf ("contributing tests for these files (see the list in the file fntests.log).\n"); |
5840
|
183 fprintf (fid, "\nFiles with no tests:\n\n%s", |
|
184 list_in_columns (files_with_no_tests, 80)); |
5836
|
185 fclose (fid); |
|
186 page_screen_output (pso); |
|
187 warning (warn_state.state, "quiet"); |
5590
|
188 catch |
5836
|
189 page_screen_output (pso); |
|
190 warning (warn_state.state, "quiet"); |
|
191 disp (lasterr ()); |
5590
|
192 end_try_catch |