Mercurial > hg > ltpda
comparison testing/utp_1.1/utp_run.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 | 9d5c88356247 |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_RUN Runs the UTP tests found in the 'utps' directory. If no output | |
2 % argument is specified a results report is generated and printed to screen, | |
3 % otherwise the results are returned. | |
4 % | |
5 % USAGE: | |
6 % | |
7 % >> % run all the tests in the 'utps' directory | |
8 % >> utp_run(); | |
9 % | |
10 % >> % run the UTPs with the given names | |
11 % >> utp_run('utp_classname_fcn1', 'utp_classname_fcn2', ...); | |
12 % | |
13 % >> % run a reduced set of UTPs operating on the listed classes | |
14 % >> utp_run('classname1', 'classname2', ...); | |
15 % | |
16 % EXAMPLES: | |
17 % | |
18 % >> utp_run(); | |
19 % >> utp_run('utp_ao_ao'); | |
20 % >> utp_run('utp_ao_ao', 'utp_ao_abs'); | |
21 % >> utp_run('ao', 'tsdata', 'fsdata'); | |
22 % >> utp_run('ao', 'tsdata', 'fsdata', pl); | |
23 % | |
24 % pl keys | |
25 % 'tests' - cell array of strings above | |
26 % 'no repository' - true/false | |
27 % 'skip tests' - cell array of tests to skip | |
28 % 'skip classes' - cell array of classes to skip | |
29 % | |
30 % | |
31 % | |
32 % $Id: utp_run.m,v 1.20 2010/08/09 16:38:49 ingo Exp $ | |
33 | |
34 function varargout = utp_run(varargin) | |
35 | |
36 % save current path | |
37 oldpath = path(); | |
38 | |
39 [pl, dummy, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
40 | |
41 % Make sure that pl is a PLIST | |
42 pl = combine(plist(), pl); | |
43 | |
44 skipClasses = pl.find('skip classes', ''); | |
45 skipTests = pl.find('skip tests', ''); | |
46 tests = pl.find('tests', ''); | |
47 noRepository = pl.find('no repository', false); | |
48 | |
49 if ~isempty(rest) && ~isempty(tests) | |
50 tests = [reshape(cellstr(tests), 1, []), reshape(rest, 1, [])]; | |
51 elseif ~isempty(tests) | |
52 tests = cellstr(tests); | |
53 elseif ~isempty(rest) | |
54 tests = rest; | |
55 end | |
56 | |
57 try | |
58 % add support functions and UTPs folders to path | |
59 utppath = fileparts(which('utp_run')); | |
60 addpath(genpath(utppath)); | |
61 | |
62 % list of the classes for which we have UTPs | |
63 classes = {}; | |
64 | |
65 % cell array to hold UTP function names to run | |
66 utps = {}; | |
67 | |
68 % check for input arguments | |
69 if numel(tests) > 0 | |
70 | |
71 % check if input argument is a list of UTP function names | |
72 if all(strncmp(tests, 'utp_', 4)) | |
73 % add the given UTPs to the list of test functions to run | |
74 for kk = 1:numel(tests) | |
75 uname = tests{kk}; | |
76 % check if the given UTPs exist | |
77 if exist(uname, 'file') == 2 | |
78 utps = addUtpTest(utps, tests(kk)); | |
79 else | |
80 error('### test ''%s'' not found\n', uname); | |
81 end | |
82 end | |
83 else | |
84 % assume input argument is a list of classes | |
85 for kk = 1:numel(tests) | |
86 cname = tests{kk}; | |
87 % check if it exists | |
88 if exist(fullfile(utppath, 'utps', cname), 'dir') | |
89 classes = [classes {cname}]; | |
90 else | |
91 error('### test class ''%s'' not found\n', cname); | |
92 end | |
93 end | |
94 end | |
95 | |
96 else | |
97 | |
98 % list of all the classes we have UTPs for | |
99 d = dir(fullfile(utppath, 'utps')); | |
100 for kk = 1:numel(d) | |
101 if ~d(kk).isdir | |
102 continue; | |
103 end | |
104 if d(kk).name(1) == '.' | |
105 continue; | |
106 end | |
107 if strcmp(d(kk).name, 'CVS') | |
108 continue; | |
109 end | |
110 | |
111 % Skip classes | |
112 if utils.helper.ismember(d(kk).name, skipClasses) | |
113 continue; | |
114 end | |
115 classes = [classes {d(kk).name}]; | |
116 end | |
117 | |
118 end | |
119 | |
120 % add to the UPTs function name list the UTPs for each class in the list | |
121 for kk = 1:numel(classes) | |
122 mfiles = dir(fullfile(utppath, 'utps', classes{kk})); | |
123 % identify all UTP functions | |
124 for jj=1:length(mfiles) | |
125 [pathstr, name, ext] = fileparts(mfiles(jj).name); | |
126 if ~strcmp(ext, '.m') | |
127 continue; | |
128 end | |
129 try | |
130 utps = addUtpTest(utps, name); | |
131 end | |
132 end | |
133 end | |
134 | |
135 % number of collected UTPs to run | |
136 fprintf('%d UTPs to run\n', numel(utps)); | |
137 | |
138 % initialize timer to measure UTPs execution time | |
139 tic(); | |
140 | |
141 % call each UTP function and collect the results | |
142 results = []; | |
143 for jj=1:length(utps) | |
144 try | |
145 results = [results eval(utps{jj})]; | |
146 catch ex | |
147 % report the error failure in running the UTP | |
148 stack.name = 'xx'; | |
149 message = ['exception: ' ex.message]; | |
150 results = [results utp_prepare_result(false, false, stack, utps{jj}, message)]; | |
151 % show error on console | |
152 fprintf(2, ['\n' ex.getReport()]); | |
153 fprintf(1, '\n'); | |
154 end | |
155 end | |
156 | |
157 % set output | |
158 if nargout == 1 | |
159 varargout{1} = results; | |
160 else | |
161 display_utp_results(results) | |
162 end | |
163 | |
164 catch ex | |
165 % restore original path | |
166 path(oldpath); | |
167 rethrow(ex); | |
168 end | |
169 | |
170 % restore original path | |
171 path(oldpath); | |
172 | |
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
174 % | |
175 % FUNCTION: addUtpTest | |
176 % | |
177 % DESCRIPTION: Local method which adds an UTP to the UTP list if it pass | |
178 % all conditions. | |
179 % | |
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
181 function utpsLocal = addUtpTest(utpsLocal, utpIn) | |
182 | |
183 utpIn = cellstr(utpIn); | |
184 | |
185 % Check if the UTP name is a UTP | |
186 if feval(utpIn{1}, 'isutp') | |
187 | |
188 addUTP = true; | |
189 % Skip the UTPs if it needs a repository. | |
190 if noRepository && feval(utpIn{1}, 'needs repository') == 2 | |
191 addUTP = false; | |
192 end | |
193 % Skip the UTPs if it is in the skil list. | |
194 if utils.helper.ismember(utpIn{1}, skipTests) | |
195 addUTP = false; | |
196 end | |
197 | |
198 if addUTP | |
199 utpsLocal = [utpsLocal utpIn]; | |
200 end | |
201 | |
202 end | |
203 | |
204 end | |
205 | |
206 end | |
207 |