Skip to content

Commit

Permalink
Remove use of indirect object notation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simbabque committed Apr 15, 2017
1 parent 493a81c commit b468a9d
Show file tree
Hide file tree
Showing 47 changed files with 222 additions and 184 deletions.
48 changes: 26 additions & 22 deletions tests/001_init.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ require_ok('Convert::Binary::C::Cached');
#===================================================================
# check if we build the right object (4 tests)
#===================================================================
eval { $p = new Convert::Binary::C };
eval { $p = Convert::Binary::C->new };
is($@, '', "create Convert::Binary::C object");
is(ref $p, 'Convert::Binary::C',
"blessed Convert::Binary::C reference");

eval { $p = new Convert::Binary::C::Cached };
eval { $p = Convert::Binary::C::Cached->new };
is($@, '', "create Convert::Binary::C::Cached object");
is(ref $p, 'Convert::Binary::C::Cached',
"blessed Convert::Binary::C::Cached reference");
Expand All @@ -34,12 +34,14 @@ is(ref $p, 'Convert::Binary::C::Cached',
# check initialization during construction (4 tests)
#===================================================================
eval {
$p = new Convert::Binary::C PointerSize => 4,
EnumSize => 4,
IntSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'Both';
$p = Convert::Binary::C->new(
PointerSize => 4,
EnumSize => 4,
IntSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'Both'
);
};
is($@, '', "create Convert::Binary::C object with arguments");
is(ref $p, 'Convert::Binary::C',
Expand All @@ -48,13 +50,15 @@ is(ref $p, 'Convert::Binary::C',
@warn = ();
eval {
local $SIG{__WARN__} = sub { push @warn, $_[0] };
$p = new Convert::Binary::C::Cached Cache => 'tests/cache.cbc',
PointerSize => 4,
EnumSize => 4,
IntSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'Both';
$p = Convert::Binary::C::Cached->new(
Cache => 'tests/cache.cbc',
PointerSize => 4,
EnumSize => 4,
IntSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'Both'
);
};
is($@, '', "create Convert::Binary::C::Cached object with arguments");
is(ref $p, 'Convert::Binary::C::Cached',
Expand All @@ -76,38 +80,38 @@ else { pass('warnings') }
# check unknown options in constructor (2 tests)
#===================================================================
eval {
$p = new Convert::Binary::C FOO => 123, ByteOrder => 'BigEndian', BAR => ['abc'];
$p = Convert::Binary::C->new( FOO => 123, ByteOrder => 'BigEndian', BAR => ['abc'] );
};
like($@, qr/Invalid option 'FOO' at \Q$0/);

eval {
$p = new Convert::Binary::C::Cached FOO => 123, ByteOrder => 'BigEndian', BAR => ['abc'];
$p = Convert::Binary::C::Cached->new( FOO => 123, ByteOrder => 'BigEndian', BAR => ['abc'] );
};
like($@, qr/Invalid option 'FOO' at \Q$0/);

#===================================================================
# check invalid construction (2 tests)
#===================================================================
eval {
$p = new Convert::Binary::C FOO;
$p = Convert::Binary::C->new( FOO );
};
like($@, qr/Number of configuration arguments to new must be even at \Q$0/);

eval {
$p = new Convert::Binary::C::Cached FOO;
$p = Convert::Binary::C::Cached->new( FOO );
};
like($@, qr/Number of configuration arguments to new must be even at \Q$0/);

#===================================================================
# check invalid construction (2 tests)
#===================================================================
eval {
$p = new Convert::Binary::C ByteOrder => 'FOO';
$p = Convert::Binary::C->new( ByteOrder => 'FOO' );
};
like($@, qr/ByteOrder must be.*not 'FOO' at \Q$0/);

eval {
$p = new Convert::Binary::C::Cached ByteOrder => 'FOO';
$p = Convert::Binary::C::Cached->new( ByteOrder => 'FOO' );
};
like($@, qr/ByteOrder must be.*not 'FOO' at \Q$0/);

Expand All @@ -124,7 +128,7 @@ ok(not defined $p);
# check calling feature as method (2 tests)
#===================================================================
eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p = $p->feature('debug');
};
is($@, '');
Expand Down
20 changes: 11 additions & 9 deletions tests/101_basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ print "1..211\n";
#===================================================================

eval {
$p = new Convert::Binary::C PointerSize => 4,
EnumSize => 4,
IntSize => 4,
LongSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'String';
$q = new Convert::Binary::C;
$p = Convert::Binary::C->new(
PointerSize => 4,
EnumSize => 4,
IntSize => 4,
LongSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'String'
);
$q = Convert::Binary::C->new;
};
ok($@,'');

Expand Down Expand Up @@ -285,7 +287,7 @@ reccmp( $refres, $result );
# test pack/unpack/sizeof/typeof for basic types
#------------------------------------------------

$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;

@tests = (
['char', $p->CharSize ],
Expand Down
36 changes: 18 additions & 18 deletions tests/201_config.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sub check_config

my $reference = $config->{out} || $config->{in};

eval { $p = new Convert::Binary::C };
eval { $p = Convert::Binary::C->new };
skip($reason, $@, '', "failed to create Convert::Binary::C object");

print "# \$p->configure( $option => $config->{in} )\n";
Expand Down Expand Up @@ -159,7 +159,7 @@ sub check_option_strlist
for my $config ( @tests ) {
@warn = ();

eval { $p = new Convert::Binary::C };
eval { $p = Convert::Binary::C->new };
ok($@, '', "failed to create Convert::Binary::C object");

print "# \$p->configure( $option => $config->{in} )\n";
Expand Down Expand Up @@ -223,7 +223,7 @@ sub check_option_strlist_args {
my $option = shift;
my @warn;
eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->$option( [qw(foo bar)] );
$p->$option( 'include' );
$p->$option( qw(a b c) );
Expand Down Expand Up @@ -433,19 +433,19 @@ check_option_strlist_args( $_ ) for qw( Include
#===================================================================

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->configure( DisabledKeywords => ['void', 'foo', 'const'] );
};
ok( $@, qr/Cannot disable unknown keyword 'foo'.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->DisabledKeywords( 'void', 'foo', 'const' );
};
ok( $@, qr/DisabledKeywords cannot take more than one argument.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->DisabledKeywords( ['auto', 'enum'] );
$p->DisabledKeywords( ['void', 'while', 'register'] );
};
Expand All @@ -458,43 +458,43 @@ ok( "@$kw", "auto enum", 'DisabledKeywords did not preserve configuration' );
#===================================================================

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->configure( KeywordMap => 5 );
};
ok( $@, qr/KeywordMap wants a hash reference.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->configure( KeywordMap => [ __xxx__ => 'foo' ] );
};
ok( $@, qr/KeywordMap wants a hash reference.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->KeywordMap( { '' => 'int' } );
};
ok( $@, qr/Cannot use empty string as a keyword.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->KeywordMap( { '1_d' => 'int' } );
};
ok( $@, qr/Cannot use '1_d' as a keyword.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->KeywordMap( { '_d' => [] } );
};
ok( $@, qr/Cannot use a reference as a keyword.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->KeywordMap( { '_d' => 'foo' } );
};
ok( $@, qr/Cannot use 'foo' as a keyword.*$thisfile/ );

eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->KeywordMap( {'__const' => 'const', '__restrict' => undef} );
$p->KeywordMap( {'__volatile' => 'volatile', '__foo' => 'foo'} );
};
Expand All @@ -512,7 +512,7 @@ ok( "@{[sort keys %$kw]}", "__const __restrict", 'KeywordMap did not preserve co
foreach $config ( @tests )
{
eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->configure( @{$config->{value}} );
};
ok( ($@ eq '' ? SUCCEED : FAIL), $config->{result},
Expand All @@ -524,7 +524,7 @@ foreach $config ( @tests )
# check invalid option
#===================================================================
eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->configure(
Something => 'xxx',
ByteOrder => 'BigEndian',
Expand All @@ -537,7 +537,7 @@ ok( $@, qr/Invalid option 'Something'.*$thisfile/ );
# check invalid method
#===================================================================
eval {
$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;
$p->some_method( 1, 2, 3 );
};
ok( $@, qr/Invalid method some_method called.*$thisfile/ );
Expand Down Expand Up @@ -578,7 +578,7 @@ ok( $@, qr/Invalid method some_method called.*$thisfile/ );
);

eval {
$p = new Convert::Binary::C %config;
$p = Convert::Binary::C->new( %config );
$cfg = $p->configure;
};
ok( $@, '', "failed to retrieve configuration" );
Expand Down Expand Up @@ -625,7 +625,7 @@ ok( compare_config( \%config, $cfg ) );
eval {
local $SIG{__WARN__} = sub { push @warn, shift };

$p = new Convert::Binary::C %config;
$p = Convert::Binary::C->new( %config );

$p->UnsignedChars( 1 )->configure( ShortSize => 4, EnumType => 'Both', EnumSize => 0 )
->Include( ['/usr/local/include'] )->DoubleSize( 8 )
Expand Down
20 changes: 11 additions & 9 deletions tests/202_misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ BEGIN { plan tests => 207 }
#===================================================================

eval {
$p = new Convert::Binary::C PointerSize => 4,
EnumSize => 4,
IntSize => 4,
LongSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'String';
$q = new Convert::Binary::C;
$p = Convert::Binary::C->new(
PointerSize => 4,
EnumSize => 4,
IntSize => 4,
LongSize => 4,
Alignment => 2,
ByteOrder => 'BigEndian',
EnumType => 'String'
);
$q = Convert::Binary::C->new;
};
ok($@,'');

Expand Down Expand Up @@ -255,7 +257,7 @@ reccmp( $refres, $result );
# test pack/unpack/sizeof/typeof for basic types
#------------------------------------------------

$p = new Convert::Binary::C;
$p = Convert::Binary::C->new;

@tests = (
['char', $p->CharSize ],
Expand Down
8 changes: 5 additions & 3 deletions tests/204_enum.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ $^W = 1;
BEGIN { plan tests => 182 }

eval {
$p = new Convert::Binary::C ByteOrder => 'BigEndian',
EnumSize => 4,
EnumType => 'Integer';
$p = Convert::Binary::C->new(
ByteOrder => 'BigEndian',
EnumSize => 4,
EnumType => 'Integer'
);
};
ok($@,'',"failed to create Convert::Binary::C object");

Expand Down
5 changes: 2 additions & 3 deletions tests/205_pack.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ $^W = 1;
BEGIN { plan tests => 275 }

eval {
$p = new Convert::Binary::C ByteOrder => 'BigEndian'
, UnsignedChars => 0
$p = Convert::Binary::C->new( ByteOrder => 'BigEndian', UnsignedChars => 0 );
};
ok($@,'',"failed to create Convert::Binary::C object");

Expand Down Expand Up @@ -431,7 +430,7 @@ ok($packed =~ /^$val.*$/);
{
my @res;

my $c = new Convert::Binary::C;
my $c = Convert::Binary::C->new;
$c->parse(<<ENDC);
typedef unsigned char u;
typedef struct {
Expand Down
Loading

0 comments on commit b468a9d

Please sign in to comment.