]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - t/38-localize_elem-magic.t
Importing Scope-Upper-0.01
[perl/modules/Scope-Upper.git] / t / 38-localize_elem-magic.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Scope::Upper qw/localize_elem/;
7
8 use Test::More tests => 6;
9
10 our $x;
11
12 {
13  local $x;
14  local $SIG{__WARN__} = sub { };
15  {
16   {
17    localize_elem '%SIG', '__WARN__' => sub { $x = join '', @_ }, 1;
18    is $x, undef, 'localize_elem $SIG{__WARN__} [not yet]';
19   }
20   warn "1\n";
21   is $x, "1\n", 'localize_elem $SIG{__WARN__} [ok]';
22  }
23  warn "2\n";
24  is $x, "1\n", 'localize_elem $SIG{__WARN__} [done]';
25 }
26
27 sub runperl {
28  my ($val, $in, $desc) = @_;
29  system { $^X } $^X, '-e', "exit(\$ENV{SCOPE_UPPER_TEST} == $val ? 0 : 1)";
30 SKIP: {
31   skip "system() failed: $!" => 1 if $? == -1;
32   if ($in) {
33    is $?, 0, $desc;
34   } else {
35    isnt $?, 0, $desc;
36   }
37  }
38 }
39
40 eval "setpgrp 0, 0";
41
42 my $time = time;
43 {
44  local $ENV{SCOPE_UPPER_TEST};
45  {
46   {
47    localize_elem '%ENV', 'SCOPE_UPPER_TEST' => $time, 1;
48    runperl $time, 0, 'localize_elem $ENV{SCOPE_UPPER_TEST} [not yet]';
49   }
50   runperl $time, 1, 'localize_elem $ENV{SCOPE_UPPER_TEST} [ok]';
51  }
52  runperl $time, 0, 'localize_elem $ENV{SCOPE_UPPER_TEST} [done]';
53 }