7 plan skip_all => "Skipping the upgrade_db.pl tests on Win32/cygwin for now."
8 if ( $^O eq 'MSWin32' || $^O eq 'cygwin' );
10 plan skip_all => "Skipping the upgrade_db.pl tests on *bsd for now."
14 eval "use Pod::Usage 1.3;"; push @failures, 'Pod::Usage' if $@;
15 eval "use IO::Scalar;"; push @failures, 'IO::Scalar' if $@;
16 eval "use FileHandle::Fmode;"; push @failures, 'FileHandle::Fmode' if $@;
18 my $missing = join ',', @failures;
19 plan skip_all => "'$missing' must be installed to run these tests";
25 use t::common qw( new_fh );
29 my $PROG = File::Spec->catfile( qw( utils upgrade_db.pl ) );
31 my $short = get_pod( $PROG, 0 );
32 my $long = get_pod( $PROG, 1 );
34 is( run_prog( $PROG ), "Missing required parameters.\n$long", "Failed no params" );
35 is( run_prog( $PROG, '-input foo' ), "Missing required parameters.\n$long", "Failed only -input" );
36 is( run_prog( $PROG, '-output foo' ), "Missing required parameters.\n$long", "Failed only -output" );
38 run_prog( $PROG, '-input foo', '-output foo' ),
39 "Cannot use the same filename for both input and output.\n$short",
44 run_prog( $PROG, '-input foo', '-output bar' ),
45 "'foo' is not a file.\n$short",
46 "Failed input does not exist",
49 my (undef, $input_filename) = new_fh();
50 my (undef, $output_filename) = new_fh();
53 run_prog( $PROG, "-input $input_filename", "-output $output_filename" ),
54 "'$input_filename' is not a DBM::Deep file.\n$short",
55 "Input is not a DBM::Deep file",
58 unlink $input_filename;unlink $output_filename;
60 # All files are of the form:
61 # $db->{foo} = [ 1 .. 3 ];
70 my @output_versions = (
71 '0.91', '0.92', '0.93', '0.94', '0.95', '0.96', '0.97', '0.98',
72 '0.981', '0.982', '0.983',
73 '0.99_01', '0.99_02', '0.99_03', '0.99_04',
74 '1.00', '1.000', '1.0000', '1.0001', '1.0002',
75 '1.0003', '1.0004', '1.0005', '1.0006', '1.0007', '1.0008', '1.0009', '1.0010',
76 '1.0011', '1.0012', '1.0013', '1.0014',
79 foreach my $input_filename (
81 File::Spec->catfile( qw( t etc ), "db-$_" )
84 # chmod it writable because old DBM::Deep versions don't handle readonly
85 # files correctly. This is fixed in DBM::Deep 1.0000
86 chmod 0600, $input_filename;
88 foreach my $v ( @output_versions ) {
89 my (undef, $output_filename) = new_fh();
91 my $output = run_prog(
93 "-input $input_filename",
94 "-output $output_filename",
98 warn "Testing $input_filename against $v\n";
100 # Clone was removed as a requirement in 1.0006
101 if ( $output =~ /Can\'t locate Clone\.pm in \@INC/ ) {
103 unless ( $input_filename =~ /_/ || $v =~ /_/ ) {
109 if ( $input_filename =~ /_/ ) {
111 $output, "'$input_filename' is a dev release and not supported.\n$short",
112 "Input file is a dev release - not supported",
120 $output, "-version '$v' is a dev release and not supported.\n$short",
121 "Output version is a dev release - not supported",
127 # Now, read the output file with the right version.
128 ok( !$output, "A successful run produces no output" );
129 die "'$input_filename' -> '$v' : $output\n" if $output;
132 if ( $v =~ /^1\.001[0-4]/ || $v =~ /^1\.000[3-9]/ ) {
134 eval "use DBM::Deep $v"; die $@ if $@;
135 $db = DBM::Deep->new( $output_filename );
137 elsif ( $v =~ /^1\.000?[0-2]?/ ) {
138 push @INC, File::Spec->catdir( 'utils', 'lib' );
139 eval "use DBM::Deep::10002";
140 $db = DBM::Deep::10002->new( $output_filename );
142 elsif ( $v =~ /^0/ ) {
143 push @INC, File::Spec->catdir( 'utils', 'lib' );
144 eval "use DBM::Deep::09830";
145 $db = DBM::Deep::09830->new( $output_filename );
148 die "How did we get here?!\n";
151 ok( $db, "Writing to version $v made a file" );
155 { foo => [ 1 .. 3 ] },
156 "We can read the output file",
161 ################################################################################
163 #XXX This needs to be made OS-portable
165 open( my $fh, '-|', "$^X @_ 2>&1" )
166 or die "Cannot launch '@_' as a piped filehandle: $!\n";
167 return join '', <$fh>;
170 # In 5.8, we could use in-memory filehandles and have done:
171 # open( my $fh, '>', \my $pod ) or die "Cannot open in-memory filehandle: $!\n";
174 # However, DBM::Deep requires 5.6, so this set of contortions will have to do.
178 my ($fh, $fn) = new_fh();
186 -exitval => 'NOEXIT',
191 return join '', <$fh>;