From 0c6f7fb3bdf5a108b3d7eea927b4183bb3845ea8 Mon Sep 17 00:00:00 2001 From: Adam Kennedy Date: Sun, 5 Apr 2009 02:32:10 +0000 Subject: [PATCH] Cleaning up the test --- t/rt_29058_group_by.t | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/t/rt_29058_group_by.t b/t/rt_29058_group_by.t index 0af1477..e7f97d3 100644 --- a/t/rt_29058_group_by.t +++ b/t/rt_29058_group_by.t @@ -5,34 +5,46 @@ BEGIN { $^W = 1; } +use Test::More tests => 6; +use Test::NoWarnings; use t::lib::Test; -use Test::More tests => 6; -use DBI; - my $dbh = connect_ok(); -$dbh->do( 'CREATE TABLE foo (bar TEXT, num INT)' ); +$dbh->do('CREATE TABLE foo (bar TEXT, num INT)'); -for (1..5) { - $dbh->do('INSERT INTO foo (bar, num) VALUES (?,?)', undef, ($_%2 ? "odd" : "even"), $_); +foreach ( 1..5 ) { + $dbh->do( + 'INSERT INTO foo (bar, num) VALUES (?, ?)', + undef, ($_%2 ? "odd" : "even"), $_ + ); } # DBI->trace(9); # see if placeholder works -my ($v, $num) = $dbh->selectrow_array('SELECT bar, num FROM foo WHERE num = ?', undef, 3); -ok $v eq 'odd' && $num == 3; +my ($v, $num) = $dbh->selectrow_array( + 'SELECT bar, num FROM foo WHERE num = ?', + undef, 3 +); +ok( $v eq 'odd' && $num == 3 ); # see if the sql itself works as expected -my $ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 1'); -ok -ok @$ar == 2; +my $ar = $dbh->selectall_arrayref( + 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > 1' +); +is( scalar(@$ar), 2, 'Got 2 results' ); # known workaround # ref: http://code.google.com/p/gears/issues/detail?id=163 -$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 0+?', undef, 1); -ok @$ar == 2; +$ar = $dbh->selectall_arrayref( + 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > 0+?', + undef, 1 +); +is( scalar(@$ar), 2, 'Got 2 results' ); # and this is what should be tested -$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?', undef, 1); -print "4: @$_\n" for @$ar; -ok @$ar == 2, "we got ".(@$ar)." items"; +$ar = $dbh->selectall_arrayref( + 'SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?', + undef, 1 +); +# print "4: @$_\n" for @$ar; +is( scalar(@$ar), 2, "we got ".(@$ar)." items" );