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 |
5836
|
61 function [dp, dn] = run_test_dir (fid, d); |
5845
|
62 global files_with_tests; |
5840
|
63 global files_with_no_tests; |
5836
|
64 lst = dir (d); |
5590
|
65 dp = dn = 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); |
|
74 [p, n] = test (nm(1:(end-2)), "quiet", fid); |
|
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; |
|
82 endif |
|
83 endfor |
|
84 endfunction |
|
85 |
5836
|
86 function [dp, dn] = run_test_script (fid, d); |
5845
|
87 global files_with_tests; |
5840
|
88 global files_with_no_tests; |
5781
|
89 global topsrcdir; |
6257
|
90 global topbuilddir; |
5836
|
91 lst = dir (d); |
5590
|
92 dp = dn = 0; |
5836
|
93 for i = 1:length (lst) |
5590
|
94 nm = lst(i).name; |
5836
|
95 if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") |
|
96 && ! strcmp (nm, "CVS")) |
|
97 [p, n] = run_test_script (fid, [d, "/", nm]); |
5590
|
98 dp += p; |
|
99 dn += n; |
|
100 endif |
|
101 endfor |
5836
|
102 for i = 1:length (lst) |
5590
|
103 nm = lst(i).name; |
5836
|
104 if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) |
|
105 || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) |
5590
|
106 f = fullfile (d, nm); |
5836
|
107 p = n = 0; |
5590
|
108 ## Only run if it contains %!test, %!assert %!error or %!warning |
5836
|
109 if (hastests (f)) |
6257
|
110 tmp = strrep (f, [topsrcdir, "/"], ""); |
|
111 tmp = strrep (tmp, [topbuilddir, "/"], "../"); |
|
112 print_test_file_name (tmp); |
5836
|
113 [p, n] = test (f, "quiet", fid); |
5840
|
114 print_pass_fail (n, p); |
5590
|
115 dp += p; |
|
116 dn += n; |
5845
|
117 files_with_tests(end+1) = f; |
5840
|
118 else |
|
119 files_with_no_tests(end+1) = f; |
5590
|
120 endif |
|
121 endif |
|
122 endfor |
5667
|
123 ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); |
5590
|
124 endfunction |
|
125 |
5836
|
126 function printf_assert (varargin) |
5590
|
127 global _assert_printf; |
5836
|
128 _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); |
5590
|
129 endfunction |
|
130 |
5836
|
131 function ret = prog_output_assert (str) |
5590
|
132 global _assert_printf; |
5836
|
133 if (isempty (_assert_printf)) |
|
134 ret = isempty (str); |
5590
|
135 elseif (_assert_printf(end) == "\n") |
5836
|
136 ret = strcmp (_assert_printf(1:(end-1)), str); |
5590
|
137 else |
5836
|
138 ret = strcmp (_assert_printf, str); |
5590
|
139 endif |
|
140 _assert_printf = ""; |
|
141 endfunction |
|
142 |
5836
|
143 pso = page_screen_output (); |
|
144 warn_state = warning ("query", "quiet"); |
|
145 warning ("on", "quiet"); |
5590
|
146 try |
5836
|
147 page_screen_output (0); |
|
148 fid = fopen ("fntests.log", "wt"); |
5590
|
149 if (fid < 0) |
5836
|
150 error ("could not open fntests.log for writing"); |
5590
|
151 endif |
5836
|
152 test ("", "explain", fid); |
|
153 dp = dn = 0; |
|
154 printf ("\nIntegrated test scripts:\n\n"); |
|
155 for i = 1:length (fundirs) |
|
156 [p, n] = run_test_script (fid, fundirs{i}); |
|
157 dp += p; |
|
158 dn += n; |
5590
|
159 endfor |
5836
|
160 printf ("\nFixed test scripts:\n\n"); |
|
161 for i = 1:length (testdirs) |
|
162 [p, n] = run_test_dir (fid, testdirs{i}); |
|
163 dp += p; |
|
164 dn += n; |
5590
|
165 endfor |
5836
|
166 printf ("\nSummary:\n\n PASS %6d\n", dp); |
5667
|
167 nfail = dn - dp; |
|
168 printf (" FAIL %6d\n", nfail); |
5845
|
169 n_files_with_no_tests = length (files_with_no_tests); |
|
170 n_files = n_files_with_no_tests + length (files_with_tests); |
6277
|
171 printf ("\n%d (of %d) files have no tests. Please help improve Octave by\n", |
|
172 n_files_with_no_tests, n_files); |
|
173 printf ("contributing tests for these files (see the list in the file fntests.log).\n"); |
5840
|
174 fprintf (fid, "\nFiles with no tests:\n\n%s", |
|
175 list_in_columns (files_with_no_tests, 80)); |
5836
|
176 fclose (fid); |
|
177 page_screen_output (pso); |
|
178 warning (warn_state.state, "quiet"); |
5590
|
179 catch |
5836
|
180 page_screen_output (pso); |
|
181 warning (warn_state.state, "quiet"); |
|
182 disp (lasterr ()); |
5590
|
183 end_try_catch |