magic.t tweak
[p5sagit/p5-mst-13.2.git] / t / op / winsystem.t
CommitLineData
dd7038b3 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 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 {
9e735501 79# chdir($cwd);
80# rmtree($testdir);
dd7038b3 81}
82if (open(my $EIN, "$cwd/op/${exename}_exe.uu")) {
83 print "# Unpacking $exename.exe\n";
84 my $e;
85 {
86 local $/;
87 $e = unpack "u", <$EIN>;
88 close $EIN;
89 }
90 open my $EOUT, ">$exename.exe" or die "Can't write $exename.exe: $!";
91 binmode $EOUT;
92 print $EOUT $e;
93 close $EOUT;
94}
95else {
9e735501 96 my $minus_o = '';
97 if ($Config{cc} eq 'gcc')
98 {
99 $minus_o = "-o $exename.exe";
100 }
101 print "# Compiling $exename.c\n# $Config{cc} $Config{ccflags} $exename.c\n";
102 if (system("$Config{cc} $Config{ccflags} $minus_o $exename.c >log 2>&1") != 0) {
dd7038b3 103 print "# Could not compile $exename.c, status $?\n"
104 ."# Where is your C compiler?\n"
105 ."1..0 # skipped: can't build test executable\n";
9e735501 106 exit(0);
107 }
108 unless (-f "$exename.exe") {
109 if (open(LOG,'<log'))
110 {
111 while(<LOG>) {
112 print "# ",$_;
113 }
114 }
115 else {
116 warn "Cannot open log (in $testdir):$!";
117 }
dd7038b3 118 }
119}
120copy("$plxname.bat","$plxname.cmd");
121chdir($cwd);
9e735501 122unless (-x "$testdir/$exename.exe") {
123 print "# Could not build $exename.exe\n"
124 ."1..0 # skipped: can't build test executable\n";
125 exit(0);
126}
dd7038b3 127
128open my $T, "$^X -I../lib -w op/system_tests |"
129 or die "Can't spawn op/system_tests: $!";
130my $expect;
131my $comment = "";
132my $test = 0;
133while (<$T>) {
134 chomp;
135 if (/^1\.\./) {
136 print "$_\n";
137 }
138 elsif (/^#+\s(.*)$/) {
139 $comment = $1;
140 }
141 elsif (/^</) {
142 $expect = $_;
143 $expect =~ tr/<>/[]/;
144 $expect =~ s/\Q$plxname\E]/$plxname.bat]/;
145 }
146 else {
147 if ($expect ne $_) {
148 print "# $comment\n" if $comment;
149 print "# want: $expect\n";
150 print "# got : $_\n";
151 print "not ";
152 }
153 ++$test;
154 print "ok $test\n";
155 }
156}
157close $T;