File: runtests_die_empty.t

package info (click to toggle)
libtest-class-perl 0.52-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 540 kB
  • sloc: perl: 1,706; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 915 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/perl -T

use strict;
use warnings;

package Object;
use overload
    bool => sub { 1 },  # there is an exception here even if it stringifies as empty!
    '""' => 'as_string',
    fallback => 1;
sub new {
    my ($class, %args) = @_;
    bless { %args }, $class;
}
sub as_string {
    return defined $_[0]->{message}
        ? $_[0]->{message}
        : '';
}

package Foo;
use Test::More;
use base qw(Test::Class);

sub die_empty : Test(1) {
        die Object->new();
        fail 'we should never get here';
}

package main;
use Test::Builder::Tester tests => 1;
$ENV{TEST_VERBOSE}=0;

my $filename = sub { return (caller)[1] }->();

test_out( "not ok 1 - die_empty died ()");
test_err( "#   Failed test 'die_empty died ()'" );
test_err( "#   at $filename line 40.");
test_err( "#   (in Foo->die_empty)" );
Foo->runtests;
test_test("we can handle an exception that stringifies to the empty string");