}
}
-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 ) );
# 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",
"-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",
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",
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",
+ );
}
}
{
my $ver = $opts{version};
- if ( $ver =~ /^0\.98/ ) {
+ if ( $ver =~ /^0\.9[1-8]/ ) {
$ver = 0;
}
elsif ( $ver =~ /^0\.99/) {
_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({
$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};
################################################################################