dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_Exit.t
CommitLineData
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
16use strict;
17use warnings;
18
19use Test::More tests => 5;
20
21BEGIN {
22 use_ok('Dpkg::Exit');
23}
24
25my $track = 0;
26
27sub test_handler {
28 $track++;
29}
30
31Dpkg::Exit::run_exit_handlers();
32
33is($track, 0, 'no handlers run');
34
35Dpkg::Exit::push_exit_handler(\&test_handler);
36Dpkg::Exit::pop_exit_handler();
37
38Dpkg::Exit::run_exit_handlers();
39
40is($track, 0, 'push/pop; no handlers run');
41
42Dpkg::Exit::push_exit_handler(\&test_handler);
43
44Dpkg::Exit::run_exit_handlers();
45
46is($track, 1, 'push; handler run');
47
48# Check the exit handlers, must be the last thing done.
49sub exit_handler {
50 pass('exit handler invoked');
51 exit 0;
52}
53
54Dpkg::Exit::push_exit_handler(\&exit_handler);
55
56kill 'INT', $$;
57
581;