1#!perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 # We need '../../lib' as well as '../lib' because parts of Config are 6 # delay-loaded, after we've chdir()'ed into $testdir. 7 @INC = ('../lib', '../../lib'); 8 # XXX this could be further munged to enable some parts on other 9 # platforms 10 unless ($^O =~ /^MSWin/) { 11 print "1..0 # skipped: windows specific test\n"; 12 exit 0; 13 } 14} 15 16use File::Path; 17use File::Copy; 18use Config; 19use Cwd; 20use strict; 21 22$| = 1; 23 24my $cwd = cwd(); 25 26my $testdir = "t e s t"; 27my $exename = "showav"; 28my $plxname = "showargv"; 29rmtree($testdir); 30mkdir($testdir); 31die "Could not create '$testdir':$!" unless -d $testdir; 32 33open(my $F, ">$testdir/$exename.c") 34 or die "Can't create $testdir/$exename.c: $!"; 35print $F <<'EOT'; 36#include <stdio.h> 37int 38main(int ac, char **av) 39{ 40 int i; 41 for (i = 0; i < ac; i++) 42 printf("[%s]", av[i]); 43 printf("\n"); 44 return 0; 45} 46EOT 47 48open($F, ">$testdir/$plxname.bat") 49 or die "Can't create $testdir/$plxname.bat: $!"; 50print $F <<'EOT'; 51@rem = '--*-Perl-*-- 52@echo off 53if "%OS%" == "Windows_NT" goto WinNT 54EOT 55 56print $F <<EOT; 57"$^X" -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 58goto endofperl 59:WinNT 60"$^X" -x -S %0 %* 61EOT 62print $F <<'EOT'; 63if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl 64if %errorlevel% == 9009 echo You do not have Perl in your PATH. 65if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul 66goto endofperl 67@rem '; 68#!perl 69#line 15 70print "[$_]" for ($0, @ARGV); 71print "\n"; 72__END__ 73:endofperl 74EOT 75 76close $F; 77 78# build the executable 79chdir($testdir); 80END { 81 chdir($cwd) && rmtree("$cwd/$testdir") if -d "$cwd/$testdir"; 82} 83if (open(my $EIN, "$cwd/win32/${exename}_exe.uu")) { 84 print "# Unpacking $exename.exe\n"; 85 my $e; 86 { 87 local $/; 88 $e = unpack "u", <$EIN>; 89 close $EIN; 90 } 91 open my $EOUT, ">$exename.exe" or die "Can't write $exename.exe: $!"; 92 binmode $EOUT; 93 print $EOUT $e; 94 close $EOUT; 95} 96else { 97 my $minus_o = ''; 98 if ($Config{cc} =~ /\bgcc/i) 99 { 100 $minus_o = "-o $exename.exe"; 101 } 102 print "# Compiling $exename.c\n# $Config{cc} $Config{ccflags} $exename.c\n"; 103 if (system("$Config{cc} $Config{ccflags} $minus_o $exename.c >log 2>&1") != 0) { 104 print "# Could not compile $exename.c, status $?\n" 105 ."# Where is your C compiler?\n" 106 ."1..0 # skipped: can't build test executable\n"; 107 exit(0); 108 } 109 unless (-f "$exename.exe") { 110 if (open(LOG,'<log')) 111 { 112 while(<LOG>) { 113 print "# ",$_; 114 } 115 } 116 else { 117 warn "Cannot open log (in $testdir):$!"; 118 } 119 } 120} 121copy("$plxname.bat","$plxname.cmd"); 122chdir($cwd); 123unless (-x "$testdir/$exename.exe") { 124 print "# Could not build $exename.exe\n" 125 ."1..0 # skipped: can't build test executable\n"; 126 exit(0); 127} 128 129open my $T, "$^X -I../lib -w win32/system_tests |" 130 or die "Can't spawn win32/system_tests: $!"; 131my $expect; 132my $comment = ""; 133my $test = 0; 134while (<$T>) { 135 chomp; 136 if (/^1\.\./) { 137 print "$_\n"; 138 } 139 elsif (/^#+\s(.*)$/) { 140 $comment = $1; 141 } 142 elsif (/^</) { 143 $expect = $_; 144 $expect =~ tr/<>/[]/; 145 $expect =~ s/\Q$plxname\E]/$plxname.bat]/; 146 } 147 else { 148 if ($expect ne $_) { 149 print "# $comment\n" if $comment; 150 print "# want: $expect\n"; 151 print "# got : $_\n"; 152 print "not "; 153 } 154 ++$test; 155 print "ok $test\n"; 156 } 157} 158close $T; 159