[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / t / configure / 061-revision_from_cache.t
blob8c489a9b020c519efbb568f570c2b7b5009411c9
1 #! perl
2 # Copyright (C) 2007, Parrot Foundation.
3 # $Id$
4 # 061-revision_from_cache.t
6 use strict;
7 use warnings;
9 use Test::More;
10 plan( skip_all =>
11     "\nRelevant only when working in checkout from repository and during configuration" )
12     unless (-e 'DEVELOPING' and ! -e 'Makefile');
13 plan( tests => 25 );
14 use Carp;
15 use Cwd;
16 use File::Copy;
17 use File::Path ();
18 use File::Temp qw| tempdir |;
19 use lib qw( lib );
20 use Parrot::Revision ();
22 my $cwd = cwd();
23 {   # revision undef
24     my $rev = 16000;
25     my ($cache, $libdir) = setup_cache($rev, $cwd);
26     my $prev = 34567;
27     my $revision = undef;
28     my $current = 12345;
29     my $ret = Parrot::Revision::_handle_update( {
30         prev        => $prev,
31         revision    => $revision,
32         cache       => $cache,
33         current     => $current,
34     } );
35     is($ret, q{unknown}, "Got expected return value from _handle_update");
36     unlink qq{$libdir/Parrot/Revision.pm}
37         or croak "Unable to delete file after testing";
38     ok( chdir $cwd, "Able to change back to starting directory");
41 {   # prev undef
42     my $rev = 16000;
43     my ($cache, $libdir) = setup_cache($rev, $cwd);
44     my $revision = 67890;
45     my $current = 12345;
46     my $ret = Parrot::Revision::_handle_update( {
47         prev        => undef,
48         revision    => $revision,
49         cache       => $cache,
50         current     => $current,
51     } );
52     is($ret, $current, "Got expected return value from _handle_update");
53     unlink qq{$libdir/Parrot/Revision.pm}
54         or croak "Unable to delete file after testing";
55     ok( chdir $cwd, "Able to change back to starting directory");
58 {   # prev and revision both defined and identical
59     my $rev = 16000;
60     my ($cache, $libdir) = setup_cache($rev, $cwd);
61     my $prev = 67890;
62     my $revision = 67890;
63     my $current = 12345;
64     my $ret = Parrot::Revision::_handle_update( {
65         prev        => $prev,
66         revision    => $revision,
67         cache       => $cache,
68         current     => $current,
69     } );
70     is($ret, $current, "Got expected return value from _handle_update");
71     unlink qq{$libdir/Parrot/Revision.pm}
72         or croak "Unable to delete file after testing";
73     ok( chdir $cwd, "Able to change back to starting directory");
76 {   # prev and revision both defined but not  identical
77     my $rev = 16000;
78     my ($cache, $libdir) = setup_cache($rev, $cwd);
79     my $prev = 67890;
80     my $revision = 67891;
81     my $current = 12345;
82     my $ret = Parrot::Revision::_handle_update( {
83         prev        => $prev,
84         revision    => $revision,
85         cache       => $cache,
86         current     => $current,
87     } );
88     is($ret, $revision, "Got expected return value from _handle_update");
89     unlink qq{$libdir/Parrot/Revision.pm}
90         or croak "Unable to delete file after testing";
91     ok( chdir $cwd, "Able to change back to starting directory");
94 pass("Completed all tests in $0");
97 ##### SUBROUTINES #####
99 sub setup_cache {
100     my ($rev, $cwd) = @_;
101     my $tdir = tempdir( CLEANUP => 1 );
102     ok( chdir $tdir, "Changed to temporary directory for testing" );
103     my $libdir = qq{$tdir/lib};
104     ok( (File::Path::mkpath( [ $libdir ], 0, 0777 )), "Able to make libdir");
105     local @INC;
106     unshift @INC, $libdir;
107     ok( (File::Path::mkpath( [ qq{$libdir/Parrot} ], 0, 0777 )), "Able to make Parrot dir");
108     ok( (copy qq{$cwd/lib/Parrot/Revision.pm},
109             qq{$libdir/Parrot}), "Able to copy Parrot::Revision");
110     my $cache = q{.parrot_current_rev};
111     open my $FH, ">", $cache
112         or croak "Unable to open $cache for writing";
113     print $FH qq{$rev\n};
114     close $FH or croak "Unable to close $cache after writing";
115     return ($cache, $libdir);
118 ################### DOCUMENTATION ###################
120 =head1 NAME
122 061-revision_from_cache.t - test Parrot::Revision
124 =head1 SYNOPSIS
126     % prove t/configure/061-revision_from_cache.t
128 =head1 DESCRIPTION
130 The files in this directory test functionality used by F<Configure.pl>.
132 The tests in this file test Parrot::Revision (F<lib/Parrot/Revision.pm>).
134 =head1 AUTHOR
136 James E Keenan
138 =head1 SEE ALSO
140 Parrot::Configure, F<Configure.pl>.
142 =cut
144 # Local Variables:
145 #   mode: cperl
146 #   cperl-indent-level: 4
147 #   fill-column: 100
148 # End:
149 # vim: expandtab shiftwidth=4: