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