This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Set GIT_DIR instead of changing directory in find_git_or_skip() in test.pl
authorNicholas Clark <nick@ccl4.org>
Tue, 5 Jun 2012 13:55:22 +0000 (15:55 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 18 Jun 2012 12:15:41 +0000 (14:15 +0200)
Return the directory of the source tree, so that tests can change directory
to it if necessary. Modify t/porting/cmp_version.t to change directory.

This gets t/porting/utils.t passing again under -Dmksymlinks, without breaking
t/porting/cmp_version.t. The former needs to run in the build tree as it
inspects various build products. The latter needs to run in the (real)
checkout tree, else it thinks that every single file has changed (into a
symlink).

t/porting/cmp_version.t
t/test.pl

index 6204c57..e7627e4 100644 (file)
@@ -12,6 +12,7 @@ use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute
 use strict;
 
 require 't/test.pl';
-find_git_or_skip('all');
+my $source = find_git_or_skip('all');
+chdir $source or die "Can't chdir to $source: $!";
 
 system "$^X Porting/cmpVERSION.pl --exclude --tap";
index b33c634..9d1da29 100644 (file)
--- a/t/test.pl
+++ b/t/test.pl
@@ -153,9 +153,9 @@ sub skip_all_without_config {
 }
 
 sub find_git_or_skip {
-    my ($found_dir, $reason);
+    my ($source_dir, $reason);
     if (-d '.git') {
-       $found_dir = 1;
+       $source_dir = '.';
     } elsif (-l 'MANIFEST' && -l 'AUTHORS') {
        my $where = readlink 'MANIFEST';
        die "Can't readling MANIFEST: $!" unless defined $where;
@@ -163,16 +163,20 @@ sub find_git_or_skip {
            unless $where =~ s!/MANIFEST\z!!;
        if (-d "$where/.git") {
            # Looks like we are in a symlink tree
-           chdir $where or die "Can't chdir '$where': $!";
-           note("Found source tree at $where");
-           $found_dir = 1;
+           if (exists $ENV{GIT_DIR}) {
+               diag("Found source tree at $where, but \$ENV{GIT_DIR} is $ENV{GIT_DIR}. Not changing it");
+           } else {
+               note("Found source tree at $where, setting \$ENV{GIT_DIR}");
+               $ENV{GIT_DIR} = "$where/.git";
+           }
+           $source_dir = $where;
        }
     }
-    if ($found_dir) {
+    if ($source_dir) {
        my $version_string = `git --version`;
        if (defined $version_string
              && $version_string =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
-           return if eval "v$1 ge v1.5.0";
+           return $source_dir if eval "v$1 ge v1.5.0";
            # If you have earlier than 1.5.0 and it works, change this test
            $reason = "in git checkout, but git version '$1$2' too old";
        } else {