155745691Smillert#!perl 255745691Smillert 355745691Smillertuse Config; 455745691Smillertuse Cwd; 555745691Smillertuse strict; 66fb12b70Safresh1BEGIN { 76fb12b70Safresh1 require './test.pl'; 86fb12b70Safresh1} 955745691Smillert 1055745691Smillert$| = 1; 1155745691Smillert 1255745691Smillertmy $cwdb = my $cwd = cwd(); 1355745691Smillert$cwd =~ s,\\,/,g; 1455745691Smillert$cwdb =~ s,/,\\,g; 1555745691Smillert 1655745691Smillertmy $testdir = "t e s t"; 1755745691Smillertmy $exename = "showav"; 1855745691Smillertmy $plxname = "showargv"; 1955745691Smillert 2055745691Smillertmy $exe = "$testdir/$exename"; 2155745691Smillertmy $exex = $exe . ".exe"; 2255745691Smillert(my $exeb = $exe) =~ s,/,\\,g; 2355745691Smillertmy $exebx = $exeb . ".exe"; 2455745691Smillert 2555745691Smillertmy $bat = "$testdir/$plxname"; 2655745691Smillertmy $batx = $bat . ".bat"; 2755745691Smillert(my $batb = $bat) =~ s,/,\\,g; 2855745691Smillertmy $batbx = $batb . ".bat"; 2955745691Smillert 3055745691Smillertmy $cmdx = $bat . ".cmd"; 3155745691Smillertmy $cmdb = $batb; 3255745691Smillertmy $cmdbx = $cmdb . ".cmd"; 3355745691Smillert 3455745691Smillertmy @commands = ( 3555745691Smillert $exe, 3655745691Smillert $exex, 3755745691Smillert $exeb, 3855745691Smillert $exebx, 3955745691Smillert "./$exe", 4055745691Smillert "./$exex", 4155745691Smillert ".\\$exeb", 4255745691Smillert ".\\$exebx", 4355745691Smillert "$cwd/$exe", 4455745691Smillert "$cwd/$exex", 4555745691Smillert "$cwdb\\$exeb", 4655745691Smillert "$cwdb\\$exebx", 4755745691Smillert $bat, 4855745691Smillert $batx, 4955745691Smillert $batb, 5055745691Smillert $batbx, 5155745691Smillert "./$bat", 5255745691Smillert "./$batx", 5355745691Smillert ".\\$batb", 5455745691Smillert ".\\$batbx", 5555745691Smillert "$cwd/$bat", 5655745691Smillert "$cwd/$batx", 5755745691Smillert "$cwdb\\$batb", 5855745691Smillert "$cwdb\\$batbx", 5955745691Smillert $cmdx, 6055745691Smillert $cmdbx, 6155745691Smillert "./$cmdx", 6255745691Smillert ".\\$cmdbx", 6355745691Smillert "$cwd/$cmdx", 6455745691Smillert "$cwdb\\$cmdbx", 6555745691Smillert [$^X, $batx], 6655745691Smillert [$^X, $batbx], 6755745691Smillert [$^X, "./$batx"], 6855745691Smillert [$^X, ".\\$batbx"], 6955745691Smillert [$^X, "$cwd/$batx"], 7055745691Smillert [$^X, "$cwdb\\$batbx"], 7155745691Smillert); 7255745691Smillert 7355745691Smillertmy @av = ( 7455745691Smillert undef, 7555745691Smillert "", 7655745691Smillert " ", 7755745691Smillert "abc", 7855745691Smillert "a b\tc", 7955745691Smillert "\tabc", 8055745691Smillert "abc\t", 8155745691Smillert " abc\t", 8255745691Smillert "\ta b c ", 8355745691Smillert ["\ta b c ", ""], 8455745691Smillert ["\ta b c ", " "], 8555745691Smillert ["", "\ta b c ", "abc"], 8655745691Smillert [" ", "\ta b c ", "abc"], 8755745691Smillert ['" "', 'a" "b" "c', "abc"], 8855745691Smillert); 8955745691Smillert 90*b8851fccSafresh1print "1.." . (@commands * @av * 3) . "\n"; 9155745691Smillertfor my $cmds (@commands) { 9255745691Smillert for my $args (@av) { 9355745691Smillert my @all_args; 9455745691Smillert my @cmds = defined($cmds) ? (ref($cmds) ? @$cmds : $cmds) : (); 9555745691Smillert my @args = defined($args) ? (ref($args) ? @$args : $args) : (); 966fb12b70Safresh1 note "####### [@cmds]"; 9755745691Smillert print "<", join('><', 9855745691Smillert $cmds[$#cmds], 9955745691Smillert map { my $x = $_; $x =~ s/"//g; $x } @args), 10055745691Smillert ">\n"; 10155745691Smillert if (system(@cmds,@args) != 0) { 10255745691Smillert print "Failed, status($?)\n"; 10355745691Smillert if ($Config{ccflags} =~ /\bDDEBUGGING\b/) { 10455745691Smillert print "Running again in debug mode\n"; 10555745691Smillert $^D = 1; # -Dp 10655745691Smillert system(@cmds,@args); 10755745691Smillert } 10855745691Smillert } 10955745691Smillert $^D = 0; 11055745691Smillert my $cmdstr = join " ", map { /\s|^$/ && !/\"/ 11155745691Smillert ? qq["$_"] : $_ } @cmds, @args; 1126fb12b70Safresh1 note "####### '$cmdstr'"; 11355745691Smillert if (system($cmdstr) != 0) { 11455745691Smillert print "Failed, status($?)\n"; 11555745691Smillert if ($Config{ccflags} =~ /\bDDEBUGGING\b/) { 11655745691Smillert print "Running again in debug mode\n"; 11755745691Smillert $^D = 1; # -Dp 11855745691Smillert system($cmdstr); 11955745691Smillert } 12055745691Smillert } 12155745691Smillert $^D = 0; 122*b8851fccSafresh1 123*b8851fccSafresh1 note "# pipe [".join(";", @cmds, @args). "]"; 124*b8851fccSafresh1 if (open my $io, "-|", @cmds, @args) { 125*b8851fccSafresh1 print <$io>; 126*b8851fccSafresh1 close $io; 127*b8851fccSafresh1 } 128*b8851fccSafresh1 else { 129*b8851fccSafresh1 print STDERR "Failed pipe open [",join(";", @cmds, @args),"]: $!\n"; 130*b8851fccSafresh1 } 13155745691Smillert } 13255745691Smillert} 133