Test table and field names with quote characters in them
[dbsrgits/SQL-Translator.git] / t / 60roundtrip.t
index 2f98ca9..9079406 100644 (file)
@@ -8,6 +8,7 @@ use Test::Differences;
 use FindBin qw/$Bin/;
 
 use SQL::Translator;
+use SQL::Translator::Utils qw/ddl_parser_instance/;
 
 
 ### Set $ENV{SQLTTEST_RT_DEBUG} = 1 for more output
@@ -16,10 +17,12 @@ use SQL::Translator;
 my $plan = [
   {
     engine => 'XML',
-    req => 'XML::LibXML',
+    req => 'XML::LibXML 1.69',
+    no_grammar => 1,
   },
   {
     engine => 'YAML',
+    no_grammar => 1,
   },
 
   {
@@ -89,7 +92,7 @@ my $base_file = "$Bin/data/roundtrip_autogen.yaml";
 open (my $base_fh, '<', $base_file) or die "$base_file: $!";
 
 my $base_t = SQL::Translator->new;
-$base_t->$_ (1) for qw/add_drop_table no_comments/;
+$base_t->$_ (1) for qw/add_drop_table no_comments quote_identifiers/;
 
 my $base_schema = $base_t->translate (
   parser => 'YAML',
@@ -111,7 +114,7 @@ for my $args (@$plan) {
     my @req = ref $args->{req} ? @{$args->{req}} : $args->{req}||();
     my @missing;
     for (@req) {
-      eval "require $_";
+      eval "use $_ ()";
       push @missing, $_ if ($@);
     }
     if (@missing) {
@@ -121,9 +124,21 @@ for my $args (@$plan) {
       );
     }
 
+    use_ok("SQL::Translator::Producer::$args->{engine}");
+    use_ok("SQL::Translator::Parser::$args->{engine}");
+
+    ok(ddl_parser_instance($args->{engine}), 'Got proper parser instance')
+      unless $args->{no_grammar};
+
     TODO: {
       local $TODO = $args->{todo} if $args->{todo};
 
+      no warnings 'once';
+      # silence PR::D from spewing on STDERR
+      local $::RD_ERRORS = 0 if $args->{todo};
+      local $::RD_WARN = 0 if $args->{todo};
+      local $::RD_HINT = 0 if $args->{todo};
+
       lives_ok (
         sub { check_roundtrip ($args, $base_schema) },
         "Round trip for $args->{name} did not throw an exception",
@@ -155,7 +170,7 @@ sub check_roundtrip {
 
 # parse the sql back
   my $parser_t = SQL::Translator->new;
-  $parser_t->$_ (1) for qw/add_drop_table no_comments/;
+  $parser_t->$_ (1) for qw/add_drop_table no_comments quote_identifiers/;
   my $mid_schema = $parser_t->translate (
     data => $base_out,
     parser => $args->{engine},
@@ -165,6 +180,12 @@ sub check_roundtrip {
   isa_ok ($mid_schema, 'SQL::Translator::Schema', "First $args->{name} parser pass produced a schema:")
     or do {
       diag (_gen_diag ( $parser_t->error, $base_out ) );
+      my $i;
+      note join ("\n" . ( '=' x 76) . "\n",
+        'Unparseable DDL:',
+        (join ("\n", map { ++$i . ":\t$_" } split /\n/, $base_out) ),
+        ''
+      );
       return;
     };
 
@@ -173,7 +194,7 @@ sub check_roundtrip {
     _get_table_info ($mid_schema->get_tables),
     _get_table_info ($base_schema->get_tables),
     "Schema tables generally match afer $args->{name} parser trip",
-  ) or return;
+  ) or (diag(explain _get_table_info($mid_schema->get_tables)), return);
 
 # and produce sql once again
 
@@ -205,9 +226,9 @@ sub check_roundtrip {
 
 # the two sql strings should be identical
   my $msg = "$args->{name} SQL roundtrip successful - SQL statements match";
-  $ENV{SQLTTEST_RT_DEBUG}     #stringify below because IO::Scalar does not behave nice
-    ? eq_or_diff ("$rt_out", "$base_out", $msg)
-    : ok ("$rt_out" eq "$base_out", $msg)
+  $ENV{SQLTTEST_RT_DEBUG}
+    ? eq_or_diff ($rt_out, $base_out, $msg)
+    : ok ($rt_out eq $base_out, $msg)
   ;
 }