Simplify newline handling in two TAP tests
authorMichael Paquier <[email protected]>
Mon, 27 Oct 2025 23:26:42 +0000 (08:26 +0900)
committerMichael Paquier <[email protected]>
Mon, 27 Oct 2025 23:26:42 +0000 (08:26 +0900)
Two tests are changed in this commit:
- libpq's 006_service
- ldap's 003_ldap_connection_param_lookup

CRLF translation is already handled by the text mode, so there should be
need for any specific logic.  See also 1c6d4629394d, msys perl being one
case where the translation mattered.

Note: This is first applied on HEAD, and backpatch will follow once the
buildfarm has provided an opinion about this commit.

Author: Jacob Champion <[email protected]>
Co-authored-by: Michael Paquier <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 13

src/interfaces/libpq/t/006_service.pl
src/test/ldap/t/003_ldap_connection_param_lookup.pl

index 797e6232b8fcbc226c3a9ca769339b986f94ca25..29a70629b4485cf811cd8034d0b79cd5e9d8735a 100644 (file)
@@ -22,18 +22,14 @@ $dummy_node->init;
 
 my $td = PostgreSQL::Test::Utils::tempdir;
 
-# Windows vs non-Windows: CRLF vs LF for the file's newline, relying on
-# the fact that libpq uses fgets() when reading the lines of a service file.
-my $newline = $windows_os ? "\r\n" : "\n";
-
 # Create the set of service files used in the tests.
 # File that includes a valid service name, and uses a decomposed connection
 # string for its contents, split on spaces.
 my $srvfile_valid = "$td/pg_service_valid.conf";
-append_to_file($srvfile_valid, "[my_srv]" . $newline);
+append_to_file($srvfile_valid, "[my_srv]\n");
 foreach my $param (split(/\s+/, $node->connstr))
 {
-   append_to_file($srvfile_valid, $param . $newline);
+   append_to_file($srvfile_valid, $param . "\n");
 }
 
 # File defined with no contents, used as default value for PGSERVICEFILE,
@@ -51,14 +47,14 @@ my $srvfile_missing = "$td/pg_service_missing.conf";
 my $srvfile_nested = "$td/pg_service_nested.conf";
 copy($srvfile_valid, $srvfile_nested)
   or die "Could not copy $srvfile_valid to $srvfile_nested: $!";
-append_to_file($srvfile_nested, 'service=invalid_srv' . $newline);
+append_to_file($srvfile_nested, "service=invalid_srv\n");
 
 # Service file with nested "servicefile" defined.
 my $srvfile_nested_2 = "$td/pg_service_nested_2.conf";
 copy($srvfile_valid, $srvfile_nested_2)
   or die "Could not copy $srvfile_valid to $srvfile_nested_2: $!";
 append_to_file($srvfile_nested_2,
-   'servicefile=' . $srvfile_default . $newline);
+   'servicefile=' . $srvfile_default . "\n");
 
 # Set the fallback directory lookup of the service file to the temporary
 # directory of this test.  PGSYSCONFDIR is used if the service file
index 8c1e1caf992a41f2821a555857d02bfe8debeafa..abcb6d22a8b475a821218d45934ff8d3da976137 100644 (file)
@@ -44,31 +44,21 @@ $ldap->ldapadd_file('authdata.ldif');
 $ldap->ldapsetpw('uid=test1,dc=example,dc=net', 'secret1');
 $ldap->ldapsetpw('uid=test2,dc=example,dc=net', 'secret2');
 
-# Windows vs non-Windows: CRLF vs LF for the file's newline, relying on
-# the fact that libpq uses fgets() when reading the lines of a service file.
-my $newline = $windows_os ? "\r\n" : "\n";
-
 my $td = PostgreSQL::Test::Utils::tempdir;
 
 # create ldap file based on postgres connection info
 my $ldif_valid = "$td/connection_params.ldif";
-append_to_file($ldif_valid, "version:1");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "dn:cn=mydatabase,dc=example,dc=net");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "changetype:add");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "objectclass:top");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "objectclass:device");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "cn:mydatabase");
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "description:host=");
-append_to_file($ldif_valid, $node->host);
-append_to_file($ldif_valid, $newline);
-append_to_file($ldif_valid, "description:port=");
-append_to_file($ldif_valid, $node->port);
+append_to_file(
+   $ldif_valid, qq{
+version:1
+dn:cn=mydatabase,dc=example,dc=net
+changetype:add
+objectclass:top
+objectclass:device
+cn:mydatabase
+description:host=} . $node->host . qq{
+description:port=} . $node->port . qq{
+});
 
 $ldap->ldapadd_file($ldif_valid);
 
@@ -86,12 +76,11 @@ note "setting up PostgreSQL instance";
 # File that includes a valid service name, that uses a decomposed
 # connection string for its contents, split on spaces.
 my $srvfile_valid = "$td/pg_service_valid.conf";
-append_to_file($srvfile_valid, "[my_srv]");
-append_to_file($srvfile_valid, $newline);
-append_to_file($srvfile_valid, "ldap://localhost:");
-append_to_file($srvfile_valid, $ldap_port);
-append_to_file($srvfile_valid,
-   "/dc=example,dc=net?description?one?(cn=mydatabase)");
+append_to_file(
+   $srvfile_valid, qq{
+[my_srv]
+ldap://localhost:$ldap_port/dc=example,dc=net?description?one?(cn=mydatabase)
+});
 
 # File defined with no contents, used as default value for
 # PGSERVICEFILE, so that no lookup is attempted in the user's home