Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Make PostgresNode::append_conf append a newline automatically.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Apr 2017 20:58:15 +0000 (16:58 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 22 Apr 2017 20:58:15 +0000 (16:58 -0400)
Although the documentation for append_conf said clearly that it didn't
add a newline, many test authors seem to have forgotten that ... or maybe
they just consulted the example at the top of the POD documentation,
which clearly shows adding a config entry without bothering to add a
trailing newline.  The worst part of that is that it works, as long as
you don't do it more than once, since the backend isn't picky about
whether config files end with newlines.  So there's not a strong forcing
function reminding test authors not to do it like that.  Upshot is that
this is a terribly fragile way to go about things, and there's at least
one existing test case that is demonstrably broken and not testing what
it thinks it is.

Let's just make append_conf append a newline, instead; that is clearly
way safer than the old definition.

I also cleaned up a few call sites that were unnecessarily ugly.
(I left things alone in places where it's plausible that additional
config lines would need to be added someday.)

Back-patch the change in append_conf itself to 9.6 where it was added,
as having a definitional inconsistency between branches would obviously
be pretty hazardous for back-patching TAP tests.  The other changes are
just cosmetic and don't need to be back-patched.

Discussion: https://postgr.es/m/19751.1492892376@sss.pgh.pa.us

src/test/perl/PostgresNode.pm

index bd627b29deea9c0692fe1db993b9cd5f0fbe424a..b55f8bf57ec7a07b2a5ec1f4521a6c13963e4ed7 100644 (file)
@@ -441,7 +441,7 @@ A shortcut method to append to files like pg_hba.conf and postgresql.conf.
 Does no validation or sanity checking. Does not reload the configuration
 after writing.
 
-A newline is NOT automatically appended to the string.
+A newline is automatically appended to the string.
 
 =cut
 
@@ -451,7 +451,7 @@ sub append_conf
 
    my $conffile = $self->data_dir . '/' . $filename;
 
-   TestLib::append_to_file($conffile, $str);
+   TestLib::append_to_file($conffile, $str . "\n");
 }
 
 =pod