Skip to content

Commit 91bdf49

Browse files
committed
Tighten up Windows CRLF conversion in our TAP test scripts.
The previous approach was to search-and-destroy all \r occurrences no matter what. That seems more likely to hide bugs than anything else; indeed it seems to be hiding one now. Fix things so that we only transform \r\n to \n. Side effects: must do this before, not after, chomp'ing if we're going to chomp, else we'd fail to clean up a trailing \r\n. Also, remove safe_psql's redundant repetition of what psql already did; else it might reduce \r\r\n to \n, which is exactly the scenario I'm hoping to expose. Perhaps this should be back-patched, but for now I'm content to see what happens in HEAD. Discussion: https://postgr.es/m/412ae8da-76bb-640f-039a-f3513499e53d@gmx.net
1 parent 2b7dbc0 commit 91bdf49

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/bin/pg_rewind/t/RewindTest.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ sub check_query
112112
}
113113
else
114114
{
115-
$stdout =~ s/\r//g if $Config{osname} eq 'msys';
115+
$stdout =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
116116
is($stdout, $expected_stdout, "$test_name: query result matches");
117117
}
118118
return;

src/test/perl/PostgresNode.pm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,6 @@ sub safe_psql
13241324
print "\n#### End standard error\n";
13251325
}
13261326

1327-
$stdout =~ s/\r//g if $TestLib::windows_os;
13281327
return $stdout;
13291328
}
13301329

@@ -1515,14 +1514,14 @@ sub psql
15151514

15161515
if (defined $$stdout)
15171516
{
1517+
$$stdout =~ s/\r\n/\n/g if $TestLib::windows_os;
15181518
chomp $$stdout;
1519-
$$stdout =~ s/\r//g if $TestLib::windows_os;
15201519
}
15211520

15221521
if (defined $$stderr)
15231522
{
1523+
$$stderr =~ s/\r\n/\n/g if $TestLib::windows_os;
15241524
chomp $$stderr;
1525-
$$stderr =~ s/\r//g if $TestLib::windows_os;
15261525
}
15271526

15281527
# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
@@ -1652,8 +1651,8 @@ sub poll_query_until
16521651
{
16531652
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
16541653

1654+
$stdout =~ s/\r\n/\n/g if $TestLib::windows_os;
16551655
chomp($stdout);
1656-
$stdout =~ s/\r//g if $TestLib::windows_os;
16571656

16581657
if ($stdout eq $expected)
16591658
{
@@ -1668,8 +1667,8 @@ sub poll_query_until
16681667

16691668
# The query result didn't change in 180 seconds. Give up. Print the
16701669
# output from the last attempt, hopefully that's useful for debugging.
1670+
$stderr =~ s/\r\n/\n/g if $TestLib::windows_os;
16711671
chomp($stderr);
1672-
$stderr =~ s/\r//g if $TestLib::windows_os;
16731672
diag qq(poll_query_until timed out executing this query:
16741673
$query
16751674
expecting this output:
@@ -2113,8 +2112,8 @@ sub pg_recvlogical_upto
21132112
}
21142113
};
21152114

2116-
$stdout =~ s/\r//g if $TestLib::windows_os;
2117-
$stderr =~ s/\r//g if $TestLib::windows_os;
2115+
$stdout =~ s/\r\n/\n/g if $TestLib::windows_os;
2116+
$stderr =~ s/\r\n/\n/g if $TestLib::windows_os;
21182117

21192118
if (wantarray)
21202119
{

src/test/perl/TestLib.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ sub slurp_file
430430
CloseHandle($fHandle)
431431
or die "could not close \"$filename\": $^E\n";
432432
}
433-
$contents =~ s/\r//g if $Config{osname} eq 'msys';
433+
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
434434
return $contents;
435435
}
436436

0 commit comments

Comments
 (0)