2 # Copyright (C) 2007, Parrot Foundation.
4 # 061-revision_from_cache.t
11 "\nRelevant only when working in checkout from repository and during configuration" )
12 unless (-e 'DEVELOPING' and ! -e 'Makefile');
18 use File::Temp qw| tempdir |;
20 use Parrot::Revision ();
25 my ($cache, $libdir) = setup_cache($rev, $cwd);
29 my $ret = Parrot::Revision::_handle_update( {
31 revision => $revision,
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");
43 my ($cache, $libdir) = setup_cache($rev, $cwd);
46 my $ret = Parrot::Revision::_handle_update( {
48 revision => $revision,
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
60 my ($cache, $libdir) = setup_cache($rev, $cwd);
64 my $ret = Parrot::Revision::_handle_update( {
66 revision => $revision,
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
78 my ($cache, $libdir) = setup_cache($rev, $cwd);
82 my $ret = Parrot::Revision::_handle_update( {
84 revision => $revision,
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 #####
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");
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 ###################
122 061-revision_from_cache.t - test Parrot::Revision
126 % prove t/configure/061-revision_from_cache.t
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>).
140 Parrot::Configure, F<Configure.pl>.
146 # cperl-indent-level: 4
149 # vim: expandtab shiftwidth=4: