File: empty_result.t

package info (click to toggle)
libobject-result-perl 0.000003-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 216 kB
  • sloc: perl: 224; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,321 bytes parent folder | download
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
use 5.014;
use Test::More;
use Object::Result;
use Carp;

sub is_ex (&$$$) {
    my ($block, $expected_err, $line, $desc) = @_;

    my $file = (caller 0)[1];

    is eval{ $block->(); }, undef()  => "$desc (threw exception)";
    like $@, qr{\Q$expected_err\E}   => "$desc (right error message)";
    like $@, qr{at $file line $line} => "$desc (right error location)";
}

sub code { return 'subroutine' }

sub get_result {
    result { };
}

my $CALL_LOC = __FILE__.' line '.__LINE__; my $result = get_result();

ok !$result => 'Boolean coercion';

my $error_msg = "Call to main::get_result() at $CALL_LOC failed\n"
              . "Failure detected";

is_ex { $result + 1   } $error_msg => __LINE__, 'No <NUM>';
is_ex { int($result)  } $error_msg => __LINE__, 'No <INT>';
is_ex { "$result"     } $error_msg => __LINE__, 'No <STR>';
is_ex { ${$result}    } $error_msg => __LINE__, 'No <SCALAR>';
is_ex { \@{$result}   } $error_msg => __LINE__, 'No <ARRAY>';
is_ex { \%{$result}   } $error_msg => __LINE__, 'No <HASH>';
is_ex { $result->()   } $error_msg => __LINE__, 'No <CODE>';
is_ex { "" =~ $result } $error_msg => __LINE__, 'No <REGEXP>';
is_ex { *{$result}    } $error_msg => __LINE__, 'No <GLOB>';

is_ex { $result->no_such_method(); 1 } $error_msg => __LINE__, 'Non-existent method called';

done_testing();