1#!/usr/bin/perl -w
2
3use strict;
4
5use File::Spec;
6
7use lib '.', File::Spec->catdir( File::Spec->curdir, 't', 'lib' );
8
9use Alzabo::Test::Utils;
10
11use Test::More;
12
13
14my @rdbms_names = Alzabo::Test::Utils->rdbms_names;
15
16unless (@rdbms_names)
17{
18    plan skip_all => 'no test config provided';
19    exit;
20}
21
22
23my $tests_per_run = 2;
24
25plan tests => $tests_per_run * @rdbms_names;
26
27
28Alzabo::Test::Utils->remove_all_schemas;
29
30
31foreach my $rdbms (@rdbms_names)
32{
33    Test::More::diag( "Running $rdbms reverse engineering tests" );
34
35    my $s1 = Alzabo::Test::Utils->make_schema($rdbms);
36
37    my $config = Alzabo::Test::Utils->test_config_for($rdbms);
38
39    delete $config->{schema_name};
40
41    $config->{name}  = $s1->name;
42    $config->{rdbms} = $s1->driver->driver_id;
43
44    my $s2;
45    eval_ok( sub { $s2 = Alzabo::Create::Schema->reverse_engineer(%$config) },
46	     "Reverse engineer the @{[$s1->name]} schema with @{[$s1->driver->driver_id]}" );
47
48    if ( ref $s2 )
49    {
50        my @diff = $s1->rules->schema_sql_diff( old => $s1,
51                                                new => $s2 );
52
53        my $sql = join "\n", @diff;
54
55        is ( $sql, '',
56             "Reverse engineered schema's SQL should be the same as the original's" );
57
58        $s1->delete;
59    }
60    else
61    {
62        ok( 0, "Reverse engineering failed, cannot do diff" );
63    }
64}
65