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