File: 003_must_not_be_scalar.t

package info (click to toggle)
libcall-context-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 100 kB
  • sloc: perl: 34; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 619 bytes parent folder | download | duplicates (2)
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
package t::Call::Context::must_not_be_scalar;

use strict;
use warnings;

use Test::More;
plan tests => 6;

my $PKG = __PACKAGE__;

use Call::Context;

sub foo {
    Call::Context::must_not_be_scalar();
    1;
}

sub try {
    return foo();
}

scalar eval { try() };

isa_ok( $@, 'Call::Context::X' );
like( "$@", qr<\Q${PKG}::foo>, 'called function is in message' );
like( "$@", qr<\Q${PKG}::try>, 'calling function is in message' );
like( "$@", qr<scalar>, 'context is in message' );

eval { try() };

is( $@, q<>, 'no die() if in void context' );

() = eval { try() };

is( $@, q<>, 'no die() if in list context' );