This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
from the non-ANSI comment police (was: it won't compile on win32)
[perl5.git] / t / op / system.t
1 #!perl
2
3 BEGIN {
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
14 use File::Path;
15 use File::Copy;
16 use Config;
17 use Cwd;
18 use strict;
19
20 $| = 1;
21
22 my $cwd = cwd();
23
24 my $testdir = "t e s t";
25 my $exename = "showav";
26 my $plxname = "showargv";
27 rmtree($testdir);
28 mkdir($testdir);
29
30 open(my $F, ">$testdir/$exename.c")
31     or die "Can't create $testdir/$exename.c: $!";
32 print $F <<'EOT';
33 #include <stdio.h>
34 int
35 main(int ac, char **av)
36 {
37     int i;
38     for (i = 0; i < ac; i++)
39         printf("[%s]", av[i]);
40     printf("\n");
41     return 0;
42 }
43 EOT
44
45 open($F, ">$testdir/$plxname.bat")
46     or die "Can't create $testdir/$plxname.bat: $!";
47 print $F <<'EOT';
48 @rem = '--*-Perl-*--
49 @echo off
50 if "%OS%" == "Windows_NT" goto WinNT
51 EOT
52
53 print $F <<EOT;
54 "$^X" -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
55 goto endofperl
56 :WinNT
57 "$^X" -x -S %0 %*
58 EOT
59 print $F <<'EOT';
60 if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
61 if %errorlevel% == 9009 echo You do not have Perl in your PATH.
62 if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
63 goto endofperl
64 @rem ';
65 #!perl
66 #line 15
67 print "[$_]" for ($0, @ARGV);
68 print "\n";
69 __END__
70 :endofperl
71 EOT
72
73 close $F;
74
75 # build the executable
76 chdir($testdir);
77 END {
78     chdir($cwd);
79     rmtree($testdir);
80 }
81 if (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 }
94 else {
95     print "# Compiling $exename.c\n";
96     if (system("$Config{cc} $Config{ccflags} $exename.c 2>&1 >nul") != 0) {
97         print "# Could not compile $exename.c, status $?\n"
98              ."# Where is your C compiler?\n"
99              ."1..0 # skipped: can't build test executable\n";
100     }
101 }
102 copy("$plxname.bat","$plxname.cmd");
103 chdir($cwd);
104
105 open my $T, "$^X -I../lib -w op/system_tests |"
106     or die "Can't spawn op/system_tests: $!";
107 my $expect;
108 my $comment = "";
109 my $test = 0;
110 while (<$T>) {
111     chomp;
112     if (/^1\.\./) {
113         print "$_\n";
114     }
115     elsif (/^#+\s(.*)$/) {
116         $comment = $1;
117     }
118     elsif (/^</) {
119         $expect = $_;
120         $expect =~ tr/<>/[]/;
121         $expect =~ s/\Q$plxname\E]/$plxname.bat]/;
122     }
123     else {
124         if ($expect ne $_) {
125             print "# $comment\n" if $comment;
126             print "# want: $expect\n";
127             print "# got : $_\n";
128             print "not ";
129         }
130         ++$test;
131         print "ok $test\n";
132     }
133 }
134 close $T;