Changeset 2155

Show
Ignore:
Timestamp:
04/29/08 23:17:00 (7 months ago)
Author:
mpaschal
Message:

Rewrite is_object() and are_objects() testers to count as single tests instead of agglomerations of several tests each

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-36/t/driver-tests.pl

    r2154 r2155  
    3030} 
    3131 
    32 use constant TESTS => 261
     32use constant TESTS => 187
    3333 
    3434use Test::More; 
     
    9191    my ($got, $expected, $name) = @_; 
    9292 
    93     isa_ok($got, ref $expected, $name); 
    94     isnt($got, $expected, "$name is not the same instance as the expected object"); 
     93    if (!defined $got) { 
     94        fail($name); 
     95        diag('    got undef, not an object'); 
     96        return; 
     97    } 
     98 
     99    if (!$got->isa(ref $expected)) { 
     100        fail($name); 
     101        diag('    got a ', ref($got), ' but expected a ', ref $expected); 
     102        return; 
     103    } 
     104 
     105    if ($got == $expected) { 
     106        fail($name); 
     107        diag('    got the exact same instance as expected, when really expected a different but equivalent object'); 
     108        return; 
     109    } 
    95110 
    96111    # Ignore object columns that have undefined values. 
     
    103118    } 
    104119 
    105     is_deeply(\%got_values, \%expected_values, "$name is equivalent to the expected object"); 
    106 } 
    107  
    108 is_object(scalar Foo->load(1), $foo[0], 'Foo #1 by id'); 
    109 is_object(scalar Foo->load({ id => 1 }), $foo[0], 'Foo #1 by id hash'); 
    110 is_object(scalar Foo->load({ id => 1, name => 'foo' }), $foo[0], 'Foo #1 by id-name hash'); 
    111 is_object(scalar Foo->load({ name => 'foo' }), $foo[0], 'Foo #1 by name hash'); 
    112 is_object(scalar Foo->load({ created_on => $foo[0]->created_on }), $foo[0], 'Foo #1 by created_on hash'); 
    113 is_object(scalar Foo->load({ status => 2 }), $foo[0], 'Foo #1 by status hash'); 
     120    is_deeply(\%got_values, \%expected_values, $name); 
     121} 
     122 
     123is_object(scalar Foo->load(1), $foo[0], 'Foo #1 by id is Foo #1'); 
     124is_object(scalar Foo->load({ id => 1 }), $foo[0], 'Foo #1 by id hash is Foo #1'); 
     125is_object(scalar Foo->load({ id => 1, name => 'foo' }), $foo[0], 'Foo #1 by id-name hash is Foo #1'); 
     126is_object(scalar Foo->load({ name => 'foo' }), $foo[0], 'Foo #1 by name hash is Foo #1'); 
     127is_object(scalar Foo->load({ created_on => $foo[0]->created_on }), $foo[0], 'Foo #1 by created_on hash is Foo #1'); 
     128is_object(scalar Foo->load({ status => 2 }), $foo[0], 'Foo #1 by status hash is Foo #1'); 
    114129 
    115130##     Change column value, save, try to load using old value (fail?), 
     
    120135ok(!$tmp, 'Foo #1 no longer loads with old status (2)'); 
    121136$tmp = Foo->load({ status => 0 }); 
    122 is_object($tmp, $foo[0], 'Foo #1 by new status (0)'); 
     137is_object($tmp, $foo[0], 'Foo #1 by new status (0) is Foo #1'); 
    123138 
    124139## Create a new object so we can do range and last/first lookups. 
     
    139154isa_ok($iter, 'CODE', "Iterator for all Foos"); 
    140155ok($tmp = $iter->(), 'Iterator for our two Foos had one object'); 
    141 is_object($tmp, $foo[0], "All Foo iterator's first Foo"); 
     156is_object($tmp, $foo[0], "All Foo iterator's first Foo is Foo #1"); 
    142157ok($tmp = $iter->(), 'Iterator for our two Foos had two objects'); 
    143 is_object($tmp, $foo[1], "All Foo iterator's second Foo"); 
     158is_object($tmp, $foo[1], "All Foo iterator's second Foo is Foo #2"); 
    144159ok(!$iter->(), 'Iterator for our two Foos did not have a third object'); 
    145160 
     
    148163isa_ok($iter, 'CODE', "Iterator for status=1 Foos"); 
    149164ok($tmp = $iter->(), 'Iterator for our status=1 Foos had one object'); 
    150 is_object($tmp, $foo[1], "Status=1 Foo iterator's first Foo"); 
     165is_object($tmp, $foo[1], "Status=1 Foo iterator's first Foo is Foo #2"); 
    151166ok(!$iter->(), "Iterator for our status=1 Foos did not have a second object"); 
    152167 
     
    160175    direction => 'descend', 
    161176    limit => 1 }); 
    162 is_object($tmp, $foo[1], 'Newest Foo'); 
     177is_object($tmp, $foo[1], 'Newest Foo is Foo #2'); 
    163178 
    164179## Load using ascending sort (oldest) 
     
    167182    direction => 'ascend', 
    168183    limit => 1 }); 
    169 is_object($tmp, $foo[0], 'Oldest Foo'); 
     184is_object($tmp, $foo[0], 'Oldest Foo is Foo #1'); 
    170185 
    171186sub are_objects { 
     
    173188 
    174189    my $count = scalar @$expected; 
    175     is(scalar @$got, $count, "$name got $count objects"); 
    176     is_object($$got[$_], $$expected[$_], "$name #$_") for (0..$count-1); 
     190    if ($count != scalar @$got) { 
     191        fail($name); 
     192        diag('    got ', scalar(@$got), ' objects but expected ', $count); 
     193        return; 
     194    } 
     195 
     196    is_object($$got[$_], $$expected[$_], "$name (#$_)") for (0..$count-1); 
    177197} 
    178198 
     
    182202    direction => 'descend', 
    183203    limit => 2 }); 
    184 are_objects(\@tmp, [ reverse @foo ], 'Two Foos newest-first load()'); 
     204are_objects(\@tmp, [ reverse @foo ], 'Two Foos newest-first load() finds Foos #2 and #1'); 
    185205 
    186206## Load using descending sort by created_on, no limit 
     
    188208    sort => 'created_on', 
    189209    direction => 'descend' }); 
    190 are_objects(\@tmp, [ reverse @foo ], 'All Foos newest-first load()'); 
     210are_objects(\@tmp, [ reverse @foo ], 'All Foos newest-first load() finds Foos #2 and #1'); 
    191211 
    192212## Load using ascending sort by status, no limit 
    193213@tmp = Foo->load(undef, { sort => 'status', }); 
    194 are_objects(\@tmp, \@foo, 'All Foos lowest-status-first load()'); 
     214are_objects(\@tmp, \@foo, 'All Foos lowest-status-first load() finds Foos #1 and #2'); 
    195215 
    196216## Load using 'last' where status == 0 
     
    199219    direction => 'descend', 
    200220    limit => 1 }); 
    201 is_object($tmp, $foo[0], 'Newest status=0 Foo'); 
     221is_object($tmp, $foo[0], 'Newest status=0 Foo is Foo #1'); 
    202222 
    203223## Load using range search, one less than foo[1]->created_on and newer 
     
    205225    { created_on => [ $foo[1]->column('created_on')-1 ] }, 
    206226    { range => { created_on => 1 } }); 
    207 is_object($tmp, $foo[1], 'Foo from open-ended date range before Foo #2'); 
     227is_object($tmp, $foo[1], 'Foo from open-ended date range before Foo #2 is Foo #2'); 
    208228 
    209229## Load using EXCLUSIVE range search, up through the momment $foo[1] created 
     
    226246    { range_incl => { created_on => 1 } }); 
    227247ok($tmp, 'Loaded an object based on range_incl (ts-1 to ts)'); 
    228 is_object($tmp, $foo[1], "Foo from inclusive date-range load() ending at Foo #1's date"); 
     248is_object($tmp, $foo[1], "Foo from inclusive date-range load() ending at Foo #1's date is Foo #2"); 
    229249 
    230250$tmp = Foo->load( 
     
    233253    { range_incl => { created_on => 1 } }); 
    234254ok($tmp, 'Loaded an object based on range_incl (ts to ts+1)'); 
    235 is_object($tmp, $foo[1], "Foo from inclusive date-range load() starting at Foo #1's date"); 
     255is_object($tmp, $foo[1], "Foo from inclusive date-range load() starting at Foo #1's date is Foo #2"); 
    236256 
    237257## Check that range searches return nothing when nothing is in the range. 
     
    244264    { created_on => [ undef, $foo[1]->column('created_on')-1 ] }, 
    245265    { range => { created_on => 1 } }); 
    246 is_object($tmp, $foo[0], "Foo from exclusive open-started date-range load() ending before Foo #1"); 
     266is_object($tmp, $foo[0], "Foo from exclusive open-started date-range load() ending before Foo #1 is Foo #1"); 
    247267 
    248268## Get count of objects 
     
    267287    direction => 'ascend', 
    268288    start_val => $foo[0]->created_on }); 
    269 is_object($tmp, $foo[1], 'Next newer Foo after Foo #1'); 
     289is_object($tmp, $foo[1], 'Next newer Foo after Foo #1 is Foo #2'); 
    270290 
    271291## Given the first Foo object, try to load the "previous" one 
     
    285305    direction => 'descend', 
    286306    start_val => $foo[1]->created_on }); 
    287 is_object($tmp, $foo[0], 'Next older Foo before Foo #2'); 
     307is_object($tmp, $foo[0], 'Next older Foo before Foo #2 is Foo #1'); 
    288308 
    289309## Given the second Foo object, try to load the "next" one 
     
    303323    direction => 'descend', 
    304324    start_val => $foo[1]->created_on-1 }); 
    305 is_object($tmp, $foo[0], 'Next older Foo before just before Foo #2'); 
     325is_object($tmp, $foo[0], 'Next older Foo before just before Foo #2 is Foo #1'); 
    306326 
    307327## Now, given the second Foo object's created_on - 1, try to 
     
    312332    direction => 'ascend', 
    313333    start_val => $foo[1]->created_on-1 }); 
    314 is_object($tmp, $foo[1], 'Next newer Foo after just before Foo #2'); 
     334is_object($tmp, $foo[1], 'Next newer Foo after just before Foo #2 is Foo #2'); 
    315335 
    316336## Override created_on timestamp, make sure it works 
     
    323343    direction => 'descend', 
    324344    limit => 2 }); 
    325 are_objects(\@tmp, \@foo, 'Time-traveled Foos newest-first'); 
     345are_objects(\@tmp, \@foo, 'Time-traveled Foos newest-first are Foos #1 and #2'); 
    326346 
    327347## Test limit of 2 with direction descend, but without 
     
    331351    direction => 'descend', 
    332352    limit => 2 }); 
    333 are_objects(\@tmp, [ reverse @foo ], 'Foos highest-id-first'); 
     353are_objects(\@tmp, [ reverse @foo ], 'Foos highest-id-first are Foos #2 and #1'); 
    334354 
    335355## Test loading using offset. 
     
    340360    limit => 1, 
    341361    offset => 1 }); 
    342 is_object($tmp, $foo[1], 'Second newest Foo'); 
     362is_object($tmp, $foo[1], 'Second newest Foo is Foo #2'); 
    343363 
    344364## We only have 2 Foo objects, so this should load 
     
    349369    limit => 2, 
    350370    offset => 1 }); 
    351 are_objects(\@tmp, [ $foo[1] ], 'Second and third newest Foos'); 
     371are_objects(\@tmp, [ $foo[1] ], 'Second and third newest Foos is just Foo #2'); 
    352372 
    353373## Should load the first Foo object (ascend with offset of 1). 
     
    357377    limit => 1, 
    358378    offset => 1 }); 
    359 is_object($tmp, $foo[0], 'Second oldest Foo'); 
     379is_object($tmp, $foo[0], 'Second oldest Foo is Foo #1'); 
    360380 
    361381## Now test join loads.