Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | #!/usr/bin/perl |
2 | # | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | ||
16 | use strict; | |
17 | use warnings; | |
18 | ||
19 | use Test::More tests => 5; | |
20 | ||
21 | BEGIN { | |
22 | use_ok('Dpkg::Exit'); | |
23 | } | |
24 | ||
25 | my $track = 0; | |
26 | ||
27 | sub test_handler { | |
28 | $track++; | |
29 | } | |
30 | ||
31 | Dpkg::Exit::run_exit_handlers(); | |
32 | ||
33 | is($track, 0, 'no handlers run'); | |
34 | ||
35 | Dpkg::Exit::push_exit_handler(\&test_handler); | |
36 | Dpkg::Exit::pop_exit_handler(); | |
37 | ||
38 | Dpkg::Exit::run_exit_handlers(); | |
39 | ||
40 | is($track, 0, 'push/pop; no handlers run'); | |
41 | ||
42 | Dpkg::Exit::push_exit_handler(\&test_handler); | |
43 | ||
44 | Dpkg::Exit::run_exit_handlers(); | |
45 | ||
46 | is($track, 1, 'push; handler run'); | |
47 | ||
48 | # Check the exit handlers, must be the last thing done. | |
49 | sub exit_handler { | |
50 | pass('exit handler invoked'); | |
51 | exit 0; | |
52 | } | |
53 | ||
54 | Dpkg::Exit::push_exit_handler(\&exit_handler); | |
55 | ||
56 | kill 'INT', $$; | |
57 | ||
58 | 1; |