seen_eval regex field wasn't getting cloned
[p5sagit/p5-mst-13.2.git] / t / test.pl
1 #
2 # t/test.pl - most of Test::More functionality without the fuss
3
4
5 # NOTE:
6 #
7 # Increment ($x++) has a certain amount of cleverness for things like
8 #
9 #   $x = 'zz';
10 #   $x++; # $x eq 'aaa';
11 #
12 # stands more chance of breaking than just a simple
13 #
14 #   $x = $x + 1
15 #
16 # In this file, we use the latter "Baby Perl" approach, and increment
17 # will be worked over by t/op/inc.t
18
19 $Level = 1;
20 my $test = 1;
21 my $planned;
22 my $noplan;
23
24 $TODO = 0;
25 $NO_ENDING = 0;
26
27 # Use this instead of print to avoid interference while testing globals.
28 sub _print {
29     local($\, $", $,) = (undef, ' ', '');
30     print STDOUT @_;
31 }
32
33 sub _print_stderr {
34     local($\, $", $,) = (undef, ' ', '');
35     print STDERR @_;
36 }
37
38 sub plan {
39     my $n;
40     if (@_ == 1) {
41         $n = shift;
42         if ($n eq 'no_plan') {
43           undef $n;
44           $noplan = 1;
45         }
46     } else {
47         my %plan = @_;
48         $n = $plan{tests};
49     }
50     _print "1..$n\n" unless $noplan;
51     $planned = $n;
52 }
53
54 END {
55     my $ran = $test - 1;
56     if (!$NO_ENDING) {
57         if (defined $planned && $planned != $ran) {
58             _print_stderr
59                 "# Looks like you planned $planned tests but ran $ran.\n";
60         } elsif ($noplan) {
61             _print "1..$ran\n";
62         }
63     }
64 }
65
66 # Use this instead of "print STDERR" when outputing failure diagnostic
67 # messages
68 sub _diag {
69     return unless @_;
70     my @mess = map { /^#/ ? "$_\n" : "# $_\n" }
71                map { split /\n/ } @_;
72     my $func = $TODO ? \&_print : \&_print_stderr;
73     $func->(@mess);
74
75 }
76
77 sub diag {
78     _diag(@_);
79 }
80
81 sub skip_all {
82     if (@_) {
83         _print "1..0 # Skipped: @_\n";
84     } else {
85         _print "1..0\n";
86     }
87     exit(0);
88 }
89
90 sub _ok {
91     my ($pass, $where, $name, @mess) = @_;
92     # Do not try to microoptimize by factoring out the "not ".
93     # VMS will avenge.
94     my $out;
95     if ($name) {
96         # escape out '#' or it will interfere with '# skip' and such
97         $name =~ s/#/\\#/g;
98         $out = $pass ? "ok $test - $name" : "not ok $test - $name";
99     } else {
100         $out = $pass ? "ok $test" : "not ok $test";
101     }
102
103     $out .= " # TODO $TODO" if $TODO;
104     _print "$out\n";
105
106     unless ($pass) {
107         _diag "# Failed $where\n";
108     }
109
110     # Ensure that the message is properly escaped.
111     _diag @mess;
112
113     $test = $test + 1; # don't use ++
114
115     return $pass;
116 }
117
118 sub _where {
119     my @caller = caller($Level);
120     return "at $caller[1] line $caller[2]";
121 }
122
123 # DON'T use this for matches. Use like() instead.
124 sub ok ($@) {
125     my ($pass, $name, @mess) = @_;
126     _ok($pass, _where(), $name, @mess);
127 }
128
129 sub _q {
130     my $x = shift;
131     return 'undef' unless defined $x;
132     my $q = $x;
133     $q =~ s/\\/\\\\/g;
134     $q =~ s/'/\\'/g;
135     return "'$q'";
136 }
137
138 sub _qq {
139     my $x = shift;
140     return defined $x ? '"' . display ($x) . '"' : 'undef';
141 };
142
143 # keys are the codes \n etc map to, values are 2 char strings such as \n
144 my %backslash_escape;
145 foreach my $x (split //, 'nrtfa\\\'"') {
146     $backslash_escape{ord eval "\"\\$x\""} = "\\$x";
147 }
148 # A way to display scalars containing control characters and Unicode.
149 # Trying to avoid setting $_, or relying on local $_ to work.
150 sub display {
151     my @result;
152     foreach my $x (@_) {
153         if (defined $x and not ref $x) {
154             my $y = '';
155             foreach my $c (unpack("U*", $x)) {
156                 if ($c > 255) {
157                     $y .= sprintf "\\x{%x}", $c;
158                 } elsif ($backslash_escape{$c}) {
159                     $y .= $backslash_escape{$c};
160                 } else {
161                     my $z = chr $c; # Maybe we can get away with a literal...
162                     $z = sprintf "\\%03o", $c if $z =~ /[[:^print:]]/;
163                     $y .= $z;
164                 }
165             }
166             $x = $y;
167         }
168         return $x unless wantarray;
169         push @result, $x;
170     }
171     return @result;
172 }
173
174 sub is ($$@) {
175     my ($got, $expected, $name, @mess) = @_;
176
177     my $pass;
178     if( !defined $got || !defined $expected ) {
179         # undef only matches undef
180         $pass = !defined $got && !defined $expected;
181     }
182     else {
183         $pass = $got eq $expected;
184     }
185
186     unless ($pass) {
187         unshift(@mess, "#      got "._q($got)."\n",
188                        "# expected "._q($expected)."\n");
189     }
190     _ok($pass, _where(), $name, @mess);
191 }
192
193 sub isnt ($$@) {
194     my ($got, $isnt, $name, @mess) = @_;
195
196     my $pass;
197     if( !defined $got || !defined $isnt ) {
198         # undef only matches undef
199         $pass = defined $got || defined $isnt;
200     }
201     else {
202         $pass = $got ne $isnt;
203     }
204
205     unless( $pass ) {
206         unshift(@mess, "# it should not be "._q($got)."\n",
207                        "# but it is.\n");
208     }
209     _ok($pass, _where(), $name, @mess);
210 }
211
212 sub cmp_ok ($$$@) {
213     my($got, $type, $expected, $name, @mess) = @_;
214
215     my $pass;
216     {
217         local $^W = 0;
218         local($@,$!);   # don't interfere with $@
219                         # eval() sometimes resets $!
220         $pass = eval "\$got $type \$expected";
221     }
222     unless ($pass) {
223         # It seems Irix long doubles can have 2147483648 and 2147483648
224         # that stringify to the same thing but are acutally numerically
225         # different. Display the numbers if $type isn't a string operator,
226         # and the numbers are stringwise the same.
227         # (all string operators have alphabetic names, so tr/a-z// is true)
228         # This will also show numbers for some uneeded cases, but will
229         # definately be helpful for things such as == and <= that fail
230         if ($got eq $expected and $type !~ tr/a-z//) {
231             unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
232         }
233         unshift(@mess, "#      got "._q($got)."\n",
234                        "# expected $type "._q($expected)."\n");
235     }
236     _ok($pass, _where(), $name, @mess);
237 }
238
239 # Check that $got is within $range of $expected
240 # if $range is 0, then check it's exact
241 # else if $expected is 0, then $range is an absolute value
242 # otherwise $range is a fractional error.
243 # Here $range must be numeric, >= 0
244 # Non numeric ranges might be a useful future extension. (eg %)
245 sub within ($$$@) {
246     my ($got, $expected, $range, $name, @mess) = @_;
247     my $pass;
248     if (!defined $got or !defined $expected or !defined $range) {
249         # This is a fail, but doesn't need extra diagnostics
250     } elsif ($got !~ tr/0-9// or $expected !~ tr/0-9// or $range !~ tr/0-9//) {
251         # This is a fail
252         unshift @mess, "# got, expected and range must be numeric\n";
253     } elsif ($range < 0) {
254         # This is also a fail
255         unshift @mess, "# range must not be negative\n";
256     } elsif ($range == 0) {
257         # Within 0 is ==
258         $pass = $got == $expected;
259     } elsif ($expected == 0) {
260         # If expected is 0, treat range as absolute
261         $pass = ($got <= $range) && ($got >= - $range);
262     } else {
263         my $diff = $got - $expected;
264         $pass = abs ($diff / $expected) < $range;
265     }
266     unless ($pass) {
267         if ($got eq $expected) {
268             unshift @mess, "# $got - $expected = " . ($got - $expected) . "\n";
269         }
270         unshift@mess, "#      got "._q($got)."\n",
271                       "# expected "._q($expected)." (within "._q($range).")\n";
272     }
273     _ok($pass, _where(), $name, @mess);
274 }
275
276 # Note: this isn't quite as fancy as Test::More::like().
277
278 sub like   ($$@) { like_yn (0,@_) }; # 0 for -
279 sub unlike ($$@) { like_yn (1,@_) }; # 1 for un-
280
281 sub like_yn ($$$@) {
282     my ($flip, $got, $expected, $name, @mess) = @_;
283     my $pass;
284     $pass = $got =~ /$expected/ if !$flip;
285     $pass = $got !~ /$expected/ if $flip;
286     unless ($pass) {
287         unshift(@mess, "#      got '$got'\n",
288                 $flip
289                 ? "# expected !~ /$expected/\n" : "# expected /$expected/\n");
290     }
291     local $Level = $Level + 1;
292     _ok($pass, _where(), $name, @mess);
293 }
294
295 sub pass {
296     _ok(1, '', @_);
297 }
298
299 sub fail {
300     _ok(0, _where(), @_);
301 }
302
303 sub curr_test {
304     $test = shift if @_;
305     return $test;
306 }
307
308 sub next_test {
309   my $retval = $test;
310   $test = $test + 1; # don't use ++
311   $retval;
312 }
313
314 # Note: can't pass multipart messages since we try to
315 # be compatible with Test::More::skip().
316 sub skip {
317     my $why = shift;
318     my $n    = @_ ? shift : 1;
319     for (1..$n) {
320         _print "ok $test # skip: $why\n";
321         $test = $test + 1;
322     }
323     local $^W = 0;
324     last SKIP;
325 }
326
327 sub todo_skip {
328     my $why = shift;
329     my $n   = @_ ? shift : 1;
330
331     for (1..$n) {
332         _print "not ok $test # TODO & SKIP: $why\n";
333         $test = $test + 1;
334     }
335     local $^W = 0;
336     last TODO;
337 }
338
339 sub eq_array {
340     my ($ra, $rb) = @_;
341     return 0 unless $#$ra == $#$rb;
342     for my $i (0..$#$ra) {
343         next     if !defined $ra->[$i] && !defined $rb->[$i];
344         return 0 if !defined $ra->[$i];
345         return 0 if !defined $rb->[$i];
346         return 0 unless $ra->[$i] eq $rb->[$i];
347     }
348     return 1;
349 }
350
351 sub eq_hash {
352   my ($orig, $suspect) = @_;
353   my $fail;
354   while (my ($key, $value) = each %$suspect) {
355     # Force a hash recompute if this perl's internals can cache the hash key.
356     $key = "" . $key;
357     if (exists $orig->{$key}) {
358       if ($orig->{$key} ne $value) {
359         _print "# key ", _qq($key), " was ", _qq($orig->{$key}),
360                      " now ", _qq($value), "\n";
361         $fail = 1;
362       }
363     } else {
364       _print "# key ", _qq($key), " is ", _qq($value),
365                    ", not in original.\n";
366       $fail = 1;
367     }
368   }
369   foreach (keys %$orig) {
370     # Force a hash recompute if this perl's internals can cache the hash key.
371     $_ = "" . $_;
372     next if (exists $suspect->{$_});
373     _print "# key ", _qq($_), " was ", _qq($orig->{$_}), " now missing.\n";
374     $fail = 1;
375   }
376   !$fail;
377 }
378
379 sub require_ok ($) {
380     my ($require) = @_;
381     eval <<REQUIRE_OK;
382 require $require;
383 REQUIRE_OK
384     _ok(!$@, _where(), "require $require");
385 }
386
387 sub use_ok ($) {
388     my ($use) = @_;
389     eval <<USE_OK;
390 use $use;
391 USE_OK
392     _ok(!$@, _where(), "use $use");
393 }
394
395 # runperl - Runs a separate perl interpreter.
396 # Arguments :
397 #   switches => [ command-line switches ]
398 #   nolib    => 1 # don't use -I../lib (included by default)
399 #   prog     => one-liner (avoid quotes)
400 #   progs    => [ multi-liner (avoid quotes) ]
401 #   progfile => perl script
402 #   stdin    => string to feed the stdin
403 #   stderr   => redirect stderr to stdout
404 #   args     => [ command-line arguments to the perl program ]
405 #   verbose  => print the command line
406
407 my $is_mswin    = $^O eq 'MSWin32';
408 my $is_netware  = $^O eq 'NetWare';
409 my $is_macos    = $^O eq 'MacOS';
410 my $is_vms      = $^O eq 'VMS';
411 my $is_cygwin   = $^O eq 'cygwin';
412
413 sub _quote_args {
414     my ($runperl, $args) = @_;
415
416     foreach (@$args) {
417         # In VMS protect with doublequotes because otherwise
418         # DCL will lowercase -- unless already doublequoted.
419        $_ = q(").$_.q(") if $is_vms && !/^\"/ && length($_) > 0;
420         $$runperl .= ' ' . $_;
421     }
422 }
423
424 sub _create_runperl { # Create the string to qx in runperl().
425     my %args = @_;
426     my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
427     #- this allows, for example, to set PERL_RUNPERL_DEBUG=/usr/bin/valgrind
428     if ($ENV{PERL_RUNPERL_DEBUG}) {
429         $runperl = "$ENV{PERL_RUNPERL_DEBUG} $runperl";
430     }
431     unless ($args{nolib}) {
432         if ($is_macos) {
433             $runperl .= ' -I::lib';
434             # Use UNIX style error messages instead of MPW style.
435             $runperl .= ' -MMac::err=unix' if $args{stderr};
436         }
437         else {
438             $runperl .= ' "-I../lib"'; # doublequotes because of VMS
439         }
440     }
441     if ($args{switches}) {
442         local $Level = 2;
443         die "test.pl:runperl(): 'switches' must be an ARRAYREF " . _where()
444             unless ref $args{switches} eq "ARRAY";
445         _quote_args(\$runperl, $args{switches});
446     }
447     if (defined $args{prog}) {
448         die "test.pl:runperl(): both 'prog' and 'progs' cannot be used " . _where()
449             if defined $args{progs};
450         $args{progs} = [$args{prog}]
451     }
452     if (defined $args{progs}) {
453         die "test.pl:runperl(): 'progs' must be an ARRAYREF " . _where()
454             unless ref $args{progs} eq "ARRAY";
455         foreach my $prog (@{$args{progs}}) {
456             if ($is_mswin || $is_netware || $is_vms) {
457                 $runperl .= qq ( -e "$prog" );
458             }
459             else {
460                 $runperl .= qq ( -e '$prog' );
461             }
462         }
463     } elsif (defined $args{progfile}) {
464         $runperl .= qq( "$args{progfile}");
465     } else {
466         # You probaby didn't want to be sucking in from the upstream stdin
467         die "test.pl:runperl(): none of prog, progs, progfile, args, "
468             . " switches or stdin specified"
469             unless defined $args{args} or defined $args{switches}
470                 or defined $args{stdin};
471     }
472     if (defined $args{stdin}) {
473         # so we don't try to put literal newlines and crs onto the
474         # command line.
475         $args{stdin} =~ s/\n/\\n/g;
476         $args{stdin} =~ s/\r/\\r/g;
477
478         if ($is_mswin || $is_netware || $is_vms) {
479             $runperl = qq{$^X -e "print qq(} .
480                 $args{stdin} . q{)" | } . $runperl;
481         }
482         elsif ($is_macos) {
483             # MacOS can only do two processes under MPW at once;
484             # the test itself is one; we can't do two more, so
485             # write to temp file
486             my $stdin = qq{$^X -e 'print qq(} . $args{stdin} . qq{)' > teststdin; };
487             if ($args{verbose}) {
488                 my $stdindisplay = $stdin;
489                 $stdindisplay =~ s/\n/\n\#/g;
490                 _print_stderr "# $stdindisplay\n";
491             }
492             `$stdin`;
493             $runperl .= q{ < teststdin };
494         }
495         else {
496             $runperl = qq{$^X -e 'print qq(} .
497                 $args{stdin} . q{)' | } . $runperl;
498         }
499     }
500     if (defined $args{args}) {
501         _quote_args(\$runperl, $args{args});
502     }
503     $runperl .= ' 2>&1'          if  $args{stderr} && !$is_macos;
504     $runperl .= " \xB3 Dev:Null" if !$args{stderr} &&  $is_macos;
505     if ($args{verbose}) {
506         my $runperldisplay = $runperl;
507         $runperldisplay =~ s/\n/\n\#/g;
508         _print_stderr "# $runperldisplay\n";
509     }
510     return $runperl;
511 }
512
513 sub runperl {
514     die "test.pl:runperl() does not take a hashref"
515         if ref $_[0] and ref $_[0] eq 'HASH';
516     my $runperl = &_create_runperl;
517     my $result;
518
519     my $tainted = ${^TAINT};
520     my %args = @_;
521     exists $args{switches} && grep m/^-T$/, @{$args{switches}} and $tainted = $tainted + 1;
522
523     if ($tainted) {
524         # We will assume that if you're running under -T, you really mean to
525         # run a fresh perl, so we'll brute force launder everything for you
526         my $sep;
527
528         eval "require Config; Config->import";
529         if ($@) {
530             warn "test.pl had problems loading Config: $@";
531             $sep = ':';
532         } else {
533             $sep = $Config{path_sep};
534         }
535
536         my @keys = grep {exists $ENV{$_}} qw(CDPATH IFS ENV BASH_ENV);
537         local @ENV{@keys} = ();
538         # Untaint, plus take out . and empty string:
539         local $ENV{'DCL$PATH'} = $1 if $is_vms && ($ENV{'DCL$PATH'} =~ /(.*)/s);
540         $ENV{PATH} =~ /(.*)/s;
541         local $ENV{PATH} =
542             join $sep, grep { $_ ne "" and $_ ne "." and -d $_ and
543                 ($is_mswin or $is_vms or !(stat && (stat _)[2]&0022)) }
544                     split quotemeta ($sep), $1;
545         $ENV{PATH} .= "$sep/bin" if $is_cygwin;  # Must have /bin under Cygwin
546
547         $runperl =~ /(.*)/s;
548         $runperl = $1;
549
550         $result = `$runperl`;
551     } else {
552         $result = `$runperl`;
553     }
554     $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these
555     return $result;
556 }
557
558 *run_perl = \&runperl; # Nice alias.
559
560 sub DIE {
561     _print_stderr "# @_\n";
562     exit 1;
563 }
564
565 # A somewhat safer version of the sometimes wrong $^X.
566 my $Perl;
567 sub which_perl {
568     unless (defined $Perl) {
569         $Perl = $^X;
570
571         # VMS should have 'perl' aliased properly
572         return $Perl if $^O eq 'VMS';
573
574         my $exe;
575         eval "require Config; Config->import";
576         if ($@) {
577             warn "test.pl had problems loading Config: $@";
578             $exe = '';
579         } else {
580             $exe = $Config{_exe};
581         }
582        $exe = '' unless defined $exe;
583
584         # This doesn't absolutize the path: beware of future chdirs().
585         # We could do File::Spec->abs2rel() but that does getcwd()s,
586         # which is a bit heavyweight to do here.
587
588         if ($Perl =~ /^perl\Q$exe\E$/i) {
589             my $perl = "perl$exe";
590             eval "require File::Spec";
591             if ($@) {
592                 warn "test.pl had problems loading File::Spec: $@";
593                 $Perl = "./$perl";
594             } else {
595                 $Perl = File::Spec->catfile(File::Spec->curdir(), $perl);
596             }
597         }
598
599         # Build up the name of the executable file from the name of
600         # the command.
601
602         if ($Perl !~ /\Q$exe\E$/i) {
603             $Perl .= $exe;
604         }
605
606         warn "which_perl: cannot find $Perl from $^X" unless -f $Perl;
607
608         # For subcommands to use.
609         $ENV{PERLEXE} = $Perl;
610     }
611     return $Perl;
612 }
613
614 sub unlink_all {
615     foreach my $file (@_) {
616         1 while unlink $file;
617         _print_stderr "# Couldn't unlink '$file': $!\n" if -f $file;
618     }
619 }
620
621
622 my $tmpfile = "misctmp000";
623 1 while -f ++$tmpfile;
624 END { unlink_all $tmpfile }
625
626 #
627 # _fresh_perl
628 #
629 # The $resolve must be a subref that tests the first argument
630 # for success, or returns the definition of success (e.g. the
631 # expected scalar) if given no arguments.
632 #
633
634 sub _fresh_perl {
635     my($prog, $resolve, $runperl_args, $name) = @_;
636
637     $runperl_args ||= {};
638     $runperl_args->{progfile} = $tmpfile;
639     $runperl_args->{stderr} = 1;
640
641     open TEST, ">$tmpfile" or die "Cannot open $tmpfile: $!";
642
643     # VMS adjustments
644     if( $^O eq 'VMS' ) {
645         $prog =~ s#/dev/null#NL:#;
646
647         # VMS file locking
648         $prog =~ s{if \(-e _ and -f _ and -r _\)}
649                   {if (-e _ and -f _)}
650     }
651
652     print TEST $prog;
653     close TEST or die "Cannot close $tmpfile: $!";
654
655     my $results = runperl(%$runperl_args);
656     my $status = $?;
657
658     # Clean up the results into something a bit more predictable.
659     $results =~ s/\n+$//;
660     $results =~ s/at\s+misctmp\d+\s+line/at - line/g;
661     $results =~ s/of\s+misctmp\d+\s+aborted/of - aborted/g;
662
663     # bison says 'parse error' instead of 'syntax error',
664     # various yaccs may or may not capitalize 'syntax'.
665     $results =~ s/^(syntax|parse) error/syntax error/mig;
666
667     if ($^O eq 'VMS') {
668         # some tests will trigger VMS messages that won't be expected
669         $results =~ s/\n?%[A-Z]+-[SIWEF]-[A-Z]+,.*//;
670
671         # pipes double these sometimes
672         $results =~ s/\n\n/\n/g;
673     }
674
675     my $pass = $resolve->($results);
676     unless ($pass) {
677         _diag "# PROG: \n$prog\n";
678         _diag "# EXPECTED:\n", $resolve->(), "\n";
679         _diag "# GOT:\n$results\n";
680         _diag "# STATUS: $status\n";
681     }
682
683     # Use the first line of the program as a name if none was given
684     unless( $name ) {
685         ($first_line, $name) = $prog =~ /^((.{1,50}).*)/;
686         $name .= '...' if length $first_line > length $name;
687     }
688
689     _ok($pass, _where(), "fresh_perl - $name");
690 }
691
692 #
693 # fresh_perl_is
694 #
695 # Combination of run_perl() and is().
696 #
697
698 sub fresh_perl_is {
699     my($prog, $expected, $runperl_args, $name) = @_;
700     local $Level = 2;
701     _fresh_perl($prog,
702                 sub { @_ ? $_[0] eq $expected : $expected },
703                 $runperl_args, $name);
704 }
705
706 #
707 # fresh_perl_like
708 #
709 # Combination of run_perl() and like().
710 #
711
712 sub fresh_perl_like {
713     my($prog, $expected, $runperl_args, $name) = @_;
714     local $Level = 2;
715     _fresh_perl($prog,
716                 sub { @_ ?
717                           $_[0] =~ (ref $expected ? $expected : /$expected/) :
718                           $expected },
719                 $runperl_args, $name);
720 }
721
722 sub can_ok ($@) {
723     my($proto, @methods) = @_;
724     my $class = ref $proto || $proto;
725
726     unless( @methods ) {
727         return _ok( 0, _where(), "$class->can(...)" );
728     }
729
730     my @nok = ();
731     foreach my $method (@methods) {
732         local($!, $@);  # don't interfere with caller's $@
733                         # eval sometimes resets $!
734         eval { $proto->can($method) } || push @nok, $method;
735     }
736
737     my $name;
738     $name = @methods == 1 ? "$class->can('$methods[0]')"
739                           : "$class->can(...)";
740
741     _ok( !@nok, _where(), $name );
742 }
743
744 sub isa_ok ($$;$) {
745     my($object, $class, $obj_name) = @_;
746
747     my $diag;
748     $obj_name = 'The object' unless defined $obj_name;
749     my $name = "$obj_name isa $class";
750     if( !defined $object ) {
751         $diag = "$obj_name isn't defined";
752     }
753     elsif( !ref $object ) {
754         $diag = "$obj_name isn't a reference";
755     }
756     else {
757         # We can't use UNIVERSAL::isa because we want to honor isa() overrides
758         local($@, $!);  # eval sometimes resets $!
759         my $rslt = eval { $object->isa($class) };
760         if( $@ ) {
761             if( $@ =~ /^Can't call method "isa" on unblessed reference/ ) {
762                 if( !UNIVERSAL::isa($object, $class) ) {
763                     my $ref = ref $object;
764                     $diag = "$obj_name isn't a '$class' it's a '$ref'";
765                 }
766             } else {
767                 die <<WHOA;
768 WHOA! I tried to call ->isa on your object and got some weird error.
769 This should never happen.  Please contact the author immediately.
770 Here's the error.
771 $@
772 WHOA
773             }
774         }
775         elsif( !$rslt ) {
776             my $ref = ref $object;
777             $diag = "$obj_name isn't a '$class' it's a '$ref'";
778         }
779     }
780
781     _ok( !$diag, _where(), $name );
782 }
783
784 1;