aboutsummaryrefslogtreecommitdiffstats
path: root/t/run.t
blob: 7f0b24be9c847f074f8f39c93200f046507a4ab2 (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
#!/usr/bin/perl
# $Id: gprintify 257533 2009-05-23 12:45:15Z guillomovitch $

use strict;
use warnings;

use IPC::Run qw/run/;
use Test::More;
use FindBin qw/$Bin/;
use File::Temp qw/tempdir/;

my @programs = qw/
    clean_files
    compress_files
    relink_symlinks
    gprintify
    translate_menu
    remove_info_dir
    fix_pamd
    fix_eol
    check_elf_files
    check_desktop_files
/;

plan tests => @programs * 6;

my ($out, $err);
delete $ENV{RPM_BUILD_ROOT};

foreach my $prog (@programs) {

    ($out, $err) = run_prog($prog);
    is(  $out, '',                         "$prog stdin without buildroot" );
    like($err, qr/^No build root defined/, "$prog stderr without buildroot");

    $ENV{RPM_BUILD_ROOT} = "foo";

    ($out, $err) = run_prog($prog);
    is(  $out, '',                      "$prog stdin with wrong buildroot" );
    like($err, qr/^Invalid build root/, "$prog stderr with wrong buildroot");

    my $buildroot = tempdir(CLEANUP => 1);

    $ENV{RPM_BUILD_ROOT} = $buildroot;

    ($out, $err) = run_prog($prog);
    is($out, '', "$prog stdin with correct buildroot" );
    is($err, '', "$prog stderr with correct buildroot");

    delete $ENV{RPM_BUILD_ROOT};
}

sub run_prog {
    my ($prog, @args) = @_;

    run (["$Bin/../$prog", @args], \my($in, $out, $err));
    return ($out, $err);
}