From: Robert Buels Date: Tue, 20 Apr 2010 19:12:22 +0000 (+0000) Subject: create_ddl_dir mkpaths its dir if necessary. also, added storage/deploy.t as place... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4068e05f67336c92ee83f71cdd86df10beee014e;p=dbsrgits%2FDBIx-Class-Historic.git create_ddl_dir mkpaths its dir if necessary. also, added storage/deploy.t as place to put deployment tests --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index e048b62..e2d0b41 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -16,6 +16,8 @@ use List::Util(); use Data::Dumper::Concise(); use Sub::Name (); +use File::Path (); + __PACKAGE__->mk_group_accessors('simple' => qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints @@ -2334,6 +2336,9 @@ sub create_ddl_dir { unless ($dir) { carp "No directory given, using ./\n"; $dir = './'; + } else { + -d $dir or File::Path::mkpath($dir) + or croak "create_ddl_dir: could not create dir '$dir'"; } $self->throw_exception ("Directory '$dir' does not exist\n") unless(-d $dir); diff --git a/t/storage/deploy.t b/t/storage/deploy.t new file mode 100644 index 0000000..4cc8dff --- /dev/null +++ b/t/storage/deploy.t @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +use File::Spec; +use File::Path qw/ mkpath rmtree /; + + +my $schema = DBICTest->init_schema(); + +my $var = File::Spec->catfile(qw| t var create_ddl_dir |); +-d $var + or mkpath($var) + or die "can't create $var"; + +my $test_dir_1 = File::Spec->catdir( $var, 'test1', 'foo', 'bar' ); +rmtree( $test_dir_1 ) if -d $test_dir_1; +$schema->create_ddl_dir( undef, undef, $test_dir_1 ); + +ok( -d $test_dir_1, 'create_ddl_dir did a mkpath on its target dir' ); +ok( scalar( glob $test_dir_1.'/*.sql' ), 'there are sql files in there' ); + +TODO: { + local $TODO = 'we should probably add some tests here for actual deployability of the DDL?'; + ok( 0 ); +} + +done_testing;