annotate TestRunner.m @ 0:33654ef5c7ea

Import
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 27 Dec 2011 19:50:44 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
1 classdef TestRunner < handle
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
3 properties
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
4
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 testcases = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7 end % properties
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 methods
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11 function self = TestRunner(testcases)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12 self.testcases = testcases;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
15 function results = run(self)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 failures = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
18
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 for kk = 1:numel(self.testcases)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
21 % instance
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22 t = feval(self.testcases{kk});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
23
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 % setup class
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
25 t.setUpClass();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 cleanclass = onCleanup(@()t.tearDownClass());
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28 for m = t.listTests()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
30 try
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
31 % setup test
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
32 t.setUp()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
33 clean = onCleanup(@()t.tearDown());
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
34 catch ex
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
35 % something went wrong in test setup code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
36 fprintf('E');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
37 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
38
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
39 try
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 % run test
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
41 feval(m{1}, t);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
42 fprintf('.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
43 catch ex
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 % test failure
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
45 fprintf('F');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
46 failures = [ failures { {self.testcases{kk} m{1} ex } }];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
47 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
48 % explicitly call cleanup handler
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49 clear clean;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51 % explicitly call class cleanup handler
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
52 clear cleanclass;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
53 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
54 fprintf('\n');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
55
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
56 self.reportFailures(failures)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
57
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
58 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
59
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 function reportFailures(self, failures)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
61 for kk = 1:numel(failures)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
62 f = failures{kk};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
63 fprintf(2, '%s: %s: %s\n%s', which(f{1}), f{1}, f{2}, f{3}.getReport());
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
65 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
66
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
67 end % methods
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
68
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
69 end