xref: /openbsd/gnu/usr.bin/perl/cpan/autodie/t/Fatal.t (revision 6fb12b70)
1b39c5158Smillert#!/usr/bin/perl -w
2b39c5158Smillertuse strict;
3b39c5158Smillert
4b39c5158Smillertuse constant NO_SUCH_FILE => "this_file_or_dir_had_better_not_exist_XYZZY";
5b39c5158Smillert
6b39c5158Smillertuse Test::More tests => 17;
7b39c5158Smillert
8*6fb12b70Safresh1use Fatal qw(:io :void opendir);
9b39c5158Smillert
10b39c5158Smillerteval { open FOO, "<".NO_SUCH_FILE };	# Two arg open
11b39c5158Smillertlike($@, qr/^Can't open/, q{Package Fatal::open});
12b39c5158Smillertis(ref $@, "", "Regular fatal throws a string");
13b39c5158Smillert
14b39c5158Smillertmy $foo = 'FOO';
15b39c5158Smillertfor ('$foo', "'$foo'", "*$foo", "\\*$foo") {
16b39c5158Smillert    eval qq{ open $_, '<$0' };
17b39c5158Smillert
18b39c5158Smillert    is($@,"", "Open using filehandle named - $_");
19b39c5158Smillert
20b39c5158Smillert    like(scalar(<$foo>), qr{^#!.*/perl}, "File contents using - $_");
21b39c5158Smillert    eval qq{ close FOO };
22b39c5158Smillert
23b39c5158Smillert    is($@,"", "Close filehandle using - $_");
24b39c5158Smillert}
25b39c5158Smillert
26b39c5158Smillerteval { opendir FOO, NO_SUCH_FILE };
27b39c5158Smillertlike($@, qr{^Can't open}, "Package :void Fatal::opendir");
28b39c5158Smillert
29b39c5158Smillerteval { my $a = opendir FOO, NO_SUCH_FILE };
30b39c5158Smillertis($@, "", "Package :void Fatal::opendir in scalar context");
31b39c5158Smillert
32b39c5158Smillerteval { Fatal->import(qw(print)) };
33b39c5158Smillertlike(
34b39c5158Smillert	$@, qr{Cannot make the non-overridable builtin print fatal},
35b39c5158Smillert	"Can't override print"
36b39c5158Smillert);
37