Mercurial > pub > Impl
comparison Lib/IMPL/Test/Plan.pm @ 83:74bae30eb25e
(no commit message)
author | wizard |
---|---|
date | Tue, 13 Apr 2010 20:27:56 +0400 |
parents | 16ada169ca75 |
children | 4267a2ac3d46 |
comparison
equal
deleted
inserted
replaced
82:3a4205e7b663 | 83:74bae30eb25e |
---|---|
71 # handle loading errors | 71 # handle loading errors |
72 $Unit = new IMPL::Test::BadUnit($Unit,"Failed to load unit",$@) if $@; | 72 $Unit = new IMPL::Test::BadUnit($Unit,"Failed to load unit",$@) if $@; |
73 | 73 |
74 $info{Unit} = $Unit; | 74 $info{Unit} = $Unit; |
75 try { | 75 try { |
76 $info{Tests} = [map $Unit->new($_), $Unit->List]; | 76 $info{Tests} = [$Unit->List]; |
77 } otherwise { | 77 } otherwise { |
78 $info{Tests} = [$info{Unit} = new IMPL::Test::BadUnit($Unit->can('UnitName') ? $Unit->UnitName : $Unit,"Failed to extract tests",$@)]; | 78 my $err = $@; |
79 $Unit = $info{Unit} = new IMPL::Test::BadUnit( | |
80 $Unit->can('UnitName') ? | |
81 $Unit->UnitName : | |
82 $Unit, | |
83 "Failed to extract tests", | |
84 $err | |
85 ); | |
86 $info{Tests} = [$Unit->List]; | |
79 }; | 87 }; |
80 $count += @{$info{Tests}}; | 88 $count += @{$info{Tests}}; |
81 push @cache, \%info if @{$info{Tests}}; | 89 push @cache, \%info if @{$info{Tests}}; |
82 } | 90 } |
83 | 91 |
105 my $data; | 113 my $data; |
106 undef $@; | 114 undef $@; |
107 eval { | 115 eval { |
108 $data = $info->{Unit}->StartUnit; | 116 $data = $info->{Unit}->StartUnit; |
109 }; | 117 }; |
110 | 118 |
111 my @results; | 119 my @results; |
112 | 120 |
113 if (not $@) { | 121 if (not $@) { |
122 | |
114 foreach my $test (@{$info->{Tests}}) { | 123 foreach my $test (@{$info->{Tests}}) { |
124 my $name = $test->Name; | |
125 | |
126 #protected creation of the test | |
127 $test = eval { $info->{Unit}->new($test); } || new IMPL::Test::BadUnit( | |
128 $info->{Unit}->can('UnitName') ? | |
129 $info->{Unit}->UnitName : | |
130 $info->{Unit}, | |
131 "Failed to construct the test $name", | |
132 $@ | |
133 ); | |
134 | |
135 # invoke the test | |
115 $this->_Tell(RunTest => $test); | 136 $this->_Tell(RunTest => $test); |
116 my $result = $test->Run($data); | 137 my $result = $test->Run($data); |
117 $this->_Tell(EndTest => $test,$result); | 138 $this->_Tell(EndTest => $test,$result); |
139 | |
118 push @results,$result; | 140 push @results,$result; |
119 } | 141 } |
120 } else { | 142 } else { |
121 my $e = $@; | 143 my $e = $@; |
144 my $badTest = new IMPL::Test::BadUnit( | |
145 $info->{Unit}->can('UnitName') ? | |
146 $info->{Unit}->UnitName : | |
147 $info->{Unit}, | |
148 "Failed to initialize the unit", | |
149 $@ | |
150 ); | |
122 foreach my $test (@{$info->{Tests}}) { | 151 foreach my $test (@{$info->{Tests}}) { |
123 $this->_Tell(RunTest => $test); | 152 |
153 $this->_Tell(RunTest => $badTest); | |
124 my $result = new IMPL::Test::Result( | 154 my $result = new IMPL::Test::Result( |
125 Name => $test->Name, | 155 Name => $test->Name, |
126 State => IMPL::Test::Result::FAIL, | 156 State => IMPL::Test::Result::FAIL, |
127 Exception => $e | 157 Exception => $e |
128 ); | 158 ); |
129 $this->_Tell(EndTest => $test,$result); | 159 $this->_Tell(EndTest => $badTest,$result); |
130 push @results,$result; | 160 push @results,$result; |
131 } | 161 } |
132 } | 162 } |
133 | 163 |
134 eval { | 164 eval { |