[TT# 1592][t] Improve test for open opcode delegation. All tests in the file pass...
[parrot.git] / t / manifest / 02-regenerate_file.t
blobd6af5168bd679140ec0f09be527cfafff494db02
1 #! perl
2 # Copyright (C) 2007-2010, Parrot Foundation.
3 # $Id$
4 # 02-regenerate_file.t
6 use strict;
7 use warnings;
9 use Test::More tests => 12;
10 use Carp;
11 use Cwd;
12 use File::Copy;
13 use File::Temp qw( tempdir );
14 use Tie::File;
15 use lib (qw| lib |);
17 SKIP: {
18     skip
19         q{Relevant only when working in checkout from repository},
20         11
21         unless (-e 'DEVELOPING');
23     use_ok('Parrot::Manifest');
25     my $script = $0;
26     my $mani = Parrot::Manifest->new( { script => $script, } );
27     isa_ok( $mani, 'Parrot::Manifest' );
29     my $cwd = cwd();
30     my $f   = q{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
38     # regenerate it.
39     {
40         my $tdir = tempdir( CLEANUP => 1 );
41         chdir $tdir
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" );
48         chdir $cwd
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";
51     }
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.
57     {
58         my $tdir = tempdir( CLEANUP => 1 );
59         chdir $tdir
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" );
64         my @lines;
65         tie @lines, 'Tie::File', qq{$tdir/$f}
66             or croak "Unable to tie to $f in tempdir";
68         for ( 1 .. 10 ) {
69             if ( defined( $lines[-1] ) ) {
70                 pop @lines;
71             }
72         }
73         push @lines, q{   };
74         push @lines, q{};
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";
81         chdir $cwd
82             or croak "Unable to change back from temporary directory after testing";
83     }
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).
87     {
88         my $tdir = tempdir( CLEANUP => 1 );
89         chdir $tdir
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" );
94         chdir $cwd
95             or croak "Unable to change back from temporary directory after testing";
96     }
99 pass("Completed all tests in $0");
101 ################### DOCUMENTATION ###################
103 =head1 NAME
105 02-regenerate_file.t - test C<Parrot::Manifest> MANIFEST-related methods
107 =head1 SYNOPSIS
109     % prove t/manifest/02-regenerate_file.t
111 =head1 DESCRIPTION
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.
119 =head1 AUTHOR
121 James E Keenan (jkeenan@cpan.org)
123 =head1 SEE ALSO
125 Parrot::Manifest, Parrot::Manifest::Files, Parrot::Manifest::Skip,
126 F<tools/dev/mk_manifest_and_skip.pl>.
128 =cut
130 # Local Variables:
131 #   mode: cperl
132 #   cperl-indent-level: 4
133 #   fill-column: 100
134 # End:
135 # vim: expandtab shiftwidth=4: