aboutsummaryrefslogtreecommitdiffstats
path: root/t/samplerun.t
blob: c3930ed8d8fc5ca60a7c517621c5bfb01ec2b4e7 (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
# -*- mode: perl -*-

use Test::More tests => 3;

use strict;
use warnings;

my $config = 't/fixtures/localhost.conf';
my $testplan = 't/fixtures/testplan';
my $input = 't/fixtures/input';

subtest 'standard input', sub {
  my $cmd = "./xmpt -c $config -p $testplan";
  my $xmptfh = new IO::File("|$cmd") or BAIL_OUT "Can't run '$cmd': $!.\n";
  my $inputfh = new IO::File($input) or
    BAIL_OUT "Couldn't open $input for reading: $!.\n";
  while (<$inputfh>) {
    print $xmptfh $_;
  }
  $inputfh->close;
  $xmptfh->close;
  ok($? == 0, 'Standard input redirect');
};

subtest 'timeout', sub {
  my $cmd = "./xmpt -t 1 -c $config -p $testplan cat 2>/dev/null";
  local $SIG{ALRM} = sub { fail("Timed out running $cmd.") };
  alarm 5;
  system $cmd;
  ok(($? >> 8) != 0, 'Timeout test');
};

subtest 'I/O redirected to cat', sub {
  my $cmd = "./xmpt -c $config -p $testplan cat $input 2>/dev/null";
  local $SIG{ALRM} = sub { fail("Timed out running $cmd.") };
  alarm 10;
  ok((system($cmd) >> 8) == 0, 'I/O redirected to cat');
  alarm 0;
};