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