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