diff options
author | Michael Paquier <michael@paquier.xyz> | 2025-01-22 14:47:13 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2025-01-22 14:47:13 +0900 |
commit | ce1b0f9da03e1cebc293f60b378079b22bd7cc0f (patch) | |
tree | 78c3030de2cc9d201168e8297b5754bf35e37fd2 /src/bin/scripts/t/020_createdb.pl | |
parent | 4a0e7314f11ee03adfe9df945598c068b4179314 (diff) |
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/scripts/t/020_createdb.pl')
-rw-r--r-- | src/bin/scripts/t/020_createdb.pl | 216 |
1 files changed, 145 insertions, 71 deletions
diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl index 191c7885a8d..a8293390ede 100644 --- a/src/bin/scripts/t/020_createdb.pl +++ b/src/bin/scripts/t/020_createdb.pl @@ -21,7 +21,13 @@ $node->issues_sql_like( qr/statement: CREATE DATABASE foobar1/, 'SQL CREATE DATABASE run'); $node->issues_sql_like( - [ 'createdb', '-l', 'C', '-E', 'LATIN1', '-T', 'template0', 'foobar2' ], + [ + 'createdb', + '--locale' => 'C', + '--encoding' => 'LATIN1', + '--template' => 'template0', + 'foobar2', + ], qr/statement: CREATE DATABASE foobar2 ENCODING 'LATIN1'/, 'create database with encoding'); @@ -32,35 +38,45 @@ if ($ENV{with_icu} eq 'yes') # provider. XXX Maybe split into multiple tests? $node->command_fails( [ - 'createdb', '-T', 'template0', '-E', 'UTF8', - '--locale-provider=icu', 'foobar4' + 'createdb', + '--template' => 'template0', + '--encoding' => 'UTF8', + '--locale-provider' => 'icu', + 'foobar4', ], 'create database with ICU fails without ICU locale specified'); $node->issues_sql_like( [ - 'createdb', '-T', - 'template0', '-E', - 'UTF8', '--locale-provider=icu', - '--locale=C', '--icu-locale=en', - 'foobar5' + 'createdb', + '--template' => 'template0', + '--encoding' => 'UTF8', + '--locale-provider' => 'icu', + '--locale' => 'C', + '--icu-locale' => 'en', + 'foobar5', ], qr/statement: CREATE DATABASE foobar5 .* LOCALE_PROVIDER icu ICU_LOCALE 'en'/, 'create database with ICU locale specified'); $node->command_fails( [ - 'createdb', '-T', 'template0', '-E', 'UTF8', - '--locale-provider=icu', - '--icu-locale=@colNumeric=lower', 'foobarX' + 'createdb', + '--template' => 'template0', + '--encoding' => 'UTF8', + '--locale-provider' => 'icu', + '--icu-locale' => '@colNumeric=lower', + 'foobarX', ], 'fails for invalid ICU locale'); $node->command_fails_like( [ - 'createdb', '-T', - 'template0', '--locale-provider=icu', - '--encoding=SQL_ASCII', 'foobarX' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'icu', + '--encoding' => 'SQL_ASCII', + 'foobarX', ], qr/ERROR: encoding "SQL_ASCII" is not supported with ICU provider/, 'fails for encoding not supported by ICU'); @@ -72,116 +88,144 @@ if ($ENV{with_icu} eq 'yes') $node2->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider=libc', - 'foobar55' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'libc', + 'foobar55', ], 'create database with libc provider from template database with icu provider' ); $node2->command_ok( [ - 'createdb', '-T', 'template0', '--icu-locale', 'en-US', - 'foobar56' + 'createdb', + '--template' => 'template0', + '--icu-locale' => 'en-US', + 'foobar56', ], 'create database with icu locale from template database with icu provider' ); $node2->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider', - 'icu', '--locale', - 'en', '--lc-collate', - 'C', '--lc-ctype', - 'C', 'foobar57' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'icu', + '--locale' => 'en', + '--lc-collate' => 'C', + '--lc-ctype' => 'C', + 'foobar57', ], 'create database with locale as ICU locale'); } else { $node->command_fails( - [ 'createdb', '-T', 'template0', '--locale-provider=icu', 'foobar4' ], + [ + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'icu', + 'foobar4', + ], 'create database with ICU fails since no ICU support'); } $node->command_fails( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - 'tbuiltin1' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + 'tbuiltin1', ], 'create database with provider "builtin" fails without --locale'); $node->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--locale=C', 'tbuiltin2' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--locale' => 'C', + 'tbuiltin2', ], 'create database with provider "builtin" and locale "C"'); $node->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--locale=C', '--lc-collate=C', - 'tbuiltin3' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--locale' => 'C', + '--lc-collate' => 'C', + 'tbuiltin3', ], 'create database with provider "builtin" and LC_COLLATE=C'); $node->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--locale=C', '--lc-ctype=C', - 'tbuiltin4' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--locale' => 'C', + '--lc-ctype' => 'C', + 'tbuiltin4', ], 'create database with provider "builtin" and LC_CTYPE=C'); $node->command_ok( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--lc-collate=C', '--lc-ctype=C', - '-E UTF-8', '--builtin-locale=C.UTF8', - 'tbuiltin5' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--lc-collate' => 'C', + '--lc-ctype' => 'C', + '--encoding' => 'UTF-8', + '--builtin-locale' => 'C.UTF8', + 'tbuiltin5', ], 'create database with --builtin-locale C.UTF-8 and -E UTF-8'); $node->command_fails( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--lc-collate=C', '--lc-ctype=C', - '-E LATIN1', '--builtin-locale=C.UTF-8', - 'tbuiltin6' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--lc-collate' => 'C', + '--lc-ctype' => 'C', + '--encoding' => 'LATIN1', + '--builtin-locale' => 'C.UTF-8', + 'tbuiltin6', ], 'create database with --builtin-locale C.UTF-8 and -E LATIN1'); $node->command_fails( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--locale=C', '--icu-locale=en', - 'tbuiltin7' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--locale' => 'C', + '--icu-locale' => 'en', + 'tbuiltin7', ], 'create database with provider "builtin" and ICU_LOCALE="en"'); $node->command_fails( [ - 'createdb', '-T', - 'template0', '--locale-provider=builtin', - '--locale=C', '--icu-rules=""', - 'tbuiltin8' + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'builtin', + '--locale' => 'C', + '--icu-rules' => '""', + 'tbuiltin8', ], 'create database with provider "builtin" and ICU_RULES=""'); $node->command_fails( [ - 'createdb', '-T', - 'template1', '--locale-provider=builtin', - '--locale=C', 'tbuiltin9' + 'createdb', + '--template' => 'template1', + '--locale-provider' => 'builtin', + '--locale' => 'C', + 'tbuiltin9', ], 'create database with provider "builtin" not matching template'); @@ -189,7 +233,12 @@ $node->command_fails([ 'createdb', 'foobar1' ], 'fails if database already exists'); $node->command_fails( - [ 'createdb', '-T', 'template0', '--locale-provider=xyz', 'foobarX' ], + [ + 'createdb', + '--template' => 'template0', + '--locale-provider' => 'xyz', + 'foobarX', + ], 'fails for invalid locale provider'); # Check use of templates with shared dependencies copied from the template. @@ -200,7 +249,7 @@ CREATE TABLE tab_foobar (id int); ALTER TABLE tab_foobar owner to role_foobar; CREATE POLICY pol_foobar ON tab_foobar FOR ALL TO role_foobar;'); $node->issues_sql_like( - [ 'createdb', '-l', 'C', '-T', 'foobar2', 'foobar3' ], + [ 'createdb', '--locale' => 'C', '--template' => 'foobar2', 'foobar3' ], qr/statement: CREATE DATABASE foobar3 TEMPLATE foobar2 LOCALE 'C'/, 'create database with template'); ($ret, $stdout, $stderr) = $node->psql( @@ -228,7 +277,7 @@ $node->command_checks_all( 1, [qr/^$/], [ - qr/^createdb: error: database creation failed: ERROR: invalid LC_COLLATE locale name|^createdb: error: database creation failed: ERROR: new collation \(foo'; SELECT '1\) is incompatible with the collation of the template database/s + qr/^createdb: error: database creation failed: ERROR: invalid LC_COLLATE locale name|^createdb: error: database creation failed: ERROR: new collation \(foo'; SELECT '1\) is incompatible with the collation of the template database/s, ], 'createdb with incorrect --lc-collate'); $node->command_checks_all( @@ -236,7 +285,7 @@ $node->command_checks_all( 1, [qr/^$/], [ - qr/^createdb: error: database creation failed: ERROR: invalid LC_CTYPE locale name|^createdb: error: database creation failed: ERROR: new LC_CTYPE \(foo'; SELECT '1\) is incompatible with the LC_CTYPE of the template database/s + qr/^createdb: error: database creation failed: ERROR: invalid LC_CTYPE locale name|^createdb: error: database creation failed: ERROR: new LC_CTYPE \(foo'; SELECT '1\) is incompatible with the LC_CTYPE of the template database/s, ], 'createdb with incorrect --lc-ctype'); @@ -245,34 +294,59 @@ $node->command_checks_all( 1, [qr/^$/], [ - qr/^createdb: error: database creation failed: ERROR: invalid create database strategy "foo"/s + qr/^createdb: error: database creation failed: ERROR: invalid create database strategy "foo"/s, ], 'createdb with incorrect --strategy'); # Check database creation strategy $node->issues_sql_like( - [ 'createdb', '-T', 'foobar2', '-S', 'wal_log', 'foobar6' ], + [ + 'createdb', + '--template' => 'foobar2', + '--strategy' => 'wal_log', + 'foobar6', + ], qr/statement: CREATE DATABASE foobar6 STRATEGY wal_log TEMPLATE foobar2/, 'create database with WAL_LOG strategy'); $node->issues_sql_like( - [ 'createdb', '-T', 'foobar2', '-S', 'WAL_LOG', 'foobar6s' ], + [ + 'createdb', + '--template' => 'foobar2', + '--strategy' => 'WAL_LOG', + 'foobar6s', + ], qr/statement: CREATE DATABASE foobar6s STRATEGY "WAL_LOG" TEMPLATE foobar2/, 'create database with WAL_LOG strategy'); $node->issues_sql_like( - [ 'createdb', '-T', 'foobar2', '-S', 'file_copy', 'foobar7' ], + [ + 'createdb', + '--template' => 'foobar2', + '--strategy' => 'file_copy', + 'foobar7', + ], qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/, 'create database with FILE_COPY strategy'); $node->issues_sql_like( - [ 'createdb', '-T', 'foobar2', '-S', 'FILE_COPY', 'foobar7s' ], + [ + 'createdb', + '--template' => 'foobar2', + '--strategy' => 'FILE_COPY', + 'foobar7s', + ], qr/statement: CREATE DATABASE foobar7s STRATEGY "FILE_COPY" TEMPLATE foobar2/, 'create database with FILE_COPY strategy'); # Create database owned by role_foobar. $node->issues_sql_like( - [ 'createdb', '-T', 'foobar2', '-O', 'role_foobar', 'foobar8' ], + [ + 'createdb', + '--template' => 'foobar2', + '--owner' => 'role_foobar', + 'foobar8', + ], qr/statement: CREATE DATABASE foobar8 OWNER role_foobar TEMPLATE foobar2/, 'create database with owner role_foobar'); ($ret, $stdout, $stderr) = |