1use Test::Mini::Unit;
2
3# The following test cases don't actually prove anything; the side effects do.
4our @calls = ();
5
6case Top {
7    setup { push @calls, [ __PACKAGE__, 'first setup' ] }
8    setup { push @calls, [ __PACKAGE__, 'second setup' ] }
9
10    test it { push @calls, [ __PACKAGE__, 'test' ]; skip('Fixture') }
11
12    teardown { push @calls, [ __PACKAGE__, 'first teardown' ] }
13    teardown { push @calls, [ __PACKAGE__, 'second teardown' ] }
14
15    case Nested {
16        setup { push @calls, [ __PACKAGE__, 'first setup' ] }
17        setup { push @calls, [ __PACKAGE__, 'second setup' ] }
18
19        test it { push @calls, [ __PACKAGE__, 'test' ]; skip('Fixture') }
20
21        teardown { push @calls, [ __PACKAGE__, 'first teardown' ] }
22        teardown { push @calls, [ __PACKAGE__, 'second teardown' ] }
23
24        case Deeply {
25            setup { push @calls, [ __PACKAGE__, 'first setup' ] }
26            setup { push @calls, [ __PACKAGE__, 'second setup' ] }
27
28            test it { push @calls, [ __PACKAGE__, 'test' ]; skip('Fixture') }
29
30            teardown { push @calls, [ __PACKAGE__, 'first teardown' ] }
31            teardown { push @calls, [ __PACKAGE__, 'second teardown' ] }
32        }
33    }
34}
35
36# Begin actual tests
37####################
38package t::Test::Mini::Unit::Sugar::TestCase::Advice;
39use base 'Test::Mini::TestCase';
40
41use Test::Mini::Assertions;
42
43sub assert_calls {
44    my ($pkg, $expectations) = @_;
45    no strict 'refs';
46    @calls = ();
47    $pkg->new(name => 'test_it')->run(Test::Mini::Logger->new());
48    assert_equal(\@calls, $expectations);
49}
50
51sub test_top_level_cases {
52    assert_calls('Top', [
53        [ 'Top', 'first setup'     ],
54        [ 'Top', 'second setup'    ],
55        [ 'Top', 'test'            ],
56        [ 'Top', 'second teardown' ],
57        [ 'Top', 'first teardown'  ],
58    ]);
59}
60
61sub test_nested_cases {
62    assert_calls('Top::Nested', [
63        [ 'Top',         'first setup'     ],
64        [ 'Top',         'second setup'    ],
65        [ 'Top::Nested', 'first setup'     ],
66        [ 'Top::Nested', 'second setup'    ],
67        [ 'Top::Nested', 'test'            ],
68        [ 'Top::Nested', 'second teardown' ],
69        [ 'Top::Nested', 'first teardown'  ],
70        [ 'Top',         'second teardown' ],
71        [ 'Top',         'first teardown'  ],
72    ]);
73}
74
75sub test_deeply_nested_cases {
76    assert_calls('Top::Nested::Deeply', [
77        [ 'Top',                 'first setup'     ],
78        [ 'Top',                 'second setup'    ],
79        [ 'Top::Nested',         'first setup'     ],
80        [ 'Top::Nested',         'second setup'    ],
81        [ 'Top::Nested::Deeply', 'first setup'     ],
82        [ 'Top::Nested::Deeply', 'second setup'    ],
83        [ 'Top::Nested::Deeply', 'test'            ],
84        [ 'Top::Nested::Deeply', 'second teardown' ],
85        [ 'Top::Nested::Deeply', 'first teardown'  ],
86        [ 'Top::Nested',         'second teardown' ],
87        [ 'Top::Nested',         'first teardown'  ],
88        [ 'Top',                 'second teardown' ],
89        [ 'Top',                 'first teardown'  ],
90    ]);
91}
92
931;
94