Cleanup a bit the environment handling around the testsuite.

Upstream status: Submitted 060427

---
 Makefile.in |    9 +--------
 test/run    |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 8 deletions(-)

--- a/test/run
+++ b/test/run
@@ -80,6 +80,26 @@ if (defined $ARGV[0]) {
 	*SOURCE = *STDIN;
 }
 
+# cleanup the environment
+map { 
+  undef $ENV{$_} if defined($ENV{$_}); 
+} qw(QUILT_PATCHES QUILT_PC LANG LC_MESSAGES LC_CTYPE LC_ALL LANGUAGE);
+
+$ENV{'LC_ALL'} = 'C';
+open RC,"test.quiltrc" || die "cannot read RC file: $?\n";
+while (<RC>) {
+    s/#.*$//;
+    if (m/^([^=]*)=(.*)$/) {
+	$ENV{$1}=$2;
+    }
+}
+
+if (defined($ENV{'QUILT_PATCHES_PREFIX'}) && length($ENV{'QUILT_PATCHES_PREFIX'})) {
+    $ENV{'P'}='patches/';
+    $ENV{'_P'}='../patches/';
+}
+
+# Run the tests
 for (;;) {
   my $line = <SOURCE>; $lineno++;
   if (defined $line) {
--- a/Makefile.in
+++ b/Makefile.in
@@ -381,20 +381,13 @@ test/.depend : Makefile $(TESTS)
 	    -e 's:quilt/setup:quilt/setup quilt/scripts/inspect:' \
 	  > $@
 
-ifneq ($(shell . $(QUILTRC) ;  echo $$QUILT_PATCHES_PREFIX),)
-CHECK_ENV := P=patches/; _P=../patches/; export P _P
-endif
-
 # Each tests dependencies are stored in test/.depend
 ifneq ($(findstring check-,$(MAKECMDGOALS)),)
 test/.%.ok : test/%.test FORCE
 else
 test/.%.ok : test/%.test
 endif
-	@LANG=C; LC_ALL=C;						\
-	export LANG LC_ALL;						\
-	$(CHECK_ENV);							\
-	cd $(@D);							\
+	@cd $(@D);							\
 	./run -q $(<F)
 	@touch $@
 
