]> git.vpit.fr Git - perl/modules/subs-auto.git/blob - t/11-pkg.t
bd4ebb3504a069a73664e22e82e99557dcd24063
[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 => 12;
7
8 our $foo;
9
10 {
11  use subs::auto in => 'subs::auto::Test::Pkg';
12
13  eval { subs::auto::Test::Pkg::foo 5 };
14  is($@, '', 'compiled to subs::auto::Test::Pkg::foo(5)');
15  is($foo, 10, 'subs::auto::Test::Pkg::foo was really called');
16
17  {
18   use subs::auto;
19
20   eval { foo 3 };
21   is($@, '', 'compiled to foo(3)');
22   is($foo, 3, 'main::foo was really called');
23
24   {
25    package subs::auto::Test::Pkg;
26
27    eval { foo 7 };
28    Test::More::is($@, '', 'compiled to foo(7)');
29    Test::More::is($foo, 14, 'subs::auto::Test::Pkg::foo was really called');
30
31    eval { main::foo 9 };
32    Test::More::is($@, '', 'compiled to main::foo(9)');
33    Test::More::is($foo, 9, 'main::foo was really called');
34   }
35  }
36 }
37
38 {
39  use subs::auto in => '::';
40
41  eval { foo 11 };
42  is($@, '', 'compiled to foo(11)');
43  is($foo, 11, 'main::foo was really called');
44 }
45
46 {
47  package subs::auto::Test;
48
49  use subs::auto in => '::Pkg';
50
51  {
52   package subs::auto::Test::Pkg;
53
54   eval { foo 13 };
55   Test::More::is($@, '', 'compiled to foo(13)');
56   Test::More::is($foo, 26, 'subs::auto::Test::Pkg::foo was really called');
57  }
58 }
59
60 sub foo {
61  $main::foo = $_[0];
62 }
63
64 sub subs::auto::Test::Pkg::foo {
65  $main::foo = 2 * $_[0];
66 }