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 734adb72ec543b9351ff942e6b13436df4b819e5..2c00b823fdbdc583bb86d23cfc10fc3317b4f03b 100644 (file)
@@ -120,7 +120,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");
    }
 }
@@ -139,8 +139,8 @@ sub poll_query_until
        my $cmd = [ 'psql', '-At', '-c', "$query", '-d', "$connstr" ];
        my $result = run $cmd, '>', \$stdout, '2>', \$stderr;
 
+       $stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
        chomp($stdout);
-       $stdout =~ s/\r//g if $Config{osname} eq 'msys';
        if ($stdout eq "t")
        {
            return 1;
@@ -153,8 +153,8 @@ sub poll_query_until
 
    # The query result didn't change in 90 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 $Config{osname} eq 'msys';
    diag qq(poll_query_until timed out executing this query:
 $query
 expecting this output:
index 3e39fd6979dab23db4dbcef70ef1e6f8b51ed8f2..6d3fa1370b56e419a179fd95db88617674886d60 100644 (file)
@@ -1122,7 +1122,6 @@ sub safe_psql
        print "\n#### End standard error\n";
    }
 
-   $stdout =~ s/\r//g if $TestLib::windows_os;
    return $stdout;
 }
 
@@ -1297,16 +1296,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
@@ -1364,8 +1367,8 @@ sub poll_query_until
          [ 'psql', '-XAt', '-c', $query, '-d', $self->connstr($dbname) ];
        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 "t")
        {
            return 1;
@@ -1378,8 +1381,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:
index b2c536b044afb85b97ea520b706251c19f5fc69d..b606e1b173f5d23314dedd9a1b416d4b207581dd 100644 (file)
@@ -259,8 +259,8 @@ sub psql
    my ($stdout, $stderr);
    print("# Running SQL command: $sql\n");
    run [ 'psql', '-X', '-A', '-t', '-q', '-d', $dbname, '-f', '-' ], '<', \$sql, '>', \$stdout, '2>', \$stderr or die;
+   $stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
    chomp $stdout;
-   $stdout =~ s/\r//g if $Config{osname} eq 'msys';
    return $stdout;
 }
 
@@ -281,7 +281,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;
 }