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