Tighten up Windows CRLF conversion in our TAP test scripts.
authorTom Lane <[email protected]>
Thu, 9 Jul 2020 21:38:52 +0000 (17:38 -0400)
committerTom Lane <[email protected]>
Thu, 9 Jul 2020 21:38:52 +0000 (17:38 -0400)
Back-patch commits 91bdf499b and ffb4cee43, so that all branches
agree on when and how to do Windows CRLF conversion.

This should close the referenced thread.  Thanks to Andrew Dunstan
for discussion/review.

Discussion: https://postgr.es/m/412ae8da-76bb-640f-039a-f3513499e53d@gmx.net

src/bin/pg_rewind/t/RewindTest.pm
src/test/perl/PostgresNode.pm
src/test/perl/TestLib.pm

index 68b6004e9461a62fc9e7a40de3170e45d8db0005..739da1945962bc60a7d8ebc2b657db22d84db17c 100644 (file)
@@ -111,7 +111,7 @@ sub check_query
    }
    else
    {
-       $stdout =~ s/\r//g if $Config{osname} eq 'msys';
+       $stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
        is($stdout, $expected_stdout, "$test_name: query result matches");
    }
    return;
index af13c320e9cca447dde89ef0844c06d4aec37312..5811fbd59a7bc796d24346e19b7e1b55449358e3 100644 (file)
@@ -1296,7 +1296,6 @@ sub safe_psql
        print "\n#### End standard error\n";
    }
 
-   $stdout =~ s/\r//g if $TestLib::windows_os;
    return $stdout;
 }
 
@@ -1472,16 +1471,20 @@ sub psql
        }
    };
 
+   # Note: on Windows, IPC::Run seems to convert \r\n to \n in program output
+   # if we're using native Perl, but not if we're using MSys Perl.  So do it
+   # by hand in the latter case, here and elsewhere.
+
    if (defined $$stdout)
    {
+       $$stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
        chomp $$stdout;
-       $$stdout =~ s/\r//g if $TestLib::windows_os;
    }
 
    if (defined $$stderr)
    {
+       $$stderr =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
        chomp $$stderr;
-       $$stderr =~ s/\r//g if $TestLib::windows_os;
    }
 
    # See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
@@ -1544,8 +1547,8 @@ sub poll_query_until
    {
        my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
 
+       $stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
        chomp($stdout);
-       $stdout =~ s/\r//g if $TestLib::windows_os;
 
        if ($stdout eq $expected)
        {
@@ -1560,8 +1563,8 @@ sub poll_query_until
 
    # The query result didn't change in 180 seconds. Give up. Print the
    # output from the last attempt, hopefully that's useful for debugging.
+   $stderr =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
    chomp($stderr);
-   $stderr =~ s/\r//g if $TestLib::windows_os;
    diag qq(poll_query_until timed out executing this query:
 $query
 expecting this output:
@@ -2005,8 +2008,8 @@ sub pg_recvlogical_upto
        }
    };
 
-   $stdout =~ s/\r//g if $TestLib::windows_os;
-   $stderr =~ s/\r//g if $TestLib::windows_os;
+   $stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
+   $stderr =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
 
    if (wantarray)
    {
index 9006b5478bffc6e551bed8bb87f133be880b049d..81e3252dcfbb20f75388cfe14c67f64f8c01bf4b 100644 (file)
@@ -260,7 +260,7 @@ sub slurp_file
      or die "could not read \"$filename\": $!";
    my $contents = <$in>;
    close $in;
-   $contents =~ s/\r//g if $Config{osname} eq 'msys';
+   $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
    return $contents;
 }