summaryrefslogtreecommitdiff
path: root/t/win32/system.t
blob: 939a02db55298d7d034668b7dda926c70bed5c7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!perl

BEGIN {
    chdir 't' if -d 't';
    # We need '../../lib' as well as '../lib' because parts of Config are
    # delay-loaded, after we've chdir()'ed into $testdir.
    @INC = ('../lib', '../../lib');
    # XXX this could be further munged to enable some parts on other
    # platforms
    require './test.pl';
}

BEGIN {
    unless ($^O =~ /^MSWin/) {
        skip_all 'windows specific test';
    }
}

use File::Path;
use File::Copy;
use Config;
use Cwd;
use strict;

$| = 1;

my $cwd = cwd();

my $testdir = "t e s t";
my $exename = "showav";
my $plxname = "showargv";
rmtree($testdir);
mkdir($testdir);
die "Could not create '$testdir':$!" unless -d $testdir;

open(my $F, ">$testdir/$exename.c")
    or die "Can't create $testdir/$exename.c: $!";
print $F <<'EOT';
#include <stdio.h>
int
main(int ac, char **av)
{
    int i;
    for (i = 0; i < ac; i++)
	printf("[%s]", av[i]);
    printf("\n");
    return 0;
}
EOT

open($F, ">$testdir/$plxname.bat")
    or die "Can't create $testdir/$plxname.bat: $!";
print $F <<'EOT';
@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
EOT

print $F <<EOT;
"$^X" -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
"$^X" -x -S %0 %*
EOT
print $F <<'EOT';
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!perl
#line 15
print "[$_]" for ($0, @ARGV);
print "\n";
__END__
:endofperl
EOT

close $F;

# build the executable
chdir($testdir);
END {
    chdir($cwd) && rmtree("$cwd/$testdir") if -d "$cwd/$testdir";
}
if (open(my $EIN, "$cwd/win32/${exename}_exe.uu")) {
    note "Unpacking $exename.exe";
    my $e;
    {
	local $/;
	$e = unpack "u", <$EIN>;
	close $EIN;
    }
    open my $EOUT, ">$exename.exe" or die "Can't write $exename.exe: $!";
    binmode $EOUT;
    print $EOUT $e;
    close $EOUT;
}
else {
    my $minus_o = '';
    if ($Config{cc} =~ /\bgcc/i)
     {
      $minus_o = "-o $exename.exe";
     }
    note "Compiling $exename.c";
    note "$Config{cc} $Config{ccflags} $exename.c";
    if (system("$Config{cc} $Config{ccflags} $minus_o $exename.c >log 2>&1") != 0) {
	note "Could not compile $exename.c, status $?";
    note "Where is your C compiler?";
    skip_all "can't build test executable";
    }
    unless (-f "$exename.exe") {
	if (open(LOG,'<log'))
         {
          while(<LOG>) {
              note $_;
          } 
         }
        else {
	  warn "Cannot open log (in $testdir):$!";
        }
    }
}
copy("$plxname.bat","$plxname.cmd");
chdir($cwd);
unless (-x "$testdir/$exename.exe") {
    note "Could not build $exename.exe";
    skip_all "can't build test executable";
}

open my $T, "$^X -I../lib -w win32/system_tests |"
    or die "Can't spawn win32/system_tests: $!";
my $expect;
my $comment = "";
while (<$T>) {
    chomp;
    if (s/^1\.\.//) {
	plan $_;
    }
    elsif (/^#+\s(.*)$/) {
	$comment = $1;
    }
    elsif (/^</) {
	$expect = $_;
	$expect =~ tr/<>/[]/;
	$expect =~ s/\Q$plxname\E]/$plxname.bat]/;
    }
    else {
	if ($expect ne $_) {
	    note $comment if $comment;
	    note "want: $expect";
	    note "got : $_";
	}
	ok($expect eq $_, $comment // '');
    }
}
close $T;