]> git.vpit.fr Git - perl/modules/subs-auto.git/blob - t/11-pkg.t
e97b7048c548a88ec27761e20696e2fd3b725feb
[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 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   eval { subs::auto::Test::Pkg::foo 4 };
25   is($@, '', 'compiled to subs::auto::Test::Pkg::foo(4)');
26   is($foo, 8, 'subs::auto::Test::Pkg::foo was really called');
27
28   {
29    package subs::auto::Test::Pkg;
30
31    eval { foo 7 };
32    Test::More::is($@, '', 'compiled to foo(7)');
33    Test::More::is($foo, 14, 'subs::auto::Test::Pkg::foo was really called');
34
35    eval { main::foo 9 };
36    Test::More::is($@, '', 'compiled to main::foo(9)');
37    Test::More::is($foo, 9, '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 8 };
48  Test::More::is($@, '', 'compiled to foo(8)');
49  Test::More::is($foo, 16, 'subs::auto::Test::Pkg::foo was really called');
50 }
51
52 {
53  use subs::auto in => '::';
54
55  eval { foo 11 };
56  is($@, '', 'compiled to foo(11)');
57  is($foo, 11, '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 13 };
69   Test::More::is($@, '', 'compiled to foo(13)');
70   Test::More::is($foo, 26, 'subs::auto::Test::Pkg::foo was really called');
71  }
72 }
73
74 sub foo {
75  $main::foo = $_[0];
76 }
77
78 sub subs::auto::Test::Pkg::foo {
79  $main::foo = 2 * $_[0];
80 }