#!/usr/bin/perl -w BEGIN { if( $ENV{PERL_CORE} ) { chdir 't'; @INC = ('../lib', 'lib'); } else { unshift @INC, 't/lib'; } } use strict; use Test::More tests => 19; package Overloaded; use overload q{eq} => sub { $_[0]->{string} eq $_[1] }, q{==} => sub { $_[0]->{num} == $_[1] }, q{""} => sub { $_[0]->{stringify}++; $_[0]->{string} }, q{0+} => sub { $_[0]->{numify}++; $_[0]->{num} } ; sub new { my $class = shift; bless { string => shift, num => shift, stringify => 0, numify => 0, }, $class; } package main; local $SIG{__DIE__} = sub { my($call_file, $call_line) = (caller)[1,2]; fail("SIGDIE accidentally called"); diag("From $call_file at $call_line"); }; my $obj = Overloaded->new('foo', 42); isa_ok $obj, 'Overloaded'; cmp_ok $obj, 'eq', 'foo', 'cmp_ok() eq'; is $obj->{stringify}, 0, ' does not stringify'; is $obj, 'foo', 'is() with string overloading'; cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading'; is $obj->{numify}, 0, ' does not numify'; is_deeply [$obj], ['foo'], 'is_deeply with string overloading'; ok eq_array([$obj], ['foo']), 'eq_array ...'; ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...'; # rt.cpan.org 13506 is_deeply $obj, 'foo', 'is_deeply with string overloading at the top'; Test::More->builder->is_num($obj, 42); Test::More->builder->is_eq ($obj, "foo"); { # rt.cpan.org 14675 package TestPackage; use overload q{""} => sub { ::fail("This should not be called") }; package Foo; ::is_deeply(['TestPackage'], ['TestPackage']); ::is_deeply({'TestPackage' => 'TestPackage'}, {'TestPackage' => 'TestPackage'}); ::is_deeply('TestPackage', 'TestPackage'); } # Make sure 0 isn't a special case. [rt.cpan.org 41109] { my $obj = Overloaded->new('0', 42); isa_ok $obj, 'Overloaded'; cmp_ok $obj, 'eq', '0', 'cmp_ok() eq'; is $obj->{stringify}, 0, ' does not stringify'; is $obj, '0', 'is() with string overloading'; }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Builder | Folder | 0755 |
|
|
Simple | Folder | 0755 |
|
|
Tester | Folder | 0755 |
|
|
lib | Folder | 0755 |
|
|
subtest | Folder | 0755 |
|
|
00compile.t | File | 982 B | 0644 |
|
00test_harness_check.t | File | 764 B | 0644 |
|
BEGIN_require_ok.t | File | 463 B | 0644 |
|
BEGIN_use_ok.t | File | 388 B | 0644 |
|
More.t | File | 5.1 KB | 0644 |
|
bad_plan.t | File | 495 B | 0644 |
|
bail_out.t | File | 660 B | 0644 |
|
buffer.t | File | 424 B | 0644 |
|
c_flag.t | File | 417 B | 0644 |
|
circular_data.t | File | 1.17 KB | 0644 |
|
cmp_ok.t | File | 1.54 KB | 0644 |
|
dependents.t | File | 939 B | 0644 |
|
diag.t | File | 1.4 KB | 0644 |
|
died.t | File | 848 B | 0644 |
|
dont_overwrite_die_handler.t | File | 353 B | 0644 |
|
eq_set.t | File | 562 B | 0644 |
|
exit.t | File | 2.98 KB | 0644 |
|
explain.t | File | 582 B | 0644 |
|
extra.t | File | 958 B | 0644 |
|
extra_one.t | File | 869 B | 0644 |
|
fail-like.t | File | 1.52 KB | 0644 |
|
fail-more.t | File | 10.37 KB | 0644 |
|
fail.t | File | 1.04 KB | 0644 |
|
fail_one.t | File | 697 B | 0644 |
|
filehandles.t | File | 290 B | 0644 |
|
fork.t | File | 574 B | 0644 |
|
harness_active.t | File | 1.35 KB | 0644 |
|
import.t | File | 244 B | 0644 |
|
is_deeply_dne_bug.t | File | 887 B | 0644 |
|
is_deeply_fail.t | File | 11.25 KB | 0644 |
|
is_deeply_with_threads.t | File | 1.4 KB | 0644 |
|
missing.t | File | 1.03 KB | 0644 |
|
new_ok.t | File | 705 B | 0644 |
|
no_plan.t | File | 664 B | 0644 |
|
no_tests.t | File | 782 B | 0644 |
|
note.t | File | 416 B | 0644 |
|
overload.t | File | 2.13 KB | 0644 |
|
overload_threads.t | File | 1.04 KB | 0644 |
|
plan.t | File | 474 B | 0644 |
|
plan_bad.t | File | 1.05 KB | 0644 |
|
plan_is_noplan.t | File | 404 B | 0644 |
|
plan_no_plan.t | File | 794 B | 0644 |
|
plan_shouldnt_import.t | File | 294 B | 0644 |
|
plan_skip_all.t | File | 190 B | 0644 |
|
pod-coverage.t | File | 793 B | 0644 |
|
pod.t | File | 149 B | 0644 |
|
require_ok.t | File | 786 B | 0644 |
|
simple.t | File | 200 B | 0644 |
|
skip.t | File | 1.9 KB | 0644 |
|
skipall.t | File | 481 B | 0644 |
|
tbm_doesnt_set_exported_to.t | File | 457 B | 0644 |
|
thread_taint.t | File | 122 B | 0644 |
|
threads.t | File | 629 B | 0644 |
|
todo.t | File | 3.28 KB | 0644 |
|
undef.t | File | 1.84 KB | 0644 |
|
use_ok.t | File | 1.42 KB | 0644 |
|
useing.t | File | 365 B | 0644 |
|
utf8.t | File | 1.25 KB | 0644 |
|
versions.t | File | 482 B | 0644 |
|