aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_waldump/t/001_basic.pl
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2025-01-22 14:47:13 +0900
committerMichael Paquier <michael@paquier.xyz>2025-01-22 14:47:13 +0900
commitce1b0f9da03e1cebc293f60b378079b22bd7cc0f (patch)
tree78c3030de2cc9d201168e8297b5754bf35e37fd2 /src/bin/pg_waldump/t/001_basic.pl
parent4a0e7314f11ee03adfe9df945598c068b4179314 (diff)
downloadpostgresql-ce1b0f9da03e1cebc293f60b378079b22bd7cc0f.tar.gz
postgresql-ce1b0f9da03e1cebc293f60b378079b22bd7cc0f.zip
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/87jzc46d8u.fsf@wibble.ilmari.org
Diffstat (limited to 'src/bin/pg_waldump/t/001_basic.pl')
-rw-r--r--src/bin/pg_waldump/t/001_basic.pl60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl
index 8d574a410cf..5c8fea275bb 100644
--- a/src/bin/pg_waldump/t/001_basic.pl
+++ b/src/bin/pg_waldump/t/001_basic.pl
@@ -21,31 +21,31 @@ command_fails_like(
# invalid option arguments
command_fails_like(
- [ 'pg_waldump', '--block', 'bad' ],
+ [ 'pg_waldump', '--block' => 'bad' ],
qr/error: invalid block number/,
'invalid block number');
command_fails_like(
- [ 'pg_waldump', '--fork', 'bad' ],
+ [ 'pg_waldump', '--fork' => 'bad' ],
qr/error: invalid fork name/,
'invalid fork name');
command_fails_like(
- [ 'pg_waldump', '--limit', 'bad' ],
+ [ 'pg_waldump', '--limit' => 'bad' ],
qr/error: invalid value/,
'invalid limit');
command_fails_like(
- [ 'pg_waldump', '--relation', 'bad' ],
+ [ 'pg_waldump', '--relation' => 'bad' ],
qr/error: invalid relation/,
'invalid relation specification');
command_fails_like(
- [ 'pg_waldump', '--rmgr', 'bad' ],
+ [ 'pg_waldump', '--rmgr' => 'bad' ],
qr/error: resource manager .* does not exist/,
'invalid rmgr name');
command_fails_like(
- [ 'pg_waldump', '--start', 'bad' ],
+ [ 'pg_waldump', '--start' => 'bad' ],
qr/error: invalid WAL location/,
'invalid start LSN');
command_fails_like(
- [ 'pg_waldump', '--end', 'bad' ],
+ [ 'pg_waldump', '--end' => 'bad' ],
qr/error: invalid WAL location/,
'invalid end LSN');
@@ -199,18 +199,24 @@ command_like(
qr/./,
'runs with start and end segment specified');
command_fails_like(
- [ 'pg_waldump', '-p', $node->data_dir ],
+ [ 'pg_waldump', '--path' => $node->data_dir ],
qr/error: no start WAL location given/,
'path option requires start location');
command_like(
[
- 'pg_waldump', '-p', $node->data_dir, '--start',
- $start_lsn, '--end', $end_lsn
+ 'pg_waldump',
+ '--path' => $node->data_dir,
+ '--start' => $start_lsn,
+ '--end' => $end_lsn,
],
qr/./,
'runs with path option and start and end locations');
command_fails_like(
- [ 'pg_waldump', '-p', $node->data_dir, '--start', $start_lsn ],
+ [
+ 'pg_waldump',
+ '--path' => $node->data_dir,
+ '--start' => $start_lsn,
+ ],
qr/error: error in WAL record at/,
'falling off the end of the WAL results in an error');
@@ -222,7 +228,11 @@ command_like(
qr/^$/,
'no output with --quiet option');
command_fails_like(
- [ 'pg_waldump', '--quiet', '-p', $node->data_dir, '--start', $start_lsn ],
+ [
+ 'pg_waldump', '--quiet',
+ '--path' => $node->data_dir,
+ '--start' => $start_lsn
+ ],
qr/error: error in WAL record at/,
'errors are shown with --quiet');
@@ -240,7 +250,8 @@ command_fails_like(
my (@cmd, $stdout, $stderr, $result);
@cmd = (
- 'pg_waldump', '--start', $new_start,
+ 'pg_waldump',
+ '--start' => $new_start,
$node->data_dir . '/pg_wal/' . $start_walfile);
$result = IPC::Run::run \@cmd, '>', \$stdout, '2>', \$stderr;
ok($result, "runs with start segment and start LSN specified");
@@ -258,8 +269,10 @@ sub test_pg_waldump
my (@cmd, $stdout, $stderr, $result, @lines);
@cmd = (
- 'pg_waldump', '-p', $node->data_dir, '--start', $start_lsn, '--end',
- $end_lsn);
+ 'pg_waldump',
+ '--path' => $node->data_dir,
+ '--start' => $start_lsn,
+ '--end' => $end_lsn);
push @cmd, @opts;
$result = IPC::Run::run \@cmd, '>', \$stdout, '2>', \$stderr;
ok($result, "pg_waldump @opts: runs ok");
@@ -274,7 +287,7 @@ my @lines;
@lines = test_pg_waldump;
is(grep(!/^rmgr: \w/, @lines), 0, 'all output lines are rmgr lines');
-@lines = test_pg_waldump('--limit', 6);
+@lines = test_pg_waldump('--limit' => 6);
is(@lines, 6, 'limit option observed');
@lines = test_pg_waldump('--fullpage');
@@ -288,21 +301,20 @@ is(grep(/^rmgr:/, @lines), 0, 'no rmgr lines output');
like($lines[0], qr/WAL statistics/, "statistics on stdout");
is(grep(/^rmgr:/, @lines), 0, 'no rmgr lines output');
-@lines = test_pg_waldump('--rmgr', 'Btree');
+@lines = test_pg_waldump('--rmgr' => 'Btree');
is(grep(!/^rmgr: Btree/, @lines), 0, 'only Btree lines');
-@lines = test_pg_waldump('--fork', 'init');
+@lines = test_pg_waldump('--fork' => 'init');
is(grep(!/fork init/, @lines), 0, 'only init fork lines');
-@lines = test_pg_waldump('--relation',
- "$default_ts_oid/$postgres_db_oid/$rel_t1_oid");
+@lines = test_pg_waldump(
+ '--relation' => "$default_ts_oid/$postgres_db_oid/$rel_t1_oid");
is(grep(!/rel $default_ts_oid\/$postgres_db_oid\/$rel_t1_oid/, @lines),
0, 'only lines for selected relation');
-@lines =
- test_pg_waldump('--relation',
- "$default_ts_oid/$postgres_db_oid/$rel_i1a_oid",
- '--block', 1);
+@lines = test_pg_waldump(
+ '--relation' => "$default_ts_oid/$postgres_db_oid/$rel_i1a_oid",
+ '--block' => 1);
is(grep(!/\bblk 1\b/, @lines), 0, 'only lines for selected block');