2 # t/test.pl - most of Test::More functionality without the fuss
24 if (defined $planned && $planned != $ran) {
25 print "# Looks like you planned $planned tests but ran $ran.\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;
53 print "# Failed $where\n";
56 # Ensure that the message is properly escaped.
57 print 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(), @_);
134 # Note: can't pass multipart messages since we try to
135 # be compatible with Test::More::skip().
138 my $n = @_ ? shift : 1;
140 print "ok $test # skip: $why\n";
149 return 0 unless $#$ra == $#$rb;
150 for my $i (0..$#$ra) {
151 return 0 unless $ra->[$i] eq $rb->[$i];
161 _ok(!$@, _where(), "require $require");
169 _ok(!$@, _where(), "use $use");
172 # runperl - Runs a separate perl interpreter.
174 # switches => [ command-line switches ]
175 # nolib => 1 # don't use -I../lib (included by default)
176 # prog => one-liner (avoid quotes)
177 # progfile => perl script
178 # stdin => string to feed the stdin
179 # stderr => redirect stderr to stdout
180 # args => [ command-line arguments to the perl program ]
181 # verbose => print the command line
183 my $is_mswin = $^O eq 'MSWin32';
184 my $is_netware = $^O eq 'NetWare';
185 my $is_macos = $^O eq 'MacOS';
186 my $is_vms = $^O eq 'VMS';
189 my ($runperl, $args) = @_;
192 # In VMS protect with doublequotes because otherwise
193 # DCL will lowercase -- unless already doublequoted.
194 $_ = q(").$_.q(") if $is_vms && !/^\"/;
195 $$runperl .= ' ' . $_;
202 if (defined $args{switches}) {
203 _quote_args(\$runperl, $args{switches});
205 unless (defined $args{nolib}) {
206 if ($is_macos && $args{stderr}) {
207 $runperl .= ' -I::lib';
208 # Use UNIX style error message instead of MPW style.
209 $runperl .= ' -MMac::err=unix' if $args{stderr};
212 $runperl .= ' "-I../lib"'; # doublequotes because of VMS
215 if (defined $args{prog}) {
216 if ($is_mswin || $is_netware || $is_vms) {
217 $runperl .= qq( -e ") . $args{prog} . qq(");
220 $runperl .= qq( -e ') . $args{prog} . qq(');
222 } elsif (defined $args{progfile}) {
223 $runperl .= qq( "$args{progfile}");
225 if (defined $args{stdin}) {
226 if ($is_mswin || $is_netware || $is_vms) {
227 $runperl = qq{$^X -e "print q(} .
228 $args{stdin} . q{)" | } . $runperl;
231 $runperl = qq{$^X -e 'print q(} .
232 $args{stdin} . q{)' | } . $runperl;
235 if (defined $args{args}) {
236 _quote_args(\$runperl, $args{args});
238 $runperl .= ' 2>&1' if $args{stderr} && !$is_macos;
239 $runperl .= " \xB3 Dev:Null" if !$args{stderr} && $is_macos;
240 if ($args{verbose}) {
241 my $runperldisplay = $runperl;
242 $runperldisplay =~ s/\n/\n\#/g;
243 print "# $runperldisplay\n";
245 my $result = `$runperl`;
246 $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these