X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Ftest.pl;h=4e00816bf7c94fd757a392abf3a7d4b08ea41ade;hb=ee94f8101362ee382e42ec2d404d79b0ab7d17ef;hp=36a12c32f9502dfb3d52ad77267f0d118b56b04c;hpb=09f0478617a12d0babd95fd09c4e7bd5bca68b5b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/test.pl b/t/test.pl index 36a12c3..4e00816 100644 --- a/t/test.pl +++ b/t/test.pl @@ -101,8 +101,8 @@ sub _q { my $x = shift; return 'undef' unless defined $x; my $q = $x; - $q =~ s/\\/\\\\/; - $q =~ s/'/\\'/; + $q =~ s/\\/\\\\/g; + $q =~ s/'/\\'/g; return "'$q'"; } @@ -258,6 +258,7 @@ sub like_yn ($$$@) { unshift(@mess, "# got '$got'\n", "# expected /$expected/\n"); } + local $Level = 2; _ok($pass, _where(), $name, @mess); } @@ -296,7 +297,7 @@ sub todo_skip { my $n = @_ ? shift : 1; for (1..$n) { - print STDOUT "ok $test # TODO & SKIP: $why\n"; + print STDOUT "not ok $test # TODO & SKIP: $why\n"; $test++; } local $^W = 0; @@ -390,6 +391,10 @@ sub _quote_args { sub _create_runperl { # Create the string to qx in runperl(). my %args = @_; my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X; + #- this allows, for example, to set PERL_RUNPERL_DEBUG=/usr/bin/valgrind + if ($ENV{PERL_RUNPERL_DEBUG}) { + $runperl = "$ENV{PERL_RUNPERL_DEBUG} $runperl"; + } unless ($args{nolib}) { if ($is_macos) { $runperl .= ' -I::lib'; @@ -476,6 +481,15 @@ sub runperl { die "test.pl:runperl() does not take a hashref" if ref $_[0] and ref $_[0] eq 'HASH'; my $runperl = &_create_runperl; + if (${^TAINT}) { + # We will assume that if you're running under -T, you really mean + # to run a fresh perl, so we'll brute force launder everything for + # you + foreach ($runperl, $ENV{PATH}) { + $_ =~ /(.*)/s; + $_ = $1; + } + } my $result = `$runperl`; $result =~ s/\n\n/\n/ if $is_vms; # XXX pipes sometimes double these return $result; @@ -575,7 +589,7 @@ sub _fresh_perl { {if (-e _ and -f _)} } - print TEST $prog, "\n"; + print TEST $prog; close TEST or die "Cannot close $tmpfile: $!"; my $results = runperl(%$runperl_args); @@ -645,4 +659,66 @@ sub fresh_perl_like { $runperl_args, $name); } +sub can_ok ($@) { + my($proto, @methods) = @_; + my $class = ref $proto || $proto; + + unless( @methods ) { + return _ok( 0, _where(), "$class->can(...)" ); + } + + my @nok = (); + foreach my $method (@methods) { + local($!, $@); # don't interfere with caller's $@ + # eval sometimes resets $! + eval { $proto->can($method) } || push @nok, $method; + } + + my $name; + $name = @methods == 1 ? "$class->can('$methods[0]')" + : "$class->can(...)"; + + _ok( !@nok, _where(), $name ); +} + +sub isa_ok ($$;$) { + my($object, $class, $obj_name) = @_; + + my $diag; + $obj_name = 'The object' unless defined $obj_name; + my $name = "$obj_name isa $class"; + if( !defined $object ) { + $diag = "$obj_name isn't defined"; + } + elsif( !ref $object ) { + $diag = "$obj_name isn't a reference"; + } + else { + # We can't use UNIVERSAL::isa because we want to honor isa() overrides + local($@, $!); # eval sometimes resets $! + my $rslt = eval { $object->isa($class) }; + if( $@ ) { + if( $@ =~ /^Can't call method "isa" on unblessed reference/ ) { + if( !UNIVERSAL::isa($object, $class) ) { + my $ref = ref $object; + $diag = "$obj_name isn't a '$class' it's a '$ref'"; + } + } else { + die <isa on your object and got some weird error. +This should never happen. Please contact the author immediately. +Here's the error. +$@ +WHOA + } + } + elsif( !$rslt ) { + my $ref = ref $object; + $diag = "$obj_name isn't a '$class' it's a '$ref'"; + } + } + + _ok( !$diag, _where(), $name ); +} + 1;