doc: Move Perl version baseline as the first perl coding style subsection
[dpkg.git] / scripts / t / Dpkg_Exit.t
blob5e83689b5f659005680ef574ad6cb1ec3fc53aac
1 #!/usr/bin/perl
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.
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.
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/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 7;
21 BEGIN {
22 use_ok('Dpkg::Exit');
25 my $track = 0;
27 sub test_handler {
28 $track++;
31 Dpkg::Exit::run_exit_handlers();
33 is($track, 0, 'no handlers run');
35 Dpkg::Exit::push_exit_handler(\&test_handler);
36 Dpkg::Exit::pop_exit_handler();
38 Dpkg::Exit::run_exit_handlers();
40 is($track, 0, 'push/pop; no handlers run');
42 Dpkg::Exit::push_exit_handler(\&test_handler);
44 Dpkg::Exit::run_exit_handlers();
46 is($track, 1, 'push; handler run');
48 # Check the exit handlers, must be the last thing done.
49 sub exit_handler {
50 pass('exit handler invoked');
51 exit 0;
54 sub ini_handler {
55 pass('ini handler invoked');
58 sub end_handler {
59 pass('end handler invoked');
62 Dpkg::Exit::push_exit_handler(\&end_handler);
63 Dpkg::Exit::push_exit_handler(\&exit_handler);
64 Dpkg::Exit::push_exit_handler(\&ini_handler);
66 kill 'INT', $$;