[Pdx-pm] Test::Builder calling convention

Eric Wilhelm enobacon at gmail.com
Fri Mar 13 13:41:44 PDT 2009

# from Hans Dieter Pearcey
# on Friday 13 March 2009 12:08:

>Trouble is, I can't remember what it bought us over a regular or
>>     $builder->ok( open my $fh, $file )
>>             ->diag( "Errno: $!" )
>>       or
>>     $builder->is( $!, ENOBACON )
>>             ->name( "Insufficient bacon" );
>> That would appear to be perfectly sufficient, understandable to all
>> and you get real short circuiting, not calling empty methods on an
>> empty object.

But 'or' does not have sufficient precedence here (you are trying to 
return the result object?)

>It seems weird to me that diag() in your second example is returning
> whether or not the test passed.

Actually, I question diag() being applied directly to a result object 
(e.g. $builder->ok(1)->diag("fail!")) -- Does the diag() merely 
passthrough when called on a true result object?

But, should this example actually be like so?  That is, we want open() 
to fail because the goal is to verify the errno.

  return $builder->ok( ! open my $fh, $file )
          ->or->diag( "Expected open to fail" )
          ->is( $!,  ENOBACON )
          ->name( "Insufficient bacon" );

Or to put it another way:

  my $res = $builder->ok( ! open my $fh, $file );
  $res->name( "Insufficient bacon" );
  return $res->diag( "Expected open to fail" ) unless($res);

  return $res->is( $!, ENOBACON );

hmm... $builder->ko( open my $fh, $file );  Groan, not this again!  
Maybe we need an example with not so much negation here.

Chicken farmer's observation:  Clunk is the past tense of cluck.

More information about the Pdx-pm-list mailing list