This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Avoid a conversion to/from UTF-8
[perl5.git] / t / win32 / system.t
CommitLineData
dd7038b3
JH
1#!perl
2
3BEGIN {
4 chdir 't' if -d 't';
f2e3b69f
SH
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');
dd7038b3
JH
8 # XXX this could be further munged to enable some parts on other
9 # platforms
0511665b
MG
10 require './test.pl';
11}
12
13BEGIN {
dd7038b3 14 unless ($^O =~ /^MSWin/) {
0511665b 15 skip_all 'windows specific test';
dd7038b3
JH
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);
9e735501 34die "Could not create '$testdir':$!" unless -d $testdir;
dd7038b3
JH
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 {
0ec158f4 84 chdir($cwd) && rmtree("$cwd/$testdir") if -d "$cwd/$testdir";
dd7038b3 85}
946f19ad 86if (open(my $EIN, "$cwd/win32/${exename}_exe.uu")) {
0511665b 87 note "Unpacking $exename.exe";
dd7038b3
JH
88 my $e;
89 {
90 local $/;
91 $e = unpack "u", <$EIN>;
92 close $EIN;
93 }
94 open my $EOUT, ">$exename.exe" or die "Can't write $exename.exe: $!";
95 binmode $EOUT;
96 print $EOUT $e;
97 close $EOUT;
98}
99else {
9e735501 100 my $minus_o = '';
d4c22fec 101 if ($Config{cc} =~ /\bgcc/i)
9e735501
NIS
102 {
103 $minus_o = "-o $exename.exe";
104 }
0511665b
MG
105 note "Compiling $exename.c";
106 note "$Config{cc} $Config{ccflags} $exename.c";
9e735501 107 if (system("$Config{cc} $Config{ccflags} $minus_o $exename.c >log 2>&1") != 0) {
0511665b
MG
108 note "Could not compile $exename.c, status $?";
109 note "Where is your C compiler?";
110 skip_all "can't build test executable";
9e735501
NIS
111 }
112 unless (-f "$exename.exe") {
113 if (open(LOG,'<log'))
114 {
115 while(<LOG>) {
0511665b 116 note $_;
9e735501
NIS
117 }
118 }
119 else {
120 warn "Cannot open log (in $testdir):$!";
121 }
dd7038b3
JH
122 }
123}
124copy("$plxname.bat","$plxname.cmd");
125chdir($cwd);
9e735501 126unless (-x "$testdir/$exename.exe") {
0511665b
MG
127 note "Could not build $exename.exe";
128 skip_all "can't build test executable";
9e735501 129}
dd7038b3 130
946f19ad
NK
131open my $T, "$^X -I../lib -w win32/system_tests |"
132 or die "Can't spawn win32/system_tests: $!";
dd7038b3
JH
133my $expect;
134my $comment = "";
dd7038b3
JH
135while (<$T>) {
136 chomp;
12508490
SH
137 if (s/^1\.\.//) {
138 plan $_;
dd7038b3
JH
139 }
140 elsif (/^#+\s(.*)$/) {
141 $comment = $1;
142 }
143 elsif (/^</) {
144 $expect = $_;
145 $expect =~ tr/<>/[]/;
146 $expect =~ s/\Q$plxname\E]/$plxname.bat]/;
147 }
148 else {
149 if ($expect ne $_) {
0511665b
MG
150 note $comment if $comment;
151 note "want: $expect";
152 note "got : $_";
12508490 153 }
aac983ac 154 ok($expect eq $_, $comment // '');
dd7038b3
JH
155 }
156}
157close $T;