summaryrefslogtreecommitdiffstats
path: root/src/interfaces/libpq/test/regress.pl
blob: de705cf5c9f15a7814922bb6b84240220a036566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl

# Copyright (c) 2021, PostgreSQL Global Development Group

use strict;
use warnings;

# 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(my $regress_in_fh, "<", $regress_in)
  or die "can't open $regress_in for reading: $!";

# save STDOUT/ERR and redirect both to regress.out
open(my $oldout_fh, ">&", \*STDOUT) or die "can't dup STDOUT: $!";
open(my $olderr_fh, ">&", \*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_fh>)
{
	chomp;
	print "trying $_\n";
	system("./uri-regress \"$_\"");
	print "\n";
}

# restore STDOUT/ERR so we can print the outcome to the user
open(STDERR, ">&", $olderr_fh)
  or die;    # can't complain as STDERR is still duped
open(STDOUT, ">&", $oldout_fh) or die "can't restore STDOUT: $!";

# just in case
close $regress_in_fh;

my $diff_status = system(
	"diff -c \"$srcdir/$subdir/expected.out\" regress.out >regress.diff");

print "=" x 70, "\n";
if ($diff_status == 0)
{
	print "All tests passed\n";
	exit 0;
}
else
{
	print <<EOF;
FAILED: the test result differs from the expected output

Review the difference in "$subdir/regress.diff"
EOF
	exit 1;
}