Skip to content

Commit ce1b0f9

Browse files
committed
Improve grammar of options for command arrays in TAP tests
This commit rewrites a good chunk of the command arrays in TAP tests with a grammar based on the following rules: - Fat commas are used between option names and their values, making it clear to both humans and perltidy that values and names are bound together. This is particularly useful for the readability of multi-line command arrays, and there are plenty of them in the TAP tests. Most of the test code is updated to use this style. Some commands used parenthesis to show the link, or attached values and options in a single string. These are updated to use fat commas instead. - Option names are switched to use their long names, making them more self-documented. Based on a suggestion by Andrew Dunstan. - Add some trailing commas after the last item in multi-line arrays, which is a common perl style. Not all the places are taken care of, but this covers a very good chunk of them. Author: Dagfinn Ilmari Mannsåker Reviewed-by: Michael Paquier, Peter Smith, Euler Taveira Discussion: https://postgr.es/m/[email protected]
1 parent 4a0e731 commit ce1b0f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2311
-1318
lines changed

contrib/basebackup_to_shell/t/001_basic.pl

+18-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# This is only needed on Windows machines that don't use UNIX sockets.
2626
$node->init(
2727
'allows_streaming' => 1,
28-
'auth_extra' => [ '--create-role', 'backupuser' ]);
28+
'auth_extra' => [ '--create-role' => 'backupuser' ]);
2929

3030
$node->append_conf('postgresql.conf',
3131
"shared_preload_libraries = 'basebackup_to_shell'");
@@ -37,15 +37,19 @@
3737
# to keep test times reasonable. Using @pg_basebackup_defs as the first
3838
# element of the array passed to IPC::Run interpolate the array (as it is
3939
# not a reference to an array)...
40-
my @pg_basebackup_defs = ('pg_basebackup', '--no-sync', '-cfast');
40+
my @pg_basebackup_defs =
41+
('pg_basebackup', '--no-sync', '--checkpoint' => 'fast');
4142

4243
# This particular test module generally wants to run with -Xfetch, because
4344
# -Xstream is not supported with a backup target, and with -U backupuser.
44-
my @pg_basebackup_cmd = (@pg_basebackup_defs, '-U', 'backupuser', '-Xfetch');
45+
my @pg_basebackup_cmd = (
46+
@pg_basebackup_defs,
47+
'--username' => 'backupuser',
48+
'--wal-method' => 'fetch');
4549

4650
# Can't use this module without setting basebackup_to_shell.command.
4751
$node->command_fails_like(
48-
[ @pg_basebackup_cmd, '--target', 'shell' ],
52+
[ @pg_basebackup_cmd, '--target' => 'shell' ],
4953
qr/shell command for backup is not configured/,
5054
'fails if basebackup_to_shell.command is not set');
5155

@@ -64,13 +68,13 @@
6468

6569
# Should work now.
6670
$node->command_ok(
67-
[ @pg_basebackup_cmd, '--target', 'shell' ],
71+
[ @pg_basebackup_cmd, '--target' => 'shell' ],
6872
'backup with no detail: pg_basebackup');
6973
verify_backup('', $backup_path, "backup with no detail");
7074

7175
# Should fail with a detail.
7276
$node->command_fails_like(
73-
[ @pg_basebackup_cmd, '--target', 'shell:foo' ],
77+
[ @pg_basebackup_cmd, '--target' => 'shell:foo' ],
7478
qr/a target detail is not permitted because the configured command does not include %d/,
7579
'fails if detail provided without %d');
7680

@@ -87,19 +91,19 @@
8791

8892
# Should fail due to lack of permission.
8993
$node->command_fails_like(
90-
[ @pg_basebackup_cmd, '--target', 'shell' ],
94+
[ @pg_basebackup_cmd, '--target' => 'shell' ],
9195
qr/permission denied to use basebackup_to_shell/,
9296
'fails if required_role not granted');
9397

9498
# Should fail due to lack of a detail.
9599
$node->safe_psql('postgres', 'GRANT trustworthy TO backupuser');
96100
$node->command_fails_like(
97-
[ @pg_basebackup_cmd, '--target', 'shell' ],
101+
[ @pg_basebackup_cmd, '--target' => 'shell' ],
98102
qr/a target detail is required because the configured command includes %d/,
99103
'fails if %d is present and detail not given');
100104

101105
# Should work.
102-
$node->command_ok([ @pg_basebackup_cmd, '--target', 'shell:bar' ],
106+
$node->command_ok([ @pg_basebackup_cmd, '--target' => 'shell:bar' ],
103107
'backup with detail: pg_basebackup');
104108
verify_backup('bar.', $backup_path, "backup with detail");
105109

@@ -133,9 +137,11 @@ sub verify_backup
133137
# Verify.
134138
$node->command_ok(
135139
[
136-
'pg_verifybackup', '-n',
137-
'-m', "${backup_dir}/${prefix}backup_manifest",
138-
'-e', $extract_path
140+
'pg_verifybackup',
141+
'--no-parse-wal',
142+
'--manifest-path' => "${backup_dir}/${prefix}backup_manifest",
143+
'--exit-on-error',
144+
$extract_path
139145
],
140146
"$test_name: backup verifies ok");
141147
}

src/bin/initdb/t/001_initdb.pl

+20-16
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@
2222
program_version_ok('initdb');
2323
program_options_handling_ok('initdb');
2424

25-
command_fails([ 'initdb', '-S', "$tempdir/nonexistent" ],
25+
command_fails([ 'initdb', '--sync-only', "$tempdir/nonexistent" ],
2626
'sync missing data directory');
2727

2828
mkdir $xlogdir;
2929
mkdir "$xlogdir/lost+found";
30-
command_fails(
31-
[ 'initdb', '-X', $xlogdir, $datadir ],
30+
command_fails([ 'initdb', '--waldir' => $xlogdir, $datadir ],
3231
'existing nonempty xlog directory');
3332
rmdir "$xlogdir/lost+found";
3433
command_fails(
35-
[ 'initdb', '-X', 'pgxlog', $datadir ],
34+
[ 'initdb', '--waldir' => 'pgxlog', $datadir ],
3635
'relative xlog directory not allowed');
3736

38-
command_fails(
39-
[ 'initdb', '-U', 'pg_test', $datadir ],
37+
command_fails([ 'initdb', '--username' => 'pg_test', $datadir ],
4038
'role names cannot begin with "pg_"');
4139

4240
mkdir $datadir;
@@ -49,12 +47,15 @@
4947
local (%ENV) = %ENV;
5048
delete $ENV{TZ};
5149

52-
# while we are here, also exercise -T and -c options
50+
# while we are here, also exercise --text-search-config and --set options
5351
command_ok(
5452
[
55-
'initdb', '-N', '-T', 'german', '-c',
56-
'default_text_search_config=german',
57-
'-X', $xlogdir, $datadir
53+
'initdb',
54+
'--no-sync',
55+
'--text-search-config' => 'german',
56+
'--set' => 'default_text_search_config=german',
57+
'--waldir' => $xlogdir,
58+
$datadir
5859
],
5960
'successful creation');
6061

@@ -75,17 +76,19 @@
7576
qr/Data page checksum version:.*1/,
7677
'checksums are enabled in control file');
7778

78-
command_ok([ 'initdb', '-S', $datadir ], 'sync only');
79+
command_ok([ 'initdb', '--sync-only', $datadir ], 'sync only');
7980
command_fails([ 'initdb', $datadir ], 'existing data directory');
8081

8182
if ($supports_syncfs)
8283
{
83-
command_ok([ 'initdb', '-S', $datadir, '--sync-method', 'syncfs' ],
84+
command_ok(
85+
[ 'initdb', '--sync-only', $datadir, '--sync-method' => 'syncfs' ],
8486
'sync method syncfs');
8587
}
8688
else
8789
{
88-
command_fails([ 'initdb', '-S', $datadir, '--sync-method', 'syncfs' ],
90+
command_fails(
91+
[ 'initdb', '--sync-only', $datadir, '--sync-method' => 'syncfs' ],
8992
'sync method syncfs');
9093
}
9194

@@ -126,7 +129,7 @@
126129
command_like(
127130
[
128131
'initdb', '--no-sync',
129-
'-A', 'trust',
132+
'-A' => 'trust',
130133
'--locale-provider=icu', '--locale=und',
131134
'--lc-collate=C', '--lc-ctype=C',
132135
'--lc-messages=C', '--lc-numeric=C',
@@ -246,7 +249,8 @@
246249
],
247250
'fails for invalid option combination');
248251

249-
command_fails([ 'initdb', '--no-sync', '--set', 'foo=bar', "$tempdir/dataX" ],
252+
command_fails(
253+
[ 'initdb', '--no-sync', '--set' => 'foo=bar', "$tempdir/dataX" ],
250254
'fails for invalid --set option');
251255

252256
# Make sure multiple invocations of -c parameters are added case insensitive
@@ -279,7 +283,7 @@
279283
# not part of the tests included in pg_checksums to save from
280284
# the creation of an extra instance.
281285
command_fails(
282-
[ 'pg_checksums', '-D', $datadir_nochecksums ],
286+
[ 'pg_checksums', '--pgdata' => $datadir_nochecksums ],
283287
"pg_checksums fails with data checksum disabled");
284288

285289
done_testing();

0 commit comments

Comments
 (0)