[patch] improve versatility and reliability of



Hi --

The following patch should be self-explanatory.
If not, I can provide more details........

commit 97036896b311675bad3615c2767b76ccb0fcea1c
Author: John Denker <jsd av8n com>
Date:   Wed Aug 21 15:09:54 2019 -0700

    allow tests to work a lot better when invoked from
    somewhere other than the test directory,
    e.g. when invoked as ./gnumeric/test/<whatever>.pl

diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 0de6467c4..47c3f8baa 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -23,22 +23,30 @@ $| = 1;
 use vars qw($topsrc $top_builddir $samples $default_subtests $default_corpus $PERL $PYTHON $verbose);
 use vars qw($ssconvert $ssindex $sstest $ssdiff $ssgrep $gnumeric);
 use vars qw($normalize_gnumeric);
+use File::Spec;
+use File::Basename;
 
 $PYTHON = undef;
 
 $PERL = $Config{'perlpath'};
 $PERL .= $Config{'_exe'} if $^O ne 'VMS' && $PERL !~ m/$Config{'_exe'}$/i;
 
-if ($0 eq '-e') {
-    # Running as "perl -e '...'", so no idea about where we are
-    $topsrc = '.';
-} else {
-    $topsrc = $0;
-    $topsrc =~ s|/[^/]+$|/..|;
-    $topsrc =~ s|/test/\.\.$||;
-}
+# Note that if we were invoked via perl -e script, then
+#  $0 will be '-e', and $fullname will be the current directory,
+#  which is a good guess for $topsrc but not guaranteed correct.
+my $fullname =  File::Spec->rel2abs($0);
+
+# directory containing the test script:
+my $dirname  = dirname($fullname);
+
+# Assuming we are in the gnumeric/test directory,
+# the parent thereof should be the gnumeric directory:
+$topsrc = $dirname;
+$topsrc =~ s'/test/?$'';        # otherwise just use the current directory
+
+# AFAICT this is just another name for the same thing:
+$top_builddir = $topsrc;
 
-$top_builddir = "..";
 $samples = "$topsrc/samples"; $samples =~ s{^\./+}{};
 $ssconvert = "$top_builddir/src/ssconvert";
 $ssindex = "$top_builddir/src/ssindex";
@@ -680,7 +688,7 @@ sub test_roundtrip {
        die "Failed to produce $file_filtered\n" unless -r $file_filtered;
        &junkfile ($file_filtered) unless $keep;
     }
-    
+
     my $tmp1 = "$tmp.$newext";
     unlink $tmp1;
     &junkfile ($tmp1) unless $keep;
@@ -927,7 +935,7 @@ sub setup_python_environment {
     $ENV{$v} = ($ENV{$v} || '') eq '' ? $dir : $dir . ':' . $ENV{$v};
 
     $ENV{'PYTHONPATH'} = "$topsrc/introspection";
-    
+
     # Don't litter
     $ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]