| 1 |
# pg_bsd_indent: some simple tests |
| 2 |
|
| 3 |
# The test cases come from FreeBSD upstream, but this test scaffolding is ours. |
| 4 |
# Copyright (c) 2017-2025, PostgreSQL Global Development Group |
| 5 |
|
| 6 |
use strict; |
| 7 |
use warnings FATAL => 'all'; |
| 8 |
|
| 9 |
use Cwd qw(getcwd); |
| 10 |
use File::Copy "cp"; |
| 11 |
use File::Spec; |
| 12 |
|
| 13 |
use PostgreSQL::Test::Utils; |
| 14 |
use Test::More; |
| 15 |
|
| 16 |
# We expect to be started in the source directory (even in a VPATH build); |
| 17 |
# we want to run pg_bsd_indent in the tmp_check directory to reduce clutter. |
| 18 |
# (Also, it's caller's responsibility that pg_bsd_indent be in the PATH.) |
| 19 |
my $src_dir = getcwd; |
| 20 |
chdir ${PostgreSQL::Test::Utils::tmp_check}; |
| 21 |
|
| 22 |
# Basic tests: pg_bsd_indent knows --version but not much else. |
| 23 |
program_version_ok('pg_bsd_indent'); |
| 24 |
|
| 25 |
# Run pg_bsd_indent on pre-fab test cases. |
| 26 |
# Any diffs in the generated files will be accumulated here. |
| 27 |
my $diffs_file = "test.diffs"; |
| 28 |
|
| 29 |
# options used with diff (see pg_regress.c's pretty_diff_opts) |
| 30 |
my @diffopts = ("-U3"); |
| 31 |
push(@diffopts, "--strip-trailing-cr") if $windows_os; |
| 32 |
|
| 33 |
# Copy support files to current dir, so *.pro files don't need to know path. |
| 34 |
while (my $file = glob("$src_dir/tests/*.list")) |
| 35 |
{ |
| 36 |
cp($file, ".") || die "cp $file failed: $!"; |
| 37 |
} |
| 38 |
|
| 39 |
while (my $test_src = glob("$src_dir/tests/*.0")) |
| 40 |
{ |
| 41 |
# extract test basename |
| 42 |
my ($volume, $directories, $test) = File::Spec->splitpath($test_src); |
| 43 |
$test =~ s/\.0$//; |
| 44 |
# run pg_bsd_indent |
| 45 |
command_ok( |
| 46 |
[ |
| 47 |
'pg_bsd_indent', $test_src, |
| 48 |
"$test.out", "-P$src_dir/tests/$test.pro" |
| 49 |
], |
| 50 |
"pg_bsd_indent succeeds on $test"); |
| 51 |
# check result matches, adding any diff to $diffs_file |
| 52 |
my $result = |
| 53 |
run_log([ 'diff', @diffopts, "$test_src.stdout", "$test.out" ], |
| 54 |
'>>' => $diffs_file); |
| 55 |
ok($result, "pg_bsd_indent output matches for $test"); |
| 56 |
} |
| 57 |
|
| 58 |
done_testing(); |