diff 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
line wrap: on
line diff
--- a/Lib/IMPL/Test/Plan.pm	Thu Apr 08 13:15:31 2010 +0400
+++ b/Lib/IMPL/Test/Plan.pm	Tue Apr 13 20:27:56 2010 +0400
@@ -73,9 +73,17 @@
         
         $info{Unit} = $Unit;
         try {
-            $info{Tests} = [map $Unit->new($_), $Unit->List];
+            $info{Tests} = [$Unit->List];
         } otherwise {
-            $info{Tests} = [$info{Unit} = new IMPL::Test::BadUnit($Unit->can('UnitName') ? $Unit->UnitName : $Unit,"Failed to extract tests",$@)];
+        	my $err = $@; 
+        	$Unit = $info{Unit} = new IMPL::Test::BadUnit(
+        		$Unit->can('UnitName') ?
+        			$Unit->UnitName :
+        			$Unit,
+        		"Failed to extract tests",
+        		$err
+        	);
+            $info{Tests} = [$Unit->List];
         };
         $count += @{$info{Tests}};
         push @cache, \%info if @{$info{Tests}};
@@ -107,26 +115,48 @@
         eval {
             $data = $info->{Unit}->StartUnit;
         };
-        
+                
         my @results;
         
         if (not $@) {
+        	
             foreach my $test (@{$info->{Tests}}) {
+            	my $name = $test->Name;
+            	
+            	#protected creation of the test
+            	$test = eval { $info->{Unit}->new($test); } || new IMPL::Test::BadUnit(
+	        		$info->{Unit}->can('UnitName') ?
+	        			$info->{Unit}->UnitName :
+	        			$info->{Unit},
+	        		"Failed to construct the test $name",
+	        		$@
+	        	);
+	        	
+	        	# invoke the test
                 $this->_Tell(RunTest => $test);
                 my $result = $test->Run($data);
                 $this->_Tell(EndTest => $test,$result);
+                
                 push @results,$result;
             }
         } else {
             my $e = $@;
+			my $badTest = new IMPL::Test::BadUnit(
+        		$info->{Unit}->can('UnitName') ?
+        			$info->{Unit}->UnitName :
+        			$info->{Unit},
+        		"Failed to initialize the unit",
+        		$@
+        	); 
             foreach my $test (@{$info->{Tests}}) {
-                $this->_Tell(RunTest => $test);
+            	
+                $this->_Tell(RunTest => $badTest);
                 my $result = new IMPL::Test::Result(
                     Name => $test->Name,
                     State => IMPL::Test::Result::FAIL,
                     Exception => $e
                 );
-                $this->_Tell(EndTest => $test,$result);
+                $this->_Tell(EndTest => $badTest,$result);
                 push @results,$result;
             }
         }