1use strict; 2use warnings; 3 4use Config qw/%Config/; 5 6use Test2::Tools::Tiny; 7use Test2::Util qw/ 8 try 9 10 get_tid USE_THREADS 11 12 pkg_to_file 13 14 CAN_FORK 15 CAN_THREAD 16 CAN_REALLY_FORK 17 18 CAN_SIGSYS 19 20 IS_WIN32 21 22 clone_io 23/; 24 25BEGIN { 26 if ($] lt "5.008") { 27 require Test::Builder::IO::Scalar; 28 } 29} 30 31{ 32 for my $try (\&try, Test2::Util->can('_manual_try'), Test2::Util->can('_local_try')) { 33 my ($ok, $err) = $try->(sub { die "xxx" }); 34 ok(!$ok, "cought exception"); 35 like($err, qr/xxx/, "expected exception"); 36 37 ($ok, $err) = $try->(sub { 0 }); 38 ok($ok, "Success"); 39 ok(!$err, "no error"); 40 } 41} 42 43is(pkg_to_file('A::Package::Name'), 'A/Package/Name.pm', "Converted package to file"); 44 45# Make sure running them does not die 46# We cannot really do much to test these. 47CAN_THREAD(); 48CAN_FORK(); 49CAN_REALLY_FORK(); 50IS_WIN32(); 51 52is(IS_WIN32(), ($^O eq 'MSWin32') ? 1 : 0, "IS_WIN32 is correct ($^O)"); 53 54my %sigs = map {$_ => 1} split /\s+/, $Config{sig_name}; 55if ($sigs{SYS}) { 56 ok(CAN_SIGSYS, "System has SIGSYS"); 57} 58else { 59 ok(!CAN_SIGSYS, "System lacks SIGSYS"); 60} 61 62my $check_for_sig_sys = Test2::Util->can('_check_for_sig_sys'); 63ok($check_for_sig_sys->("FOO SYS BAR"), "Found SIGSYS in the middle"); 64ok($check_for_sig_sys->("SYS FOO BAR"), "Found SIGSYS at start"); 65ok($check_for_sig_sys->("FOO BAR SYS"), "Found SIGSYS at end"); 66ok(!$check_for_sig_sys->("FOO SYSX BAR"), "SYSX is not SYS"); 67ok(!$check_for_sig_sys->("FOO XSYS BAR"), "XSYS is not SYS"); 68 69my $io = clone_io(\*STDOUT); 70ok($io, "Cloned the filehandle"); 71close($io); 72 73my $fh; 74my $out = ''; 75if ($] ge "5.008") { 76 open($fh, '>', \$out) or die "Could not open filehandle"; 77} else { 78 $fh = Test::Builder::IO::Scalar->new(\$out) or die "Could not open filehandle"; 79} 80 81$io = clone_io($fh); 82is($io, $fh, "For a scalar handle we simply return the original handle, no other choice"); 83print $io "Test\n"; 84 85is($out, "Test\n", "wrote to the scalar handle"); 86 87 88done_testing; 89