Debian Codegraph @

t/exefiles.t

raw
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3
4 #
5 # $Id: $
6 # Author: Slaven Rezic
7 #
8
9 use strict;
10 use FindBin;
11 use File::Spec;
12
13 BEGIN {
14 if (!eval q{
15 use Test::More;
16 use POSIX ":sys_wait_h";
17 1;
18 }) {
19 print "1..0 # skip no Test::More and/or POSIX module\n";
20 exit;
21 }
22 if ($^O eq 'MSWin32') {
23 print "1..0 # skip not on Windows (because of fork, waitpid...)\n";
24 exit;
25 }
26 }
27
28 our $DEBUG = 0;
29
30 my @cmd = (
31 ['ptksh'],
32 ['ptked'],
33 ['ptked', "-encoding", "utf8", File::Spec->rel2abs($0)],
34 ['ptked', "-encoding", "iso-8859-1", File::Spec->rel2abs($0)],
35 ['gedi'],
36 ['gedi', File::Spec->rel2abs($0)],
37 );
38
39 chdir "$FindBin::RealBin/.."
40 or die "Can't change to ptk directory: $!";
41
42 plan tests => scalar(@cmd);
43
44 OPT:
45 for my $opt (@cmd) {
46 my $script = shift @$opt;
47 my $testname = "Executing $script with " . (@$opt ? "@$opt" : "no args");
48 my @cmd = ($^X, "-Mblib", "blib/script/$script", "-geometry", "+10+10", @$opt);
49 my $pid = fork;
50 if ($pid == 0) {
51 warn "@cmd\n" if $DEBUG;
52 open(STDERR, ">" . File::Spec->devnull);
53 exec @cmd;
54 die $!;
55 }
56 for (1..10) {
57 select(undef,undef,undef,0.1);
58 my $kid = waitpid($pid, WNOHANG);
59 if ($kid) {
60 is($?, 0, "$testname (exited spontaneously)")
61 or diag "@cmd";
62 next OPT;
63 }
64 }
65 kill TERM => $pid;
66 for (1..20) {
67 select(undef,undef,undef,0.1);
68 my $kid = waitpid($pid, WNOHANG); # reap zombie
69 if (!kill 0 => $pid) {
70 pass("$testname (killed with TERM)");
71 next OPT;
72 }
73 }
74 kill KILL => $pid;
75 pass("$testname (killed with KILL)");
76 }
77
78 __END__