summaryrefslogtreecommitdiffstats
path: root/t/scripts/run-private-scripts.t
blob: 0632ea26ec61eb67578a9d1308a636335e2bf389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl

# Copyright (C) 2014-2016 Jakub Wilk <jwilk@jwilk.net>
# Copyright (C) 2017-2022 Axel Beckert <abe@debian.org>
#
# This program is free software.  It is distributed under the terms of
# the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, you can find it on the World Wide
# Web at https://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

use strict;
use warnings;

use Const::Fast;
use IPC::Run3;
use Test::More tests => 2;

const my $DOT => q{.};
const my $WAIT_STATUS_SHIFT => 8;

$ENV{'LINTIAN_BASE'} //= $DOT;
my $cmd_dir = "$ENV{LINTIAN_BASE}/private";

sub t {
    my ($cmd, $expected, $expected_stderr) = @_;

    subtest $cmd => sub {
        my $command = "$cmd_dir/$cmd";
        if (-x $command) {
            plan tests => 3;

            $expected_stderr //= qr/\A\Z/;
            my $input = undef;
            my $output;
            my $error;
            run3([$command], \$input, \$output, \$error);

            my $status = ($? >> $WAIT_STATUS_SHIFT);
            is($status, 0, "Exit status 0 of $cmd");
            like($error, $expected_stderr,
                "STDERR of $cmd matches $expected_stderr");
            like($output, $expected, "Expected output of $cmd");
        } else {
            plan skip_all =>'due to script not present (likely not installed)';
        }
    };

    return;
}

SKIP: {
    skip('Only works with git', 1) unless -x '/usr/bin/git' && -d '.git';

    t(
        'generate-tag-summary',
        qr/Assuming commit range to be/,
        qr/^No tags were added or removed$|\A\Z/
    );
}
t('latest-policy-version', qr/^(\d+\.){3}/);

done_testing();

# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et