Skip to content
Snippets Groups Projects
account-manager.t 813 B
Newer Older
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed
#!/usr/bin/perl

use strict;
use warnings;

use English qw(-no_match_vars);
use IPC::Run qw(run);
use Test::More;

plan tests => 6;

my ($out, $err, $rc);

($out, $err, $rc) = run_executable('account-manager.pl', '--help');
ok($rc == 0, '--help exit status');
is($err, '', '--help stderr');
like(
    $out,
    qr/^Usage:/,
    '--help stdout'
);

($out, $err, $rc) = run_executable('account-manager.pl');
ok($rc == 2, 'no action exit status');
like(
    $err,
    qr/no action given, aborting/,
    'no action stderr'
);
is($out, '', 'no action stdout');

sub run_executable {
    my ($executable, $args) = @_;

    my @args = $args ? split(/\s+/, $args) : ();
    run(
        [ $EXECUTABLE_NAME, 'bin/' . $executable, @args ],
        \my ($in, $out, $err)
    );
    return ($out, $err, $CHILD_ERROR >> 8);
}