root/t/02pl-scripts.t

Revision 303:6f57b7328cb8, 1.3 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

The Great Renaming: Change all command names to 'pl-*' and directory to '.pl'.
The idea behind this is to emphasise that the software is called ?*Project*
Lancelot? as opposed to plain ?Lancelot?. There is apparently a KDE tool that
goes by the name of ?Lancelot?, and we want to make clear that this is separate
and different. Also, Project Lancelot has been around for a lot longer!

Line 
1#!/usr/bin/perl -w
2
3use Test::More "no_plan";
4
5use English;
6use FindBin qw($Bin);
7use File::Temp qw/tempdir/;
8use IPC::Open3;
9use POSIX ":sys_wait_h";
10
11sub execscript ($$$$);
12
13my $tmphome = tempdir(CLEANUP => 1);
14$ENV{HOME} = $tmphome;
15
16sub cleanup ($;$) {
17    my ($signal, $exitcode) = @_;
18    $exitcode = 0 unless (defined $exitcode);
19    my $cleanup = "/bin/rm -rf $tmphome";
20    system ($cleanup);
21
22    exit $exitcode;
23}
24$SIG{__DIE__} = \&cleanup;
25$SIG{'INT'} = \&cleanup;
26$SIG{'QUIT'} = \&cleanup;
27
28my @in = <DATA>;
29is (@in, 2, "no of addresses");
30my (@out, @err);
31
32execscript ("blib/script/pl-init test\@localhost $ENV{USER}\@localhost", [], \@out, \@err);
33is (@err, 0, "init errors");
34execscript ("blib/script/pl-subscribe --nowelcome --nomail test\@localhost", \@in, \@out, \@err);
35is (@err, 0, "subscribe errors");
36cleanup('NONE', 0);
37
38sub execscript ( $$$$ ) {
39    my ($script, $pIn, $pOut, $pErr) = @_;
40
41    my $pid
42      = open3 (*IN, *OUT, *ERR,
43               $script)
44        or die "Cannot start script (\"$script\"): $ERRNO";
45
46    print IN @{$pIn};
47    close IN;
48
49    @{$pOut} = <OUT>;
50    close OUT;
51    @{$pErr} = <ERR>;
52    close ERR;
53
54    print STDERR @{$pErr} if @{$pErr};
55
56    waitpid ($pid, 0)
57      or die "Cannot stop (\"$script\"): $ERRNO";
58
59}
60
61__DATA__
62Gerd Aschemann <aschemann@localhost>
63Anselm Lingnau <anselm@localhost>
Note: See TracBrowser for help on using the browser.