forked from darold/pgFormatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regress_test.pl
51 lines (46 loc) · 1.31 KB
/
regress_test.pl
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
my @files = `find samples/ -maxdepth 1 -name '*.sql' | sort`;
chomp(@files);
foreach my $f (@files) {
print "Running test on file $f...\n";
my $opt = '';
$opt = "-S '\$f\$'" if ($f =~ m#/ex19.sql$#);
$opt = "-W 4" if ($f =~ m#/ex46.sql$#);
$opt .= ' -t' if (grep(/^-t/, @ARGV));
my $cmd = "./pg_format $opt -u 2 $f >/tmp/output.sql";
`$cmd`;
$f =~ s/\//\/expected\//;
if (lc($ARGV[0]) eq 'update') {
`cp -f /tmp/output.sql $f`;
} else {
my @diff = `diff -u /tmp/output.sql $f | grep "^[+-]" | grep -v "^[+-]\t\$" | grep -v "^[+-][+-][+-]"`;
if ($#diff < 0) {
print "\ttest ok.\n";
} else {
print "\ttest failed!!!\n";
print @diff;
}
}
unlink("/tmp/output.sql");
}
@files = `find pg-test-files/sql/ -maxdepth 1 -name '*.sql' | sort`;
chomp(@files);
foreach my $f (@files) {
print "Running test on file $f...\n";
my $opt = '';
$opt .= ' -t' if (grep(/^-t/, @ARGV));
my $cmd = "./pg_format $opt -u 2 $f >/tmp/output.sql";
`$cmd`;
$f =~ s/\/sql\//\/expected\//;
if (lc($ARGV[0]) eq 'update') {
`cp -f /tmp/output.sql $f`;
} else {
my @diff = `diff -u /tmp/output.sql $f | grep "^[+-]" | grep -v "^[+-]\$" | grep -v "^[+-]\t\$" | grep -v "^[+-][+-][+-]"`;
if ($#diff < 0) {
print "\ttest ok.\n";
} else {
print "\ttest failed!!!\n";
print @diff;
}
}
unlink("/tmp/output.sql");
}