Skip to content

Commit

Permalink
convert tests to use right module
Browse files Browse the repository at this point in the history
  • Loading branch information
2shortplanks committed Jun 18, 2013
1 parent 0a38cb8 commit a6c4910
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
12 changes: 6 additions & 6 deletions t/01array.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
print "1..$tests\n";
}
END {print "not ok 1\n" unless $loaded;}
use Clone qw( clone );
use Clone::AsUTF8Bytes qw( clone_as_utf8_bytes );
$loaded = 1;
print "ok 1\n";

Expand All @@ -33,7 +33,7 @@ package Test::Array;

use vars @ISA;

@ISA = qw(Clone);
@ISA = qw(Clone::AsUTF8Bytes);

sub new
{
Expand All @@ -57,8 +57,8 @@ my $a = Test::Array->new(
],
],
);
my $b = $a->clone(0);
my $c = $a->clone(2);
my $b = $a->clone_as_utf8_bytes(0);
my $c = $a->clone_as_utf8_bytes(2);

# TEST 2
$b->[1][0] eq 'two' ? ok : not_ok;
Expand All @@ -74,7 +74,7 @@ $c->[1][1][1] == $a->[1][1][1] ? ok : not_ok;

my @circ = ();
$circ[0] = \@circ;
$aref = clone(\@circ);
$aref = clone_as_utf8_bytes(\@circ);

if ($has_data_dumper) {
Dumper(\@circ) eq Dumper($aref) ? ok : not_ok;
Expand All @@ -83,6 +83,6 @@ if ($has_data_dumper) {
# test for unicode support
{
my $a = [ chr(256) => 1 ];
my $b = clone( $a );
my $b = clone_as_utf8_bytes( $a );
ord( $a->[0] ) == ord( $b->[0] ) ? ok : not_ok;
}
12 changes: 6 additions & 6 deletions t/02hash.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
print "1..$tests\n";
}
END {print "not ok 1\n" unless $loaded;}
use Clone qw( clone );
use Clone::AsUTF8Bytes qw( clone_as_utf8_bytes );
$loaded = 1;
print "ok 1\n";

Expand All @@ -33,7 +33,7 @@ package Test::Hash;

use vars @ISA;

@ISA = qw(Clone);
@ISA = qw(Clone::AsUTF8Bytes);

sub new
{
Expand Down Expand Up @@ -71,8 +71,8 @@ my $a = Test::Hash->new(

$a->{a} = $a;

my $b = $a->clone(0);
my $c = $a->clone(3);
my $b = $a->clone_as_utf8_bytes(0);
my $c = $a->clone_as_utf8_bytes(3);

$a->{level} == $b->{level} ? ok : not_ok;

Expand All @@ -90,14 +90,14 @@ $c->{href}{href}{href} == $a->{href}{href}{href} ? ok : not_ok;

my %circ = ();
$circ{c} = \%circ;
my $cref = clone(\%circ);
my $cref = clone_as_utf8_bytes(\%circ);
if ($has_data_dumper) {
Dumper(\%circ) eq Dumper($cref) ? ok : not_ok;
}

# test for unicode support
{
my $a = { chr(256) => 1 };
my $b = clone( $a );
my $b = clone_as_utf8_bytes( $a );
ord( (keys(%$a))[0] ) == ord( (keys(%$b))[0] ) ? ok : not_ok;
}
18 changes: 9 additions & 9 deletions t/03scalar.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
print "1..$tests\n";
}
END {print "not ok 1\n" unless $loaded;}
use Clone qw( clone );
use Clone::AsUTF8Bytes qw( clone_as_utf8_bytes );
$loaded = 1;
print "ok 1\n";

Expand All @@ -33,7 +33,7 @@ package Test::Scalar;

use vars @ISA;

@ISA = qw(Clone);
@ISA = qw(Clone::AsUTF8Bytes);

sub new
{
Expand All @@ -49,47 +49,47 @@ sub DESTROY
}

package main;

sub ok { print "ok $test\n"; $test++ }
sub not_ok { print "not ok $test\n"; $test++ }

$^W = 0;
$test = 2;

my $a = Test::Scalar->new(1.0);
my $b = $a->clone(1);
my $b = $a->clone_as_utf8_bytes(1);

$$a == $$b ? ok : not_ok;
$a != $b ? ok : not_ok;

my $c = \"test 2 scalar";
my $d = Clone::clone($c, 2);
my $d = Clone::AsUTF8Bytes::clone_as_utf8_bytes($c, 2);

$$c == $$d ? ok : not_ok;
$c != $d ? ok : not_ok;

my $circ = undef;
$circ = \$circ;
$aref = clone($circ);
$aref = clone_as_utf8_bytes($circ);
if ($has_data_dumper) {
Dumper($circ) eq Dumper($aref) ? ok : not_ok;
}

# the following used to produce a segfault, rt.cpan.org id=2264
undef $a;
$b = clone($a);
$b = clone_as_utf8_bytes($a);
$$a == $$b ? ok : not_ok;

# used to get a segfault cloning a ref to a qr data type.
my $str = 'abcdefg';
my $qr = qr/$str/;
my $qc = clone( $qr );
my $qc = clone_as_utf8_bytes( $qr );
$qr eq $qc ? ok : not_ok;
$str =~ /$qc/ ? ok : not_ok;

# test for unicode support
{
my $a = \( chr(256) );
my $b = clone( $a );
my $b = clone_as_utf8_bytes( $a );
ord($$a) == ord($$b) ? ok : not_ok;
}
4 changes: 2 additions & 2 deletions t/04tie.t
Expand Up @@ -9,7 +9,7 @@

BEGIN { $| = 1; print "1..5\n"; }
END {print "not ok 1\n" unless $loaded;}
use Clone qw( clone );
use Clone::AsUTF8Bytes qw( clone_as_utf8_bytes );
$loaded = 1;
print "ok 1\n";

Expand All @@ -29,7 +29,7 @@ $a{b} = 1;

my $b = [\%a, \@a, \$a];

my $c = clone($b);
my $c = clone_as_utf8_bytes($b);

my $d1 = &dump($b);
my $d2 = &dump($c);
Expand Down
6 changes: 3 additions & 3 deletions t/05dtype.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
print "1..$tests\n";
}
END {print "not ok 1\n" unless $loaded;}
use Clone;
use Clone::AsUTF8Bytes;
$loaded = 1;
print "ok 1\n";

Expand Down Expand Up @@ -47,7 +47,7 @@ use strict;

package Test::Hash;

@Test::Hash::ISA = qw( Clone );
@Test::Hash::ISA = qw( Clone::AsUTF8Bytes );

sub new()
{
Expand All @@ -64,7 +64,7 @@ my ($master, $clone1);

my $a = Test::Hash->new();

my $b = $a->clone;
my $b = $a->clone_as_utf8_bytes;
my $c = dclone($a);

if ($has_data_dumper) {
Expand Down
24 changes: 12 additions & 12 deletions t/06refcnt.t
Expand Up @@ -25,7 +25,7 @@ BEGIN {
print "1..$plan\n";
}
END {print "not ok 1\n" unless $loaded;}
use Clone qw( clone );
use Clone::AsUTF8Bytes qw( clone_as_utf8_bytes );
$loaded = 1;
print "ok 1\n";

Expand All @@ -39,7 +39,7 @@ print "ok 1\n";

## use Benchmark;
## use Data::Dumper;
# use Storable qw( dclone );
# use Storable qw( dclone_as_utf8_bytes );

$^W = 1;
$test = 2;
Expand All @@ -51,7 +51,7 @@ use strict;

package Test::Hash;

@Test::Hash::ISA = qw( Clone );
@Test::Hash::ISA = qw( Clone::AsUTF8Bytes );

sub new()
{
Expand All @@ -73,29 +73,29 @@ package main;

{
my $a = Test::Hash->new();
my $b = $a->clone;
my $b = $a->clone_as_utf8_bytes;
# my $c = dclone($a);
}

# benchmarking bug
{
my $a = Test::Hash->new();
my $sref = sub { my $b = clone($a) };
my $sref = sub { my $b = clone_as_utf8_bytes($a) };
$sref->();
}

# test for cloning unblessed ref
{
my $a = {};
my $b = clone($a);
my $b = clone_as_utf8_bytes($a);
bless $a, 'Test::Hash';
bless $b, 'Test::Hash';
}

# test for cloning unblessed ref
{
my $a = [];
my $b = clone($a);
my $b = clone_as_utf8_bytes($a);
bless $a, 'Test::Hash';
bless $b, 'Test::Hash';
}
Expand All @@ -104,7 +104,7 @@ package main;
{
my $a = 1;
$a = [];
my $b = clone($a);
my $b = clone_as_utf8_bytes($a);
bless $a, 'Test::Hash';
bless $b, 'Test::Hash';
}
Expand All @@ -113,7 +113,7 @@ package main;
{
my $a = '';
$a = [];
my $b = clone($a);
my $b = clone_as_utf8_bytes($a);
bless $a, 'Test::Hash';
bless $b, 'Test::Hash';
}
Expand All @@ -122,7 +122,7 @@ package main;
{
my $a = *STDOUT;
$a = [];
my $b = clone($a);
my $b = clone_as_utf8_bytes($a);
bless $a, 'Test::Hash';
bless $b, 'Test::Hash';
}
Expand All @@ -134,7 +134,7 @@ if ( $HAS_WEAKEN ) {
my $b = { r => $a };
$a->{r} = $b;
weaken($b->{'r'});
my $c = clone($a);
my $c = clone_as_utf8_bytes($a);
}

# another weak reference problem, this one causes a segfault in 0.24
Expand All @@ -146,7 +146,7 @@ if ( $HAS_WEAKEN ) {
weaken($b->[0]);
weaken($b->[1]);
}
my $c = clone($a);
my $c = clone_as_utf8_bytes($a);
# check that references point to the same thing
print "not " unless $c->{'r'}[0] == $c->{'r'}[1];
printf "ok %d\n", $::test++;
Expand Down
8 changes: 4 additions & 4 deletions t/07magic.t
Expand Up @@ -2,7 +2,7 @@

use strict;

use Clone;
use Clone::AsUTF8Bytes;
use Test::More tests => 3;

SKIP: {
Expand All @@ -16,7 +16,7 @@ SKIP: {
my $x = { a => "worked\n" };
my $y = $x;
weaken($y);
my $z = Clone::clone($x);
my $z = Clone::AsUTF8Bytes::clone_as_utf8_bytes($x);
ok( Dumper($x) eq Dumper($z), "Cloned weak reference");
}

Expand All @@ -33,7 +33,7 @@ SKIP: {
substr ($string, 0, 4),
substr ($string, 4),
);
my $z = Clone::clone($string);
my $z = Clone::AsUTF8Bytes::clone_as_utf8_bytes($string);
ok( Dumper($string) eq Dumper($z), "Cloned magic utf8");
}
}
Expand All @@ -48,7 +48,7 @@ SKIP: {
$x = $ENV{$_};
last if ( $x && length($x) > 0 );
}
my $y = Clone::clone($x);
my $y = Clone::AsUTF8Bytes::clone_as_utf8_bytes($x);
## ok(Clone::clone($tainted), "Tainted input");
ok( Dumper($x) eq Dumper($y), "Tainted input");
}
Expand Down
4 changes: 2 additions & 2 deletions t/08fieldhash.t
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

use Clone 'clone';
use Clone::AsUTF8Bytes 'clone_as_utf8_bytes';

BEGIN {
use Test::More;
Expand All @@ -22,7 +22,7 @@ my $var = {};

exists $hash{ \$var };

my $cloned = clone($var);
my $cloned = clone_as_utf8_bytes($var);
cmp_ok($cloned, '!=', $var);

done_testing;

0 comments on commit a6c4910

Please sign in to comment.