use IO::File;
use SQL::Translator;
+use Test::More;
-# How many tests
-BEGIN { print "1..3\n"; }
-
-$SQL::Translator::DEBUG = 0;
+plan tests => 3;
# Our object; uses the default parser and producer
my $tr = SQL::Translator->new;
# Pass filename: simplest way
my $translated_datafile = $tr->translate($datafile);
-#warn "Data from filename method is\n$translated_datafile\n\n\n";
# Pass string reference
read($fh, $data, -s $datafile);
my $translated_data = $tr->translate(\$data);
-#warn "Data from string is\n$translated_data\n\n\n";
-
-print "not " unless length $translated_datafile;
-print "ok 1 # passing string (filename) works\n";
-
-print "not " unless length $translated_data;
-print "ok 2 # passing string as SCALAR reference\n";
-print "not " unless ($translated_datafile eq $translated_data);
-print "ok 3 # from file == from string\n";
+ok(length $translated_datafile, "passing string (filename) works");
+ok(length $translated_data, "passing string as SCALAR reference");
+is($translated_datafile, $translated_data, "from file == from string");
use strict;
use SQL::Translator;
use SQL::Translator::Parser::xSV qw(parse);
+use Test::More;
-$SQL::Translator::DEBUG = 0;
+plan tests => 10;
my $tr = SQL::Translator->new;
my $data = q|One, Two, Three, Four, Five
And, So, am, I, "you crazy, crazy bastard"
);|;
-BEGIN { print "1..10\n"; }
-
my $val = parse($tr, $data);
# $val holds the processed data structure.
# The data structure should have one key:
-print "not " if (scalar keys %{$val} != 1);
-print "ok 1\n";
+is(scalar keys %{$val}, 1, "One table...");
# The data structure should have a single key, named sessions
-print "not " unless (defined $val->{'table1'});
-print qq(ok 2 # has a key named "table1"\n);
+ok(defined $val->{'table1'} => "...named 'table1'");
# $val->{'table1'} should have a single index (since we haven't
# defined an index, but have defined a primary key)
my $indices = $val->{'table1'}->{'indices'};
-print "not " unless (scalar @{$indices} == 1);
-print "ok 3 # correct index number\n";
+is(scalar @{$indices}, 1, "correct index number");
-print "not " unless ($indices->[0]->{'type'} eq 'primary_key');
-print "ok 4 # correct index type\n";
-print "not " unless ($indices->[0]->{'fields'}->[0] eq 'One');
-print "ok 5 # correct index name\n";
+is($indices->[0]->{'type'}, 'primary_key', "correct index type");
+is($indices->[0]->{'fields'}->[0], 'One', "correct index name");
# $val->{'table1'} should have two fields, id and a_sessionn
my $fields = $val->{'table1'}->{'fields'};
-print "not " unless (scalar keys %{$fields} == 5);
-print "ok 6 # correct number of fields (5)\n";
+is(scalar keys %{$fields} => 5 => "5 fields in %fields");
-print "not " unless ($fields->{'One'}->{'data_type'} eq 'char');
-print "ok 7 # correct field type: One (char)\n";
+is($fields->{'One'}->{'data_type'}, 'char',
+ "\$fields->{'One'}->{'data_type'} == 'char'");
-print "not " unless ($fields->{'One'}->{'is_primary_key'} == 1);
-print "ok 8 # correct key identification (One == key)\n";
+is($fields->{'One'}->{'is_primary_key'} => 1,
+ "\$fields->{'One'}->{'is_primary_key'} == 1");
-print "not " if (defined $fields->{'Two'}->{'is_primary_key'});
-print "ok 9 # correct key identification (Two != key)\n";
+ok(! defined $fields->{'Two'}->{'is_primary_key'},
+ "\$fields->{'Two'}->{'is_primary_key'} == 0");
# Test that the order is being maintained by the internal order
# data element
<=>
$fields->{$b}->{'order'}
} keys %{$fields};
-print "not " unless ($order[0] eq 'One' && $order[4] eq 'Five');
-print "ok 10 # ordering of fields\n";
+ok($order[0] eq 'One' && $order[4] eq 'Five', "Ordering OK");