Skip to content

Commit

Permalink
Replace bizarre use of cmp_ok() with is(), which does the same thing
Browse files Browse the repository at this point in the history
and is easier to read.
  • Loading branch information
autarch committed Nov 8, 2008
1 parent 334e01a commit 0080fb9
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 96 deletions.
4 changes: 2 additions & 2 deletions lib/DBD/Mock.pm
Expand Up @@ -1372,15 +1372,15 @@ To do that our test might look like:
# Now query that history record to
# see if our expectations match reality
cmp_ok(scalar(@{$history}), '==', 1, 'Correct number of statements executed' ;
is(scalar(@{$history}), 1, 'Correct number of statements executed' ;
my $login_st = $history->[0];
like($login_st->statement,
qr/SELECT login_name.*FROM users WHERE login_name = ?/sm,
'Correct statement generated' );
my $params = $login_st->bound_params;
cmp_ok(scalar(@{$params}), '==', 1, 'Correct number of parameters bound');
is(scalar(@{$params}), 1, 'Correct number of parameters bound');
is($params->[0], $login_name, 'Correct value for parameter 1' );
# Reset the handle for future operations
Expand Down
28 changes: 14 additions & 14 deletions t/001_db_handle.t
Expand Up @@ -14,25 +14,25 @@ BEGIN {
isa_ok($dbh, 'DBI::db');

is($dbh->{Name}, '', '... if no db-name is given');
cmp_ok( $dbh->{AutoCommit}, '==', 1,
is( $dbh->{AutoCommit}, 1,
'... AutoCommit DB attribute defaults to set' );

# DBI will handle attributes with 'private_', 'dbi_' or ,
# 'dbd_' prefixes but all others, we need to handle.

$dbh->{mysql_insertid} = 10;
cmp_ok($dbh->{mysql_insertid}, '==', 10, '... this attribute should be 10');
is($dbh->{mysql_insertid}, 10, '... this attribute should be 10');

# DBI will handle these

$dbh->{private_insert_id} = 15;
cmp_ok($dbh->{private_insert_id}, '==', 15, '... this attribute should be 15');
is($dbh->{private_insert_id}, 15, '... this attribute should be 15');

$dbh->{dbi_attribute} = 2000;
cmp_ok($dbh->{dbi_attribute}, '==', 2000, '... this attribute should be 2000');
is($dbh->{dbi_attribute}, 2000, '... this attribute should be 2000');

$dbh->{dbd_attr} = 15_000;
cmp_ok($dbh->{dbd_attr}, '==', 15_000, '... this attribute should be 15,000');
is($dbh->{dbd_attr}, 15_000, '... this attribute should be 15,000');

$dbh->disconnect();
}
Expand All @@ -46,11 +46,11 @@ BEGIN {
$dbh->{PrintError} = 1;
$dbh->{AutoCommit} = 1;

cmp_ok( $dbh->{RaiseError}, '==', 1,
is( $dbh->{RaiseError}, 1,
'RaiseError DB attribute set after connect()' );
cmp_ok( $dbh->{PrintError}, '==', 1,
is( $dbh->{PrintError}, 1,
'PrintError DB attribute set after connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 1,
is( $dbh->{AutoCommit}, 1,
'AutoCommit DB attribute set after connect()' );

$dbh->disconnect();
Expand All @@ -63,11 +63,11 @@ BEGIN {
{ RaiseError => 1,
PrintError => 1,
AutoCommit => 1 } );
cmp_ok( $dbh->{RaiseError}, '==', 1,
is( $dbh->{RaiseError}, 1,
'RaiseError DB attribute set in connect()' );
cmp_ok( $dbh->{PrintError}, '==', 1,
is( $dbh->{PrintError}, 1,
'PrintError DB attribute set in connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 1,
is( $dbh->{AutoCommit}, 1,
'AutoCommit DB attribute set in connect()' );

$dbh->disconnect();
Expand All @@ -80,11 +80,11 @@ BEGIN {
{ RaiseError => 0,
PrintError => 0,
AutoCommit => 0 } );
cmp_ok( $dbh->{RaiseError}, '==', 0,
is( $dbh->{RaiseError}, 0,
'RaiseError DB attribute unset in connect()' );
cmp_ok( $dbh->{PrintError}, '==', 0,
is( $dbh->{PrintError}, 0,
'PrintError DB attribute unset in connect()' );
cmp_ok( $dbh->{AutoCommit}, '==', 0,
is( $dbh->{AutoCommit}, 0,
'AutoCommit DB attribute unset in connect()' );

$dbh->disconnect();
Expand Down
6 changes: 3 additions & 3 deletions t/002_dr_handle.t
Expand Up @@ -53,15 +53,15 @@ is_deeply(
}

{ # check the mock_connect_fail attribute
cmp_ok($drh->{mock_connect_fail}, '==', 0, '... the default is set not to fail');
is($drh->{mock_connect_fail}, 0, '... the default is set not to fail');

# make sure the this only affects the initial connect
my $_dbh = DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
isa_ok($_dbh, 'DBI::db');

# now no more connections
$drh->{mock_connect_fail} = 1;
cmp_ok($drh->{mock_connect_fail}, '==', 1, '... we are set to fail');
is($drh->{mock_connect_fail}, 1, '... we are set to fail');

eval {
DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
Expand All @@ -76,7 +76,7 @@ is_deeply(
ok(!$@, '... we should not have an exception here');

$drh->{mock_connect_fail} = 0;
cmp_ok($drh->{'mock_connect_fail'}, '==', 0, '... we are set not to fail');
is($drh->{'mock_connect_fail'}, 0, '... we are set not to fail');

my $dbh;
eval {
Expand Down
8 changes: 4 additions & 4 deletions t/003_db_can_connect.t
Expand Up @@ -13,7 +13,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');

# check to see it is active in the first place
ok($dbh->{Active}, '...our handle with the default settting is Active' );
Expand All @@ -22,7 +22,7 @@ BEGIN {
$dbh->{mock_can_connect} = 0;

# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');

# and check the side effects of that
ok(!$dbh->{Active}, '...our handle is no longer Active after setting mock_can_connect');
Expand All @@ -49,7 +49,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');

# check to see it is active in the first place
ok($dbh->{Active}, '...our handle with the default settting is Active' );
Expand All @@ -58,7 +58,7 @@ BEGIN {
$dbh->{mock_can_connect} = 0;

# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');

# and check the side effects of that
ok(!$dbh->{Active}, '...our handle is no longer Active after setting mock_can_connect');
Expand Down
16 changes: 8 additions & 8 deletions t/004_misc_mock_attr.t
Expand Up @@ -13,21 +13,21 @@ my $dbh = DBI->connect('DBI:Mock:', '', '');
isa_ok($dbh, 'DBI::db');

$dbh->{AutoCommit} = 1;
cmp_ok($dbh->{AutoCommit}, '==', 1, '... it handles AutoCommit as well');
is($dbh->{AutoCommit}, 1, '... it handles AutoCommit as well');

$dbh->{AutoCommit} = 0;
cmp_ok($dbh->{AutoCommit}, '==', 0, '... and turns off AutoCommit as well');
is($dbh->{AutoCommit}, 0, '... and turns off AutoCommit as well');

for (0 .. 5) {
my $sth = $dbh->prepare('SELECT * FROM foo');
$sth->execute();
}

cmp_ok(scalar(@{$dbh->{mock_all_history}}), '==', 6, '... we have 6 statements');
is(scalar(@{$dbh->{mock_all_history}}), 6, '... we have 6 statements');

$dbh->{mock_clear_history} = 1;

cmp_ok(scalar(@{$dbh->{mock_all_history}}), '==', 0, '... we have 0 statements');
is(scalar(@{$dbh->{mock_all_history}}), 0, '... we have 0 statements');

# test the misc. attributes of $sth

Expand Down Expand Up @@ -67,10 +67,10 @@ is_deeply(
'... we have 3 records');

# mock_num_records
cmp_ok($sth->{mock_num_records}, '==', 3, '... we have 3 records');
is($sth->{mock_num_records}, 3, '... we have 3 records');

# mock_current_record_num
cmp_ok($sth->{mock_current_record_num}, '==', 0, '... we are at record number 0');
is($sth->{mock_current_record_num}, 0, '... we are at record number 0');

# mock_is_finished
is($sth->{mock_is_finished}, 'no', '... we are not yet finished');
Expand All @@ -79,8 +79,8 @@ is($sth->{mock_is_finished}, 'no', '... we are not yet finished');
ok(!$sth->{mock_is_depleted}, '... nor are we depleted');

for (1 .. 3) {
cmp_ok(($sth->fetchrow_array())[0], '==', $_, '... got the expected row');
cmp_ok($sth->{mock_current_record_num}, '==', $_, '... we are at record number ' . $_);
is(($sth->fetchrow_array())[0], $_, '... got the expected row');
is($sth->{mock_current_record_num}, $_, '... we are at record number ' . $_);
}

# mock_is_depleted
Expand Down
8 changes: 4 additions & 4 deletions t/005_db_parser.t
Expand Up @@ -12,7 +12,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');

# check parse sub-refs

Expand Down Expand Up @@ -57,7 +57,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');

# check parse objects

Expand Down Expand Up @@ -94,7 +94,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{RaiseError}, '==', 1, '... make sure RaiseError is set correctly');
is($dbh->{RaiseError}, 1, '... make sure RaiseError is set correctly');

eval {
$dbh->{mock_add_parser} = "Fail";
Expand All @@ -115,7 +115,7 @@ BEGIN {
isa_ok($dbh, "DBI::db");
# check to be sure this is set, otherwise
# the test wont be set up right
cmp_ok($dbh->{PrintError}, '==', 1, '... make sure PrintError is set correctly');
is($dbh->{PrintError}, 1, '... make sure PrintError is set correctly');

{ # isolate the warn handler
local $SIG{__WARN__} = sub {
Expand Down
8 changes: 4 additions & 4 deletions t/006_prepare_cached.t
Expand Up @@ -14,18 +14,18 @@ foreach my $i ( 1 .. 2 ) {
my $sth = $dbh->prepare('SELECT foo FROM bar WHERE x = ?');
$sth->execute($i);
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', $i, "... have $i statement executions");
is(scalar(@{$history}), $i, "... have $i statement executions");
}

$dbh->{mock_clear_history} = 1;
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', 0, '... the history has been is cleared');
is(scalar(@{$history}), 0, '... the history has been is cleared');

foreach my $i ( 1 .. 2 ) {
my $sth = $dbh->prepare_cached('SELECT foo FROM bar WHERE x = ?');
$sth->execute($i);
my $history = $dbh->{mock_all_history};
cmp_ok(scalar(@{$history}), '==', $i, "... have $i statement executions");
is(scalar(@{$history}), $i, "... have $i statement executions");
}

my $st_track = $dbh->{mock_all_history}->[0];
Expand All @@ -34,4 +34,4 @@ isa_ok($st_track, 'DBD::Mock::StatementTrack');
is($st_track->statement, 'SELECT foo FROM bar WHERE x = ?', '... our statements match');

my $params = $st_track->bound_params;
cmp_ok(scalar(@{$params}), '==', 1, '... got the expected amount of params');
is(scalar(@{$params}), 1, '... got the expected amount of params');
4 changes: 2 additions & 2 deletions t/007_mock_attribute_aliases.t
Expand Up @@ -60,7 +60,7 @@ like($@, qr/Attribute aliases not available for \'Fail\'/, '... got the error we

$sth->execute();

cmp_ok($dbh->{mysql_insertid}, '==', 1, '... our alias works');
is($dbh->{mysql_insertid}, 1, '... our alias works');

}

Expand All @@ -83,6 +83,6 @@ like($@, qr/Attribute aliases not available for \'Fail\'/, '... got the error we

$sth->execute();

cmp_ok($dbh->{mysql_insertid}, '==', 1, '... our alias works');
is($dbh->{mysql_insertid}, 1, '... our alias works');

}
4 changes: 2 additions & 2 deletions t/012_st_handle.t
Expand Up @@ -22,8 +22,8 @@ BEGIN {
is($sth->{Statement}, 'SELECT Foo, Bar, Baz FROM FooBarBaz', '... got the right statement');
is($sth->{Database}, $dbh, '... got the right Database handle');

cmp_ok($sth->{NUM_OF_FIELDS}, '==', 3, '... got the right number of fields');
cmp_ok($sth->{NUM_OF_PARAMS}, '==', 0, '... got the right number of params');
is($sth->{NUM_OF_FIELDS}, 3, '... got the right number of fields');
is($sth->{NUM_OF_PARAMS}, 0, '... got the right number of params');

is_deeply(
$sth->{NAME},
Expand Down
8 changes: 4 additions & 4 deletions t/016_mock_add_resultset_test.t
Expand Up @@ -31,7 +31,7 @@ $dbh->{mock_add_resultset} = {
my ($result) = $sth->fetchrow_array();


cmp_ok($result, '==', 10, '... got the result we expected');
is($result, 10, '... got the result we expected');

$sth->finish();
}
Expand All @@ -50,7 +50,7 @@ $dbh->{mock_add_resultset} = {

my ($result) = $sth->fetchrow_array();

cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');

$sth->finish();
}
Expand All @@ -65,7 +65,7 @@ $dbh->{mock_add_resultset} = {

my ($result) = $sth->fetchrow_array();

cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');

$sth->finish();
}
Expand All @@ -80,7 +80,7 @@ $dbh->{mock_add_resultset} = {

my ($result) = $sth->fetchrow_array();

cmp_ok($result, '==', 50, '... got the result we expected');
is($result, 50, '... got the result we expected');

$sth->finish();
}
Expand Down
10 changes: 5 additions & 5 deletions t/017_st_can_connect.t
Expand Up @@ -9,8 +9,8 @@ BEGIN {

my $dbh = DBI->connect('DBI:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
isa_ok($dbh, "DBI::db");
cmp_ok($dbh->{RaiseError}, '==', 1, '... RaiseError is set correctly');
cmp_ok($dbh->{PrintError}, '==', 0, '... PrintError is set correctly');
is($dbh->{RaiseError}, 1, '... RaiseError is set correctly');
is($dbh->{PrintError}, 0, '... PrintError is set correctly');

my $sth_exec = $dbh->prepare('SELECT foo FROM bar');
isa_ok($sth_exec, "DBI::st");
Expand All @@ -19,7 +19,7 @@ isa_ok($sth_exec, "DBI::st");
$dbh->{mock_can_connect} = 0;

# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');

# and check the side effects of that
ok(!$dbh->{Active}, '... the handle is not Active');
Expand All @@ -36,7 +36,7 @@ like($@, qr/No connection present/, '... we got the expected execption');
$dbh->{mock_can_connect} = 1;

# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 1, '... can connect is set to 1');
is($dbh->{mock_can_connect}, 1, '... can connect is set to 1');

# and check the side effects of that
ok($dbh->{Active}, '... the handle is Active');
Expand All @@ -60,7 +60,7 @@ is_deeply($row, [ qw(this that) ], '... we got back the expected data in the fir
$dbh->{mock_can_connect} = 0;

# check our value is correctly set
cmp_ok($dbh->{mock_can_connect}, '==', 0, '... can connect is set to 0');
is($dbh->{mock_can_connect}, 0, '... can connect is set to 0');

# and check the side effects of that
ok(!$dbh->{Active}, '... the handle is not Active');
Expand Down

0 comments on commit 0080fb9

Please sign in to comment.