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