From: rkinyon Date: Sun, 18 Feb 2007 11:53:27 +0000 (+0000) Subject: Conversion seems to be working X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c393ff54dc6905356339ea38e07b0828e595fcf;p=dbsrgits%2FDBM-Deep.git Conversion seems to be working --- diff --git a/t/44_upgrade_db.t b/t/44_upgrade_db.t index 8362c29..48e53f2 100644 --- a/t/44_upgrade_db.t +++ b/t/44_upgrade_db.t @@ -10,10 +10,11 @@ BEGIN { } } -plan tests => 11; +plan tests => 109; use t::common qw( new_fh ); use File::Spec; +use Test::Deep; my $PROG = File::Spec->catfile( qw( utils upgrade_db.pl ) ); @@ -47,17 +48,26 @@ is( # All files are of the form: # $db->{foo} = [ 1 .. 3 ]; -my @versions = ( +my @input_files = ( '0-983', '0-99_04', '1-0000', ); -foreach my $input_version ( @versions ) { - my $input_filename = File::Spec->catfile( qw( t etc ), "db-$input_version" ); +my @output_versions = ( + '0.91', '0.92', '0.93', '0.94', '0.95', '0.96', '0.97', '0.98', + '0.981', '0.982', '0.983', + '0.99_01', '0.99_02', '0.99_03', '0.99_04', + '1.00', '1.0000', +); - foreach my $output_version ( @versions ) { - (my $v = $output_version) =~ s/-/./g; +foreach my $input_filename ( + map { + File::Spec->catfile( qw( t etc ), "db-$_" ) + } @input_files +) { + foreach my $v ( @output_versions ) { + #print "$input_filename => $output_filename ($v)\n"; my $output = run_prog( $PROG, "-input $input_filename", @@ -65,7 +75,7 @@ foreach my $input_version ( @versions ) { "-version $v", ); - if ( $input_version =~ /_/ ) { + if ( $input_filename =~ /_/ ) { is( $output, "'$input_filename' is a dev release and not supported.\n$short", "Input file is a dev release - not supported", @@ -74,7 +84,7 @@ foreach my $input_version ( @versions ) { next; } - if ( $output_version =~ /_/ ) { + if ( $v =~ /_/ ) { is( $output, "-version '$v' is a dev release and not supported.\n$short", "Output version is a dev release - not supported", @@ -82,6 +92,35 @@ foreach my $input_version ( @versions ) { next; } + + # Now, read the output file with the right version. + ok( !$output, "A successful run produces no output" ); + die "$output\n" if $output; + + my $db; + if ( $v =~ /^0/ ) { + push @INC, File::Spec->catdir( 'utils', 'lib' ); + eval "use DBM::Deep::09830"; + $db = DBM::Deep::09830->new( $output_filename ); + } + elsif ( $v =~ /^1/ ) { + push @INC, 'lib'; + eval "use DBM::Deep"; + $db = DBM::Deep->new( $output_filename ); + } + else { + die "How did we get here?!\n"; + } + + ok( $db, "Writing to version $v made a file" ); + + cmp_deeply( + $db->export, + { + foo => [ 1 .. 3 ], + }, + "We can read the output file", + ); } } diff --git a/utils/lib/DBM/Deep/09830.pm b/utils/lib/DBM/Deep/09830.pm index b5342df..4022e58 100644 --- a/utils/lib/DBM/Deep/09830.pm +++ b/utils/lib/DBM/Deep/09830.pm @@ -184,13 +184,13 @@ sub _init { sub TIEHASH { shift; - require DBM::Deep::09830::Hash; + #require DBM::Deep::09830::Hash; return DBM::Deep::09830::Hash->TIEHASH( @_ ); } sub TIEARRAY { shift; - require DBM::Deep::09830::Array; + #require DBM::Deep::09830::Array; return DBM::Deep::09830::Array->TIEARRAY( @_ ); } diff --git a/utils/upgrade_db.pl b/utils/upgrade_db.pl index bbd9586..226488e 100755 --- a/utils/upgrade_db.pl +++ b/utils/upgrade_db.pl @@ -67,7 +67,7 @@ my %db; { my $ver = $opts{version}; - if ( $ver =~ /^0\.98/ ) { + if ( $ver =~ /^0\.9[1-8]/ ) { $ver = 0; } elsif ( $ver =~ /^0\.99/) { @@ -84,6 +84,9 @@ my %db; _exit( "-version '$opts{version}' is a dev release and not supported." ); } + # First thing is to destroy the file, in case it's an incompatible version. + unlink $opts{output}; + my $mod = $headerver_to_module{ $ver }; eval "use $mod;"; $db{output} = $mod->new({ @@ -94,7 +97,9 @@ my %db; $db{output}->lock; } -# Do the actual conversion +# Do the actual conversion. This is the code that compress uses. +$db{input}->_copy_node( $db{output} ); +undef $db{output}; ################################################################################