X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fstorage%2Fquote_names.t;h=591606c4d359c24a67f83ee9082169a2edbbd910;hb=09d8fb4a05e6cd025924cc08e41484f17a116695;hp=4d768cf6e3b3b5e7b7a5533792f25a8c4a041606;hpb=199fbc453ec03891d0e156d7353c5e992ba4de47;p=dbsrgits%2FDBIx-Class.git diff --git a/t/storage/quote_names.t b/t/storage/quote_names.t index 4d768cf..591606c 100644 --- a/t/storage/quote_names.t +++ b/t/storage/quote_names.t @@ -1,11 +1,13 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; -use Test::Exception; -use Data::Dumper::Concise; use Try::Tiny; -use lib qw(t/lib); + use DBICTest; +use DBIx::Class::_Util 'dump_value'; +$Data::Dumper::Indent = 0; my %expected = ( 'DBIx::Class::Storage::DBI' => @@ -51,14 +53,17 @@ my %expected = ( ); for my $class (keys %expected) { SKIP: { - eval "require ${class}" - or skip "Skipping test of quotes for $class due to missing dependencies", 1; + + eval "require ${class}" or do { + note "Failed load of $class:\n\n$@\n\n"; + skip "Skipping test of quotes for $class due to missing compile-time dependencies", 1; + }; my $mapping = $expected{$class}; my ($quote_char, $name_sep) = @$mapping{qw/quote_char name_sep/}; my $instance = $class->new; - my $quote_char_text = dumper($quote_char); + my $quote_char_text = dump_value $quote_char; if (exists $mapping->{quote_char}) { is_deeply $instance->sql_quote_char, $quote_char, @@ -71,21 +76,11 @@ for my $class (keys %expected) { SKIP: { # Try quote_names with available DBs. -# SQLite first. - -my $schema = DBICTest->init_schema(quote_names => 1); - -is $schema->storage->sql_maker->quote_char, '"', - q{quote_names => 1 sets correct quote_char for SQLite ('"')}; - -is $schema->storage->sql_maker->name_sep, '.', - q{quote_names => 1 sets correct name_sep for SQLite (".")}; - -# Now the others. - # Env var to base class mapping, these are the DBs I actually have. -# -- Caelum +# the SQLITE is a fake memory dsn +local $ENV{DBICTEST_SQLITE_DSN} = 'dbi:SQLite::memory:'; my %dbs = ( + SQLITE => 'DBIx::Class::Storage::DBI::SQLite', ORA => 'DBIx::Class::Storage::DBI::Oracle::Generic', PG => 'DBIx::Class::Storage::DBI::Pg', MYSQL => 'DBIx::Class::Storage::DBI::mysql', @@ -99,43 +94,58 @@ my %dbs = ( MSSQL_ODBC => 'DBIx::Class::Storage::DBI::MSSQL', ); -while (my ($db, $base_class) = each %dbs) { +# lie that we already locked stuff - the tests below do not touch anything +# unless we are under travis, where the OOM killers reign and things are rough +$ENV{DBICTEST_LOCK_HOLDER} = -1 + unless DBICTest::RunMode->is_ci; + +# Make sure oracle is tried last - some clients (e.g. 10.2) have symbol +# clashes with libssl, and will segfault everything coming after them +for my $db (sort { + $a eq 'ORA' ? 1 + : $b eq 'ORA' ? -1 + : $a cmp $b +} keys %dbs) { my ($dsn, $user, $pass) = map $ENV{"DBICTEST_${db}_$_"}, qw/DSN USER PASS/; next unless $dsn; my $schema; - try { + my $sql_maker = try { $schema = DBICTest::Schema->connect($dsn, $user, $pass, { quote_names => 1 }); $schema->storage->ensure_connected; - 1; + $schema->storage->sql_maker; } || next; - my $expected_quote_char = $expected{$base_class}{quote_char}; - my $quote_char_text = dumper($expected_quote_char); + my ($exp_quote_char, $exp_name_sep) = + @{$expected{$dbs{$db}}}{qw/quote_char name_sep/}; + + my ($quote_char_text, $name_sep_text) = map { dump_value $_ } + ($exp_quote_char, $exp_name_sep); - is_deeply $schema->storage->sql_maker->quote_char, - $expected_quote_char, + is_deeply $sql_maker->quote_char, + $exp_quote_char, "$db quote_char with quote_names => 1 is $quote_char_text"; - my $expected_name_sep = $expected{$base_class}{name_sep}; - is $schema->storage->sql_maker->name_sep, - $expected_name_sep, - "$db name_sep with quote_names => 1 is '$expected_name_sep'"; -} + is $sql_maker->name_sep, + $exp_name_sep, + "$db name_sep with quote_names => 1 is $name_sep_text"; -done_testing; + # if something was produced - it better be quoted + if ( + # the SQLT producer has no idea what quotes are :/ + ! grep { $db eq $_ } qw( SYBASE DB2 ) + and + my $ddl = try { $schema->deployment_statements } + ) { + my $quoted_artist = $sql_maker->_quote('artist'); -sub dumper { - my $val = shift; - - my $dd = DumperObject; - $dd->Indent(0); - return $dd->Values([ $val ])->Dump; + like ($ddl, qr/^CREATE\s+TABLE\s+\Q$quoted_artist/msi, "$db DDL contains expected quoted table name"); + } } -1; +done_testing;