comparison testing/utp_1.1/generate_report.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % GERERATE_REPORT reads all unit test and generates a report.
2
3 % TODO
4 %
5 % + Format UTP table by hand - not using \utp
6 % + move code block to tables in appendix with same numbering as UTP tables
7 % + add pdf link in UTP table to code block
8 % + keep code indentation from m-file
9 % + wrap strings using utils.prog.wrapstring (or similar) - add ...
10 %
11
12 function report = generate_report()
13
14 setappdata(0, 'ltpda_verbose_level', -1);
15
16 pdfFilename = 'report/report.pdf';
17 texFilename = 'report/ltpda_report_template.html';
18 repFilename = 'report/report.html';
19
20 load resultsave.mat results
21 % results = utp_run('utp_ao_log10');
22 disp(results(1).a);
23 disp(results(1).s);
24 disp(results(1).fcn);
25 disp(results(1).num);
26 disp(results(1).date);
27
28 inFile = fopen(texFilename, 'r');
29
30 methodDescription = '';
31 testDescription = '';
32 syntaxDescription = '';
33 algoDescription = '';
34 syntaxCode = '';
35 algoCode = '';
36
37 writeDirectly = true;
38 outputTex = '';
39
40 % Get the rest:
41 while ~feof(inFile)
42 line = fgetl(inFile);
43
44 if strfind(line, '<!-- Report /-->')
45 writeDirectly = false;
46 preTests = outputTex;
47 outputTex = '';
48 end
49
50 if strfind(line, '<!-- EndReport /-->')
51 writeDirectly = true;
52 end
53
54 if strfind(line, '<!-- MethodDescription /-->')
55 methodDescription = '';
56 while isempty(strfind(line, '<!-- EndMethodDescription /-->'))
57 methodDescription = sprintf('%s%s\n', methodDescription, line);
58 line = fgetl(inFile);
59 end
60 methodDescription = sprintf('%s%s\n', methodDescription, line);
61 end
62
63 if strfind(line, '<!-- TestDescription /-->')
64 testDescription = '';
65 while isempty(strfind(line, '<!-- EndTestDescription /-->'))
66 testDescription = sprintf('%s%s\n', testDescription, line);
67 line = fgetl(inFile);
68 end
69 testDescription = sprintf('%s%s\n', testDescription, line);
70 end
71
72 if strfind(line, '<!-- SyntaxDescription /-->')
73 syntaxDescription = '';
74 while isempty(strfind(line, '<!-- EndSyntaxDescription /-->'))
75 syntaxDescription = sprintf('%s%s\n', syntaxDescription, line);
76 line = fgetl(inFile);
77 end
78 syntaxDescription = sprintf('%s%s\n', syntaxDescription, line);
79 end
80
81 if strfind(line, '<!-- AlgoDescription /-->')
82 algoDescription = '';
83 while isempty(strfind(line, '<!-- EndAlgoDescription /-->'))
84 algoDescription = sprintf('%s%s\n', algoDescription, line);
85 line = fgetl(inFile);
86 end
87 algoDescription = sprintf('%s%s\n', algoDescription, line);
88 end
89
90 if strfind(line, '<!-- SyntaxCode /-->')
91 syntaxCode = '';
92 while isempty(strfind(line, '<!-- EndSyntaxCode /-->'))
93 syntaxCode = sprintf('%s%s\n', syntaxCode, line);
94 line = fgetl(inFile);
95 end
96 syntaxCode = sprintf('%s%s\n', syntaxCode, line);
97 end
98
99 if strfind(line, '<!-- AlgoCode /-->')
100 algoCode = '';
101 while isempty(strfind(line, '<!-- EndAlgoCode /-->'))
102 algoCode = sprintf('%s%s\n', algoCode, line);
103 line = fgetl(inFile);
104 end
105 algoCode = sprintf('%s%s\n', algoCode, line);
106 end
107
108 if writeDirectly
109 outputTex = sprintf('%s%s\n', outputTex, line);
110 end
111 end
112 postTests = outputTex;
113
114 fclose(inFile);
115
116 % All vars are ready, now read test files:
117
118 outFile = fopen(repFilename, 'wt');
119 filenames = {};
120 filenames{end+1} = 's';
121 for i=1:length(results)
122 positions = strfind(results(i).fcn, '_');
123 lastUnderscore = positions(length(positions)) -1;
124 if ~strcmp(filenames{end}, sscanf(results(i).fcn, '%c', lastUnderscore))
125 filenames{end+1} = sscanf(results(i).fcn, '%c', lastUnderscore);
126 end
127 end
128
129 % Print the intro
130 fprintf(outFile, '%s', preTests);
131 temp = '';
132
133 for i=2:length(filenames)
134 filename = ['utps/ao/' filenames{i} '.m'];
135 if exist(filename, 'file')
136 utpRead = fopen(filename);
137
138 headerNumber = 1;
139
140 % Get header:
141 if ~feof(utpRead), header = fgetl(utpRead); end
142 header = remComment(header);
143 header = escTex(header);
144
145 % Get rest:
146 while ~feof(utpRead)
147 line = fgetl(utpRead);
148 line = strtrim(line);
149
150 % if strfind(line, 'function result')
151
152 if strfind(line, '<MethodDescription>')
153 line = fgetl(utpRead);
154 utpMethodDescription = '';
155 while isempty(strfind(line, '</MethodDescription>'))
156 utpMethodDescription = sprintf('%s%s\n', utpMethodDescription, line);
157 line = remComment(fgetl(utpRead));
158 end
159 temp = strrep(methodDescription, '%%%CONTENT%%%', utpMethodDescription);
160 temp = strrep(temp, '%%%HEADER%%%', strrep(filenames{i}, '_', ' '));
161 fprintf(outFile, '%s', temp);
162 end
163
164 if strfind(line, '<TestDescription>')
165 line = fgetl(utpRead);
166 utpTestDescription = '';
167 while isempty(strfind(line, '</TestDescription>'))
168 utpTestDescription = sprintf('%s%s\n', utpTestDescription, line);
169 line = remComment(fgetl(utpRead));
170 end
171 temp = strrep(testDescription, '%%%CONTENT%%%', utpTestDescription);
172 temp = strrep(temp, '%%%HEADER%%%', sprintf('%s %2g', strrep(filenames{i}, '_', ' '), headerNumber));
173 fprintf(outFile, '%s', temp);
174 end
175
176 if strfind(line, '<SyntaxDescription>')
177 line = remComment(fgetl(utpRead));
178 utpSyntaxDescription = '';
179 while isempty(strfind(line, '</SyntaxDescription>'))
180 if ~strcmp(strtrim(line), '')
181 utpSyntaxDescription = sprintf('%s%s <br />\n', utpSyntaxDescription, line);
182 end
183 line = remComment(fgetl(utpRead));
184 end
185 fprintf(outFile, '%s', strrep(syntaxDescription, '%%%CONTENT%%%', utpSyntaxDescription));
186 end
187
188 if strfind(line, '<AlgoDescription>')
189 line = remComment(fgetl(utpRead));
190 utpAlgoDescription = '';
191 while isempty(strfind(line, '</AlgoDescription>'))
192 if ~strcmp(strtrim(line), '')
193 utpAlgoDescription = sprintf('%s%s <br />\n', utpAlgoDescription, line);
194 end
195 line = remComment(fgetl(utpRead));
196 end
197 fprintf(outFile, '%s', strrep(algoDescription, '%%%CONTENT%%%', utpAlgoDescription));
198 end
199
200 if strfind(line, '<SyntaxCode>')
201 line = escComment(fgetl(utpRead));
202 % Get number of spaces before string
203
204 utpSyntaxCode = '';
205 while isempty(strfind(line, '</SyntaxCode>'))
206 utpSyntaxCode = sprintf('%s%s\n', utpSyntaxCode, line);
207 line = escComment(fgetl(utpRead));
208 end
209 fprintf(outFile, '%s', strrep(syntaxCode, '%%%CONTENT%%%', utpSyntaxCode));
210 end
211
212 if strfind(line, '<AlgoCode>')
213 line = escComment(fgetl(utpRead));
214 utpAlgoCode = '';
215 while isempty(strfind(line, '</AlgoCode>'))
216 utpAlgoCode = sprintf('%s%s\n', utpAlgoCode, line);
217 line = escComment(fgetl(utpRead));
218 end
219 fprintf(outFile, '%s', strrep(algoCode, '%%%CONTENT%%%', utpAlgoCode));
220 headerNumber = headerNumber + 1;
221 end
222
223 end
224 fclose(utpRead);
225 end
226
227 end
228
229 % Print the outro
230 fprintf(outFile, '%s', postTests);
231
232 fclose(outFile);
233
234 report = '';
235
236 end
237
238
239 function newString = remComment(string)
240 pos = strfind(string, '%');
241 newString = strtrim(string(pos+1:length(string)));
242 end
243
244 function newString = escComment(string)
245 string = strrep(string, '%', '\%');
246 % string = strtrim(string);
247 newString = sprintf('%s<br />', string);
248 end
249
250 function newString = escTex(string)
251 string = strrep(string, '\', '\\');
252 string = strrep(string, '%', '\%');
253 string = strrep(string, '_', '\_');
254 string = strrep(string, '^', '\^');
255 newString = string;
256 end