]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/34-glob.t
2e1a441a56b3c9cb10e5825cf5a1d8af4bb26339
[perl/modules/Variable-Magic.git] / t / 34-glob.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use lib 't/lib';
9 use VPIT::TestHelpers;
10
11 BEGIN {
12  load_or_skip('Symbol', undef, [ 'gensym' ],
13               'required for testing magic for globs');
14
15  plan tests => 2 * 17 + 1;
16 }
17
18 use Variable::Magic qw<cast dispell VMG_COMPAT_GLOB_GET>;
19
20 my %get = VMG_COMPAT_GLOB_GET ? (get => 1) : ();
21
22 use lib 't/lib';
23 use Variable::Magic::TestWatcher;
24
25 my $wiz = init_watcher
26         [ qw<get set len clear free copy dup local fetch store exists delete> ],
27         'glob';
28
29 local *a = gensym();
30
31 watch { cast *a, $wiz } +{ }, 'cast';
32
33 watch { local *b = *a } +{ %get }, 'assign to';
34
35 SKIP: {
36  skip 'This failed temporarily between perls 5.13.1 and 5.13.8 (included)'
37                             => 5 * 2 if "$]" >= 5.013_001 and "$]" <= 5.013_008;
38
39  my $cxt = 'void contex';
40  my $exp = { set => 1 };
41
42  watch { *a = \1 }          $exp, "assign scalar slot in $cxt";
43  watch { *a = [ qw<x y> ] } $exp, "assign array slot in $cxt";
44  watch { *a = { u => 1 } }  $exp, "assign hash slot in $cxt";
45  watch { *a = sub { } }     $exp, "assign code slot in $cxt";
46  watch { *a = gensym() }    $exp, "assign glob in $cxt";
47 }
48
49 {
50  my $cxt = 'scalar context';
51  my $exp = { %get, set => 1 };
52  my $v;
53
54  $v = watch { *a = \1 }          $exp, "assign scalar slot in $cxt";
55  $v = watch { *a = [ qw<x y> ] } $exp, "assign array slot in $cxt";
56  $v = watch { *a = { u => 1 } }  $exp, "assign hash slot in $cxt";
57  $v = watch { *a = sub { } }     $exp, "assign code slot in $cxt";
58  $v = watch { *a = gensym() }    $exp, "assign glob in $cxt";
59 }
60
61 watch {
62  local *b = gensym();
63  watch { cast *b, $wiz } +{ }, 'cast 2';
64 } +{ }, 'scope end';
65
66 %get = () if "$]" >= 5.013_007;
67
68 watch { undef *a } +{ %get }, 'undef';
69
70 watch { dispell *a, $wiz } +{ %get }, 'dispell';