2 # Copyright (C) 2007-2010, Parrot Foundation.
9 use Test::More tests => 12;
13 use File::Temp qw( tempdir );
19 q{Relevant only when working in checkout from repository},
21 unless (-e 'DEVELOPING');
23 use_ok('Parrot::Manifest');
26 my $mani = Parrot::Manifest->new( { script => $script, } );
27 isa_ok( $mani, 'Parrot::Manifest' );
32 my $manifest_lines_ref = $mani->prepare_manifest();
33 ok( $manifest_lines_ref, "prepare_manifest_skip() returned" );
35 # 1: Copy the real MANIFEST unaltered to the tempdir.
36 # Assuming the real MANIFEST was correct going in to this test, the
37 # absence of any change in it will mean that there will be no need to
40 my $tdir = tempdir( CLEANUP => 1 );
42 or croak "Unable to change to temporary directory for testing";
43 copy( qq{$cwd/$f}, qq{$tdir/$f} )
44 or croak "Unable to copy $f to tempdir";
45 ok( -f $f, "$f found in tempdir" );
46 my $need_for_file = $mani->determine_need_for_manifest($manifest_lines_ref);
47 ok( !$need_for_file, "No need to regenerate $f" );
49 or croak "Unable to change back from temporary directory after testing";
50 unlink qq{$tdir/$f} or croak "Unable to delete file from tempdir";
53 # 2: Copy the real MANIFEST to the tempdir but mangle it there.
54 # The alteration in the copied MANIFEST will be sufficient to require
55 # regeneration of MANIFEST. And for good measure, toss in a line of all
56 # whitespace to demonstrate that it is correctly skipped.
58 my $tdir = tempdir( CLEANUP => 1 );
60 or croak "Unable to change to temporary directory for testing";
61 copy( qq{$cwd/$f}, qq{$tdir/$f} )
62 or croak "Unable to copy $f to tempdir";
63 ok( -f $f, "$f found in tempdir" );
65 tie @lines, 'Tie::File', qq{$tdir/$f}
66 or croak "Unable to tie to $f in tempdir";
69 if ( defined( $lines[-1] ) ) {
75 untie @lines or croak "Unable to untie from $f";
76 my $need_for_file = $mani->determine_need_for_manifest($manifest_lines_ref);
77 ok( $need_for_file, "Need to regenerate $f" );
78 ok( $mani->print_manifest($manifest_lines_ref), "print_manifest() returned true" );
79 ok( -f $f, "$f has been created in tempdir" );
80 unlink qq{$tdir/$f} or croak "Unable to delete file from tempdir";
82 or croak "Unable to change back from temporary directory after testing";
85 # 3: Go to a tempdir which lacks a MANIFEST. Confirm that you need to
86 # regenerate MANIFEST (but do not bother to actually do it there).
88 my $tdir = tempdir( CLEANUP => 1 );
90 or croak "Unable to change to temporary directory for testing";
91 ok( !-f $f, "$f found in tempdir" );
92 my $need_for_file = $mani->determine_need_for_manifest($manifest_lines_ref);
93 ok( $need_for_file, "We would need to regenerate $f" );
95 or croak "Unable to change back from temporary directory after testing";
99 pass("Completed all tests in $0");
101 ################### DOCUMENTATION ###################
105 02-regenerate_file.t - test C<Parrot::Manifest> MANIFEST-related methods
109 % prove t/manifest/02-regenerate_file.t
113 The files in this directory test the publicly callable methods of
114 F<lib/Parrot/Manifest.pm> and packages which inherit from that package.
116 F<02-regenerate_file.t> tests whether Parrot::Manifest correctly determines
117 whether MANIFEST needs to be regenerated or not.
121 James E Keenan (jkeenan@cpan.org)
125 Parrot::Manifest, Parrot::Manifest::Files, Parrot::Manifest::Skip,
126 F<tools/dev/mk_manifest_and_skip.pl>.
132 # cperl-indent-level: 4
135 # vim: expandtab shiftwidth=4: