From 0432490d290f679cad773ce4735e8769e2c4db75 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Wed, 4 May 2022 14:15:25 +0200 Subject: Rename libpq test programs with libpq_ prefix The testclient and uri-regress programs in the libpq test suite had quite generic names which didn't convey much meaning. Since they are installed as part of the MSVC test runs, ensure that their purpose is a little bit clearer by renaming with a libpq_ prefix. While at it rename uri-regress to uri_regress to avoid mixing dash and under- score in the same filename. Reported-by: Noah Misch Discussion: https://postgr.es/m/20220501080706.GA1542365@rfd.leadboat.com --- src/interfaces/libpq/t/001_uri.pl | 30 +++++----- src/interfaces/libpq/t/002_api.pl | 2 +- src/interfaces/libpq/test/.gitignore | 4 +- src/interfaces/libpq/test/Makefile | 2 +- src/interfaces/libpq/test/libpq_testclient.c | 37 ++++++++++++ src/interfaces/libpq/test/libpq_uri_regress.c | 84 +++++++++++++++++++++++++++ src/interfaces/libpq/test/testclient.c | 37 ------------ src/interfaces/libpq/test/uri-regress.c | 84 --------------------------- src/tools/msvc/Mkvcbuild.pm | 8 +-- 9 files changed, 144 insertions(+), 144 deletions(-) create mode 100644 src/interfaces/libpq/test/libpq_testclient.c create mode 100644 src/interfaces/libpq/test/libpq_uri_regress.c delete mode 100644 src/interfaces/libpq/test/testclient.c delete mode 100644 src/interfaces/libpq/test/uri-regress.c (limited to 'src') diff --git a/src/interfaces/libpq/t/001_uri.pl b/src/interfaces/libpq/t/001_uri.pl index 1d595c05292..beaf13b49ca 100644 --- a/src/interfaces/libpq/t/001_uri.pl +++ b/src/interfaces/libpq/t/001_uri.pl @@ -72,7 +72,7 @@ my @tests = ( ], [ q{postgresql://host/db?u%7aer=someotheruser&port=12345}, q{}, - q{uri-regress: invalid URI query parameter: "uzer"}, + q{libpq_uri_regress: invalid URI query parameter: "uzer"}, ], [ q{postgresql://host:12345?user=uri-user}, @@ -114,63 +114,63 @@ my @tests = ( ], [ q{postgresql://host?uzer=}, q{}, - q{uri-regress: invalid URI query parameter: "uzer"}, + q{libpq_uri_regress: invalid URI query parameter: "uzer"}, ], [ q{postgre://}, q{}, - q{uri-regress: missing "=" after "postgre://" in connection info string}, + q{libpq_uri_regress: missing "=" after "postgre://" in connection info string}, ], [ q{postgres://[::1}, q{}, - q{uri-regress: end of string reached when looking for matching "]" in IPv6 host address in URI: "postgres://[::1"}, + q{libpq_uri_regress: end of string reached when looking for matching "]" in IPv6 host address in URI: "postgres://[::1"}, ], [ q{postgres://[]}, q{}, - q{uri-regress: IPv6 host address may not be empty in URI: "postgres://[]"}, + q{libpq_uri_regress: IPv6 host address may not be empty in URI: "postgres://[]"}, ], [ q{postgres://[::1]z}, q{}, - q{uri-regress: unexpected character "z" at position 17 in URI (expected ":" or "/"): "postgres://[::1]z"}, + q{libpq_uri_regress: unexpected character "z" at position 17 in URI (expected ":" or "/"): "postgres://[::1]z"}, ], [ q{postgresql://host?zzz}, q{}, - q{uri-regress: missing key/value separator "=" in URI query parameter: "zzz"}, + q{libpq_uri_regress: missing key/value separator "=" in URI query parameter: "zzz"}, ], [ q{postgresql://host?value1&value2}, q{}, - q{uri-regress: missing key/value separator "=" in URI query parameter: "value1"}, + q{libpq_uri_regress: missing key/value separator "=" in URI query parameter: "value1"}, ], [ q{postgresql://host?key=key=value}, q{}, - q{uri-regress: extra key/value separator "=" in URI query parameter: "key"}, + q{libpq_uri_regress: extra key/value separator "=" in URI query parameter: "key"}, ], [ q{postgres://host?dbname=%XXfoo}, q{}, - q{uri-regress: invalid percent-encoded token: "%XXfoo"}, + q{libpq_uri_regress: invalid percent-encoded token: "%XXfoo"}, ], [ q{postgresql://a%00b}, q{}, - q{uri-regress: forbidden value %00 in percent-encoded value: "a%00b"}, + q{libpq_uri_regress: forbidden value %00 in percent-encoded value: "a%00b"}, ], [ q{postgresql://%zz}, q{}, - q{uri-regress: invalid percent-encoded token: "%zz"}, + q{libpq_uri_regress: invalid percent-encoded token: "%zz"}, ], [ q{postgresql://%1}, q{}, - q{uri-regress: invalid percent-encoded token: "%1"}, + q{libpq_uri_regress: invalid percent-encoded token: "%1"}, ], [ q{postgresql://%}, q{}, - q{uri-regress: invalid percent-encoded token: "%"}, + q{libpq_uri_regress: invalid percent-encoded token: "%"}, ], [ q{postgres://@host}, q{host='host' (inet)}, q{}, ], [ q{postgres://host:/}, q{host='host' (inet)}, q{}, ], @@ -224,7 +224,7 @@ sub test_uri $expect{'exit'} = $expect{stderr} eq ''; - my $cmd = [ 'uri-regress', $uri ]; + my $cmd = [ 'libpq_uri_regress', $uri ]; $result{exit} = IPC::Run::run $cmd, '>', \$result{stdout}, '2>', \$result{stderr}; diff --git a/src/interfaces/libpq/t/002_api.pl b/src/interfaces/libpq/t/002_api.pl index 7c6c5788a0c..8b3355e6dd6 100644 --- a/src/interfaces/libpq/t/002_api.pl +++ b/src/interfaces/libpq/t/002_api.pl @@ -6,7 +6,7 @@ use PostgreSQL::Test::Utils; use Test::More; # Test PQsslAttribute(NULL, "library") -my ($out, $err) = run_command(['testclient', '--ssl']); +my ($out, $err) = run_command(['libpq_testclient', '--ssl']); if ($ENV{with_ssl} eq 'openssl') { diff --git a/src/interfaces/libpq/test/.gitignore b/src/interfaces/libpq/test/.gitignore index 4b17210483d..6ba78adb678 100644 --- a/src/interfaces/libpq/test/.gitignore +++ b/src/interfaces/libpq/test/.gitignore @@ -1,2 +1,2 @@ -/testclient -/uri-regress +/libpq_testclient +/libpq_uri_regress diff --git a/src/interfaces/libpq/test/Makefile b/src/interfaces/libpq/test/Makefile index 1d45be0c375..1f75b73b8c1 100644 --- a/src/interfaces/libpq/test/Makefile +++ b/src/interfaces/libpq/test/Makefile @@ -11,7 +11,7 @@ endif override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) LDFLAGS_INTERNAL += $(libpq_pgport) -PROGS = testclient uri-regress +PROGS = libpq_testclient libpq_uri_regress all: $(PROGS) diff --git a/src/interfaces/libpq/test/libpq_testclient.c b/src/interfaces/libpq/test/libpq_testclient.c new file mode 100644 index 00000000000..d945bacf1b2 --- /dev/null +++ b/src/interfaces/libpq/test/libpq_testclient.c @@ -0,0 +1,37 @@ +/* + * libpq_testclient.c + * A test program for the libpq public API + * + * Copyright (c) 2022, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/interfaces/libpq/test/libpq_testclient.c + */ + +#include "postgres_fe.h" + +#include "libpq-fe.h" + +static void +print_ssl_library() +{ + const char *lib = PQsslAttribute(NULL, "library"); + + if (!lib) + fprintf(stderr, "SSL is not enabled\n"); + else + printf("%s\n", lib); +} + +int +main(int argc, char *argv[]) +{ + if ((argc > 1) && !strcmp(argv[1], "--ssl")) + { + print_ssl_library(); + return 0; + } + + printf("currently only --ssl is supported\n"); + return 1; +} diff --git a/src/interfaces/libpq/test/libpq_uri_regress.c b/src/interfaces/libpq/test/libpq_uri_regress.c new file mode 100644 index 00000000000..60469002fda --- /dev/null +++ b/src/interfaces/libpq/test/libpq_uri_regress.c @@ -0,0 +1,84 @@ +/* + * libpq_uri_regress.c + * A test program for libpq URI format + * + * This is a helper for libpq conninfo regression testing. It takes a single + * conninfo string as a parameter, parses it using PQconninfoParse, and then + * prints out the values from the parsed PQconninfoOption struct that differ + * from the defaults (obtained from PQconndefaults). + * + * Portions Copyright (c) 2012-2022, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/interfaces/libpq/test/libpq_uri_regress.c + */ + +#include "postgres_fe.h" + +#include "libpq-fe.h" + +int +main(int argc, char *argv[]) +{ + PQconninfoOption *opts; + PQconninfoOption *defs; + PQconninfoOption *opt; + PQconninfoOption *def; + char *errmsg = NULL; + bool local = true; + + if (argc != 2) + return 1; + + opts = PQconninfoParse(argv[1], &errmsg); + if (opts == NULL) + { + fprintf(stderr, "libpq_uri_regress: %s", errmsg); + return 1; + } + + defs = PQconndefaults(); + if (defs == NULL) + { + fprintf(stderr, "libpq_uri_regress: cannot fetch default options\n"); + return 1; + } + + /* + * Loop on the options, and print the value of each if not the default. + * + * XXX this coding assumes that PQconninfoOption structs always have the + * keywords in the same order. + */ + for (opt = opts, def = defs; opt->keyword; ++opt, ++def) + { + if (opt->val != NULL) + { + if (def->val == NULL || strcmp(opt->val, def->val) != 0) + printf("%s='%s' ", opt->keyword, opt->val); + + /* + * Try to detect if this is a Unix-domain socket or inet. This is + * a bit grotty but it's the same thing that libpq itself does. + * + * Note that we directly test for '/' instead of using + * is_absolute_path, as that would be considerably more messy. + * This would fail on Windows, but that platform doesn't have + * Unix-domain sockets anyway. + */ + if (*opt->val && + (strcmp(opt->keyword, "hostaddr") == 0 || + (strcmp(opt->keyword, "host") == 0 && *opt->val != '/'))) + { + local = false; + } + } + } + + if (local) + printf("(local)\n"); + else + printf("(inet)\n"); + + return 0; +} diff --git a/src/interfaces/libpq/test/testclient.c b/src/interfaces/libpq/test/testclient.c deleted file mode 100644 index 2c730d83fa6..00000000000 --- a/src/interfaces/libpq/test/testclient.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * testclient.c - * A test program for the libpq public API - * - * Copyright (c) 2022, PostgreSQL Global Development Group - * - * IDENTIFICATION - * src/interfaces/libpq/test/testclient.c - */ - -#include "postgres_fe.h" - -#include "libpq-fe.h" - -static void -print_ssl_library() -{ - const char *lib = PQsslAttribute(NULL, "library"); - - if (!lib) - fprintf(stderr, "SSL is not enabled\n"); - else - printf("%s\n", lib); -} - -int -main(int argc, char *argv[]) -{ - if ((argc > 1) && !strcmp(argv[1], "--ssl")) - { - print_ssl_library(); - return 0; - } - - printf("currently only --ssl is supported\n"); - return 1; -} diff --git a/src/interfaces/libpq/test/uri-regress.c b/src/interfaces/libpq/test/uri-regress.c deleted file mode 100644 index c5ef33c46b7..00000000000 --- a/src/interfaces/libpq/test/uri-regress.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * uri-regress.c - * A test program for libpq URI format - * - * This is a helper for libpq conninfo regression testing. It takes a single - * conninfo string as a parameter, parses it using PQconninfoParse, and then - * prints out the values from the parsed PQconninfoOption struct that differ - * from the defaults (obtained from PQconndefaults). - * - * Portions Copyright (c) 2012-2022, PostgreSQL Global Development Group - * - * IDENTIFICATION - * src/interfaces/libpq/test/uri-regress.c - */ - -#include "postgres_fe.h" - -#include "libpq-fe.h" - -int -main(int argc, char *argv[]) -{ - PQconninfoOption *opts; - PQconninfoOption *defs; - PQconninfoOption *opt; - PQconninfoOption *def; - char *errmsg = NULL; - bool local = true; - - if (argc != 2) - return 1; - - opts = PQconninfoParse(argv[1], &errmsg); - if (opts == NULL) - { - fprintf(stderr, "uri-regress: %s", errmsg); - return 1; - } - - defs = PQconndefaults(); - if (defs == NULL) - { - fprintf(stderr, "uri-regress: cannot fetch default options\n"); - return 1; - } - - /* - * Loop on the options, and print the value of each if not the default. - * - * XXX this coding assumes that PQconninfoOption structs always have the - * keywords in the same order. - */ - for (opt = opts, def = defs; opt->keyword; ++opt, ++def) - { - if (opt->val != NULL) - { - if (def->val == NULL || strcmp(opt->val, def->val) != 0) - printf("%s='%s' ", opt->keyword, opt->val); - - /* - * Try to detect if this is a Unix-domain socket or inet. This is - * a bit grotty but it's the same thing that libpq itself does. - * - * Note that we directly test for '/' instead of using - * is_absolute_path, as that would be considerably more messy. - * This would fail on Windows, but that platform doesn't have - * Unix-domain sockets anyway. - */ - if (*opt->val && - (strcmp(opt->keyword, "hostaddr") == 0 || - (strcmp(opt->keyword, "host") == 0 && *opt->val != '/'))) - { - local = false; - } - } - } - - if (local) - printf("(local)\n"); - else - printf("(inet)\n"); - - return 0; -} diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm index fc04e1db8e2..c3058399d49 100644 --- a/src/tools/msvc/Mkvcbuild.pm +++ b/src/tools/msvc/Mkvcbuild.pm @@ -285,17 +285,17 @@ sub mkvcbuild $libpqwalreceiver->AddReference($postgres, $libpq); my $libpq_testclient = - $solution->AddProject('testclient', 'exe', 'misc', + $solution->AddProject('libpq_testclient', 'exe', 'misc', 'src/interfaces/libpq/test'); - $libpq_testclient->AddFile('src/interfaces/libpq/test/testclient.c'); + $libpq_testclient->AddFile('src/interfaces/libpq/test/libpq_testclient.c'); $libpq_testclient->AddIncludeDir('src/interfaces/libpq'); $libpq_testclient->AddReference($libpgport, $libpq); $libpq_testclient->AddLibrary('ws2_32.lib'); my $libpq_uri_regress = - $solution->AddProject('uri-regress', 'exe', 'misc', + $solution->AddProject('libpq_uri_regress', 'exe', 'misc', 'src/interfaces/libpq/test'); - $libpq_uri_regress->AddFile('src/interfaces/libpq/test/uri-regress.c'); + $libpq_uri_regress->AddFile('src/interfaces/libpq/test/libpq_uri_regress.c'); $libpq_uri_regress->AddIncludeDir('src/interfaces/libpq'); $libpq_uri_regress->AddReference($libpgport, $libpq); $libpq_uri_regress->AddLibrary('ws2_32.lib'); -- cgit v1.2.3