1# This script should be runnable with 'make test'.
2
3######################### We start with some black magic to print on failure.
4
5BEGIN { $| = 1 }
6END { print "not ok 1\n"  unless $loaded }
7
8use lib qw( ./t );
9use Magic;
10
11use Class::Contract;
12$loaded = 1;
13print "ok 1\n";
14
15######################### End of black magic.
16# alpha, bravo, charlie, delta, echo, foxtrot,
17# golf, hotel, india, juliett, kilo, lima, mike,
18# november, oscar, papa, quebec, romeo, sierra,
19# tango, uniform, victor, whiskey, xray, yankee, zulu
20::ok('desc'   => "ctor initialization left-most depth-first order",
21     'expect' => 1,
22     'code'   => <<'CODE');
23package Alpha;
24use Class::Contract;
25contract { ctor 'new'; impl { push @::test, 'A'; $::test{'A'} = [@_] } };
26
27package Bravo;
28use Class::Contract;
29contract {
30  inherits 'Alpha';
31  ctor 'new';
32    impl { push @::test, 'B'; $::test{'B'} = [@_] }
33};
34
35package Charlie; use Class::Contract;
36contract {
37  inherits 'Alpha';
38  ctor 'new';
39    impl { push @::test, 'C'; $::test{'C'} = [@_] };
40};
41
42package Delta;
43use Class::Contract;
44contract { ctor 'new'; impl { push @::test, 'D'; $::test{'D'} = [@_] } };
45
46package Echo;
47use Class::Contract;
48contract {
49  inherits 'Delta';
50  ctor 'new';
51    impl { push @::test, 'E'; $::test{'E'} = [@_] };
52};
53
54package Foxtrot;
55use Class::Contract;
56contract {
57  inherits qw( Bravo Charlie Echo );
58  ctor 'new';
59    impl { push @::test, 'F'; $::test{'F'} = [@_] };
60};
61
62package main;
63(@::test, %::test) = ();
64{ my $foo = Foxtrot->new; }
65join('', @::test) eq 'ABCDEF' ? 1 : 0;
66CODE
67
68::ok('desc'   => "Can't use ctor from class with abstract methods",
69     'expect' => qr/^Class \w+ has abstract methods. Can\'t create \w+ object/,
70     'code'   => <<'CODE');
71package Abstract; use Class::Contract; contract { abstract method 'foo' };
72Abstract->new();
73CODE
74
75::ok('desc'   => "ctor initialization pre post impl done right",
76     'expect' => 1,
77     'code'   => <<'CODE');
78#fixme
791;
80CODE
81
821;
83__END__
84
85