diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-06 15:38:11 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2012-07-06 16:45:48 -0400 |
commit | a184e4db83c80d28103774ced984c7790fbd44ba (patch) | |
tree | edf2f2687d92e77ba697d16ad0c1c97cbdb5014a | |
parent | adb9b7d53be5a3a0cae8b7a71c28a3e8c7628769 (diff) | |
download | postgresql-a184e4db83c80d28103774ced984c7790fbd44ba.tar.gz postgresql-a184e4db83c80d28103774ced984c7790fbd44ba.zip |
Convert libpq regress script to Perl
This should ease its use on the Windows build environment.
-rw-r--r-- | src/interfaces/libpq/test/Makefile | 2 | ||||
-rw-r--r-- | src/interfaces/libpq/test/regress.pl | 62 | ||||
-rw-r--r-- | src/interfaces/libpq/test/regress.sh | 21 |
3 files changed, 63 insertions, 22 deletions
diff --git a/src/interfaces/libpq/test/Makefile b/src/interfaces/libpq/test/Makefile index b9023c37f32..ab41dc33a6c 100644 --- a/src/interfaces/libpq/test/Makefile +++ b/src/interfaces/libpq/test/Makefile @@ -15,7 +15,7 @@ all: $(PROGS) installcheck: all SRCDIR='$(top_srcdir)' SUBDIR='$(subdir)' \ - $(SHELL) $(top_srcdir)/$(subdir)/regress.sh + $(PERL) $(top_srcdir)/$(subdir)/regress.pl clean distclean maintainer-clean: rm -f $(PROGS) diff --git a/src/interfaces/libpq/test/regress.pl b/src/interfaces/libpq/test/regress.pl new file mode 100644 index 00000000000..f2fee620da8 --- /dev/null +++ b/src/interfaces/libpq/test/regress.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl -w + +use strict; + +# use of SRCDIR/SUBDIR is required for supporting VPath builds +my $srcdir = $ENV{'SRCDIR'} or die 'SRCDIR environment variable is not set'; +my $subdir = $ENV{'SUBDIR'} or die 'SUBDIR environment variable is not set'; + +my $regress_in = "$srcdir/$subdir/regress.in"; +my $expected_out = "$srcdir/$subdir/expected.out"; + +# the output file should land in the build_dir of VPath, or just in +# the current dir, if VPath isn't used +my $regress_out = "regress.out"; + +# open input file first, so possible error isn't sent to redirected STDERR +open(REGRESS_IN, "<", $regress_in) + or die "can't open $regress_in for reading: $!"; + +# save STDOUT/ERR and redirect both to regress.out +open(OLDOUT, ">&", \*STDOUT) or die "can't dup STDOUT: $!"; +open(OLDERR, ">&", \*STDERR) or die "can't dup STDERR: $!"; + +open(STDOUT, ">", $regress_out) + or die "can't open $regress_out for writing: $!"; +open(STDERR, ">&", \*STDOUT) or die "can't dup STDOUT: $!"; + +# read lines from regress.in and run uri-regress on them +while (<REGRESS_IN>) + { + chomp; + print "trying $_\n"; + system("./uri-regress \"$_\""); + print "\n"; +} + +# restore STDOUT/ERR so we can print the outcome to the user +open(STDERR, ">&", \*OLDERR) or die; # can't complain as STDERR is still duped +open(STDOUT, ">&", \*OLDOUT) or die "Can't restore STDOUT: $!"; + +# just in case +close REGRESS_IN; + +my $diff_status = system( + "diff -c \"$srcdir/$subdir/expected.out\" regress.out >regress.diff"); +if ($diff_status == 0) + { + print "=" x 70, "\n"; + print "All tests passed\n"; + exit 0; +} +else + { + print "=" x 70, "\n"; + print <<EOF; +FAILED: the test result differs from the expected output + +Review the difference in "$subdir/regress.diff" +EOF + print "=" x 70, "\n"; + exit 1; +} diff --git a/src/interfaces/libpq/test/regress.sh b/src/interfaces/libpq/test/regress.sh deleted file mode 100644 index 298d8bdc4a2..00000000000 --- a/src/interfaces/libpq/test/regress.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -while read line -do - echo "trying $line" - ./uri-regress "$line" - echo "" -done < "${SRCDIR}/${SUBDIR}"/regress.in >regress.out 2>&1 - -if diff -c "${SRCDIR}/${SUBDIR}/"expected.out regress.out >regress.diff; then - echo "========================================" - echo "All tests passed" - exit 0 -else - echo "========================================" - echo "FAILED: the test result differs from the expected output" - echo - echo "Review the difference in ${SUBDIR}/regress.diff" - echo "========================================" - exit 1 -fi |