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