some more progress. All the initialization routines run and I can get some of the...
[kakapo:kakapo.git] / src / UnitTest / Suite.nqp
1 # Copyright (C) 2010, Austin Hastings. See accompanying LICENSE file, or
2 # http://www.opensource.org/licenses/artistic-license-2.0.php for license.
3
4 class UnitTest::Suite;
5
6 has     @!members;
7 has     $!num_tests;
8
9 method add_test($test) {
10         @!members.push($test);
11         $!num_tests := $!num_tests + $test.num_tests;
12         self;
13 }
14
15 method add_tests(*@tests) {
16         for @tests {
17                 self.add_test($_);
18         }
19
20         self;
21 }
22
23 my method default_result() {
24         my $result := UnitTest::Result.new();
25         $result.add_listener(UnitTest::Listener::TAP.new);
26         $result;
27 }
28
29 method run($result?) {
30         unless $result.defined {
31                 $result := self.default_result;
32         }
33
34         $result.plan_tests(self.num_tests);
35
36         for self.members {
37                 unless $result.should_stop {
38                         $_.run($result);
39                 }
40         }
41
42         $result;
43 }
44
45 sub sort_cmp($a, $b) {
46         $a.name lt $b.name ?? -1 !! 1;
47 }
48
49 method sort() {
50         self.members.sort(UnitTest::Suite::sort_cmp);
51         self;
52 }
53
54 method suite() {
55         self;
56 }