1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#!/usr/bin/perl
# This test validates which usages of return_value are allowed when setting the
# return value, and which are not.
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use Test::More tests => 5;
use Test::NoWarnings;
use Aspect;
my $CALLED = 0;
SCOPE: {
package Foo;
sub foo {
$CALLED++;
return 2;
}
sub bar {
$CALLED++;
return 3;
}
sub baz {
$CALLED++;
return 4;
}
1;
}
# Set the return value and don't run the function
before {
$_->return_value(10);
return;
} call 'Foo::foo';
is( Foo::foo(), 10, 'Foo::foo() returns hijacked return value' );
is( $CALLED, 0, 'Original function was not called' );
# Set the return value in an explicit return
before {
return $_->return_value(20);
} call 'Foo::bar';
is( Foo::bar(), 20, 'Foo::bar() returns hijacked return value' );
is( $CALLED, 0, 'Original function was not called' );
|