2 # t/test.pl - most of Test::More functionality without the fuss
18 print STDOUT "1..$n\n";
24 if (defined $planned && $planned != $ran) {
25 print STDOUT "# Looks like you planned $planned tests but ran $ran.\n";
31 print STDOUT "1..0 - @_\n";
33 print STDOUT "1..0\n";
39 my ($pass, $where, $name, @mess) = @_;
40 # Do not try to microoptimize by factoring out the "not ".
44 $out = $pass ? "ok $test - $name" : "not ok $test - $name";
46 $out = $pass ? "ok $test" : "not ok $test";
49 $out .= " # TODO $TODO" if $TODO;
50 print STDOUT "$out\n";
53 print STDOUT "# Failed $where\n";
56 # Ensure that the message is properly escaped.
57 print STDOUT map { /^#/ ? "$_\n" : "# $_\n" }
58 map { split /\n/ } @mess if @mess;
66 my @caller = caller(1);
67 return "at $caller[1] line $caller[2]";
71 my ($pass, $name, @mess) = @_;
72 _ok($pass, _where(), $name, @mess);
77 return 'undef' unless defined $x;
84 my ($got, $expected, $name, @mess) = @_;
85 my $pass = $got eq $expected;
87 unshift(@mess, "# got "._q($got)."\n",
88 "# expected "._q($expected)."\n");
90 _ok($pass, _where(), $name, @mess);
94 my ($got, $isnt, $name, @mess) = @_;
95 my $pass = $got ne $isnt;
97 unshift(@mess, "# it should not be "._q($got)."\n",
100 _ok($pass, _where(), $name, @mess);
103 # Note: this isn't quite as fancy as Test::More::like().
105 my ($got, $expected, $name, @mess) = @_;
107 if (ref $expected eq 'Regexp') {
108 $pass = $got =~ $expected;
110 unshift(@mess, "# got '$got'\n");
113 $pass = $got =~ /$expected/;
115 unshift(@mess, "# got '$got'\n",
116 "# expected /$expected/\n");
119 _ok($pass, _where(), $name, @mess);
127 _ok(0, _where(), @_);
138 # Note: can't pass multipart messages since we try to
139 # be compatible with Test::More::skip().
142 my $n = @_ ? shift : 1;
144 print STDOUT "ok $test # skip: $why\n";
153 return 0 unless $#$ra == $#$rb;
154 for my $i (0..$#$ra) {
155 return 0 unless $ra->[$i] eq $rb->[$i];
165 _ok(!$@, _where(), "require $require");
173 _ok(!$@, _where(), "use $use");
176 # runperl - Runs a separate perl interpreter.
178 # switches => [ command-line switches ]
179 # nolib => 1 # don't use -I../lib (included by default)
180 # prog => one-liner (avoid quotes)
181 # progfile => perl script
182 # stdin => string to feed the stdin
183 # stderr => redirect stderr to stdout
184 # args => [ command-line arguments to the perl program ]
185 # verbose => print the command line
187 my $is_mswin = $^O eq 'MSWin32';
188 my $is_netware = $^O eq 'NetWare';
189 my $is_macos = $^O eq 'MacOS';
190 my $is_vms = $^O eq 'VMS';
193 my ($runperl, $args) = @_;
196 # In VMS protect with doublequotes because otherwise
197 # DCL will lowercase -- unless already doublequoted.
198 $_ = q(").$_.q(") if $is_vms && !/^\"/;
199 $$runperl .= ' ' . $_;
206 if ($args{switches}) {
207 _quote_args(\$runperl, $args{switches});
209 unless ($args{nolib}) {
211 $runperl .= ' -I::lib';
212 # Use UNIX style error messages instead of MPW style.
213 $runperl .= ' -MMac::err=unix' if $args{stderr};
216 $runperl .= ' "-I../lib"'; # doublequotes because of VMS
219 if (defined $args{prog}) {
220 if ($is_mswin || $is_netware || $is_vms) {
221 $runperl .= qq( -e ") . $args{prog} . qq(");
224 $runperl .= qq( -e ') . $args{prog} . qq(');
226 } elsif (defined $args{progfile}) {
227 $runperl .= qq( "$args{progfile}");
229 if (defined $args{stdin}) {
230 # so we don't try to put literal newlines and crs onto the
232 $args{stdin} =~ s/\n/\\n/g;
233 $args{stdin} =~ s/\r/\\r/g;
235 if ($is_mswin || $is_netware || $is_vms) {
236 $runperl = qq{$^X -e "print qq(} .
237 $args{stdin} . q{)" | } . $runperl;
240 $runperl = qq{$^X -e 'print qq(} .
241 $args{stdin} . q{)' | } . $runperl;
244 if (defined $args{args}) {
245 _quote_args(\$runperl, $args{args});
247 $runperl .= ' 2>&1' if $args{stderr} && !$is_macos;
248 $runperl .= " \xB3 Dev:Null" if !$args{stderr} && $is_macos;
249 if ($args{verbose}) {
250 my $runperldisplay = $runperl;
251 $runperldisplay =~ s/\n/\n\#/g;
252 print STDOUT "# $runperldisplay\n";
254 my $result = `$runperl`;
255 $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
261 print STDOUT "Bail out! @_\n";