]> git.vpit.fr Git - perl/modules/subs-auto.git/blob - t/11-pkg.t
Fix default package
[perl/modules/subs-auto.git] / t / 11-pkg.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 16;
7
8 our $foo;
9
10 {
11  eval q{
12   use subs::auto in => 'subs::auto::Test::Pkg';
13   subs::auto::Test::Pkg::foo 1
14  };
15  my $err = $@;
16  is($err, '', 'compiled to subs::auto::Test::Pkg::foo(1)');
17  is($foo, 3,  'subs::auto::Test::Pkg::foo was really called');
18 }
19
20 {
21  eval q{
22   use subs::auto in => 'subs::auto::Test::Pkg';
23   {
24    use subs::auto;
25    foo 2
26   }
27  };
28  my $err = $@;
29  no warnings 'uninitialized';
30  is($err, '', 'compiled to foo(2)');
31  is($foo, 4,  'main::foo was really called');
32 }
33
34 {
35  eval q{
36   use subs::auto in => 'subs::auto::Test::Pkg';
37   {
38    use subs::auto;
39    subs::auto::Test::Pkg::foo 3;
40   }
41  };
42  my $err = $@;
43  no warnings 'uninitialized';
44  is($err, '', 'compiled to subs::auto::Test::Pkg::foo(3)');
45  is($foo, 9,  'subs::auto::Test::Pkg::foo was really called');
46 }
47
48 {
49  eval q{
50   use subs::auto in => 'subs::auto::Test::Pkg';
51   {
52    use subs::auto;
53    {
54     package subs::auto::Test::Pkg;
55     foo 4
56    }
57   }
58  };
59  my $err = $@;
60  no warnings 'uninitialized';
61  Test::More::is($err, '', 'compiled to foo(4)');
62  Test::More::is($foo, 12, 'subs::auto::Test::Pkg::foo was really called');
63 }
64
65 {
66  eval q{
67   use subs::auto in => 'subs::auto::Test::Pkg';
68   {
69    use subs::auto;
70    {
71     package subs::auto::Test::Pkg;
72     main::foo 5
73    }
74   }
75  };
76  my $err = $@;
77  no warnings 'uninitialized';
78  Test::More::is($err, '', 'compiled to main::foo(5)');
79  Test::More::is($foo, 10, 'main::foo was really called');
80 }
81
82 {
83  package subs::auto::Test::Pkg;
84
85  eval q{
86   use subs::auto;
87   foo 6
88  };
89  my $err = $@;
90  no warnings 'uninitialized';
91  Test::More::is($err, '', 'compiled to foo(6)');
92  Test::More::is($foo, 18, 'subs::auto::Test::Pkg::foo was really called');
93 }
94
95 {
96  eval q{
97   use subs::auto in => '::';
98   foo 7
99  };
100  my $err = $@;
101  no warnings 'uninitialized';
102  is($err, '', 'compiled to foo(7)');
103  is($foo, 14, 'main::foo was really called');
104 }
105
106 {
107  package subs::auto::Test;
108
109  eval q{
110   use subs::auto in => '::Pkg';
111   {
112    package subs::auto::Test::Pkg;
113    foo 8;
114   }
115  };
116  my $err = $@;
117  no warnings 'uninitialized';
118  Test::More::is($err, '', 'compiled to foo(8)');
119  Test::More::is($foo, 24, 'subs::auto::Test::Pkg::foo was really called');
120 }
121
122 sub foo {
123  $main::foo = 2 * $_[0];
124 }
125
126 sub subs::auto::Test::Pkg::foo {
127  $main::foo = 3 * $_[0];
128 }