changeset 31:d59526f6310e

Small fixes to Test framework (correct handlinf of the compilation errors in the test units) Imported and refactored SQL DB schema from the old project
author Sergey
date Mon, 09 Nov 2009 01:39:16 +0300
parents dd4d72600c69
children 56cef8e3cda6
files Lib/IMPL/ORM/Object.pm Lib/IMPL/ORM/Schema.pm Lib/IMPL/Test/BadUnit.pm Lib/IMPL/Test/Plan.pm _test/Test/ORM/Schema.pm
diffstat 5 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Object.pm	Tue Nov 03 16:31:47 2009 +0300
+++ b/Lib/IMPL/ORM/Object.pm	Mon Nov 09 01:39:16 2009 +0300
@@ -78,7 +78,7 @@
             $schema->appendChild( new IMPL::ORM::Schema::Relation::HasOne($ormProp->Name,$entity->entityName));
         } else {
             # хз что. Скорее всего не удалось квалифицировать тип свойства не как ссылочный и как поле.
-            die new IMPL::Exception('Uexpected error due building schema for a class', $ormProp->Class, $ormProp->Name);
+            die new IMPL::Exception('Uexpected error due building schema for a class', $ormProp->Class, $ormProp->Name,$ormProp->Type);
         }
     }
     
--- a/Lib/IMPL/ORM/Schema.pm	Tue Nov 03 16:31:47 2009 +0300
+++ b/Lib/IMPL/ORM/Schema.pm	Mon Nov 09 01:39:16 2009 +0300
@@ -14,7 +14,7 @@
     public property mapValueTypes => prop_get | owner_set;
     public property mapReferenceTypes => prop_get | owner_set;
     public property mapPending => prop_get | owner_set;
-    public property prefix => prop_all; 
+    public property prefix => prop_get | owner_set; 
 }
 
 sub CTOR {
@@ -91,9 +91,20 @@
 sub usePrefix {
     my ($this,$prefix) = @_;
     
+    $prefix .= '::' if $prefix and $prefix !~ /::$/;
+    
     (ref $this ? $this : $this->instance)->prefix($prefix);
 }
 
+sub CompleteSchema {
+    my ($this) = @_;
+    
+    $this = ref $this ? $this : $this->instance;
+    
+    $this->mapReferenceTypes->{$_} = $_->ormGetSchema($this,delete $this->mapPending->{$_})
+        foreach (keys %{$this->mapPending});
+}
+
 1;
 
 __END__
--- a/Lib/IMPL/Test/BadUnit.pm	Tue Nov 03 16:31:47 2009 +0300
+++ b/Lib/IMPL/Test/BadUnit.pm	Mon Nov 09 01:39:16 2009 +0300
@@ -13,12 +13,18 @@
 
 our %CTOR = (
     'IMPL::Test::Unit' => sub {
-        my ($unit,$message,$error) = @_;
-        return new IMPL::Test::Unit::TestInfo(
-            BadUnitTest => sub {
-                die new IMPL::Test::FailException($message,$unit,eval {$error->isa('IMPL::Exception')} ? $error->toString(1) : $error)
-            }
-        );
+        if (@_>1) {
+            # Unit construction
+            my ($unit,$message,$error) = @_;
+            return new IMPL::Test::Unit::TestInfo(
+                BadUnitTest => sub {
+                    die new IMPL::Test::FailException($message,$unit,eval {$error->isa('IMPL::Exception')} ? $error->toString(1) : $error)
+                }
+            );
+        } else {
+            # test construction
+            return @_;
+        }
     }
 );
 
@@ -45,5 +51,15 @@
     $inst->callCTOR(@args{qw(UnitName Message)});
 }
 
+sub List {
+    my ($this) = @_;
+    my $error = $this->Error;
+    return new IMPL::Test::Unit::TestInfo(
+        BadUnitTest => sub {
+            die new IMPL::Test::FailException($this->Message,$this->UnitName,eval {$error->isa('IMPL::Exception')} ? $error->toString(1) : $error)
+        }
+    );
+}
+
 
 1;
--- a/Lib/IMPL/Test/Plan.pm	Tue Nov 03 16:31:47 2009 +0300
+++ b/Lib/IMPL/Test/Plan.pm	Mon Nov 09 01:39:16 2009 +0300
@@ -64,8 +64,13 @@
         my %info;
         
         # preload module
+        undef $@;
+        
         eval "require $Unit" unless (ref $Unit);
         
+        # handle loading errors
+        $Unit = new IMPL::Test::BadUnit($Unit,"Failed to load unit",$@) if $@;
+        
         $info{Unit} = $Unit;
         try {
             $info{Tests} = [map $Unit->new($_), $Unit->List];
--- a/_test/Test/ORM/Schema.pm	Tue Nov 03 16:31:47 2009 +0300
+++ b/_test/Test/ORM/Schema.pm	Mon Nov 09 01:39:16 2009 +0300
@@ -51,8 +51,8 @@
 BEGIN {
     public property Id => prop_get, { type => 'String' }; # Field
     public property User => prop_get, { type => 'Test::ORM::Schema::Data::User' }; # HasOne
-    public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne
-    public property AccessTime => prop_get { type => 'DateTime' }; # Field
+    #public property Data => prop_all, { type => Map( 'String','String' ) }; # HasOne
+    public property AccessTime => prop_get, { type => 'DateTime' }; # Field
 }
 
 package Test::ORM::Schema::Data;
@@ -73,4 +73,6 @@
     Session
 );
 
+__PACKAGE__->CompleteSchema;
+
 1;