t0021/rot13-filter: refactor checking final lf

As checking for a lf character at the end of a buffer will be useful in another function, let's refactor this functionality into a small remove_final_lf_or_die() helper function. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Nov 5, 2017 at 22:38 UTC 4a9ef1bbc19f362a63c3e3ab88c651f97cbd1c1d
1 file changed +11 -3
t/t0021/rot13-filter.pl
+11 -3
@@ -93,12 +93,20 @@ sub packet_bin_read {
93 }
94 }
95
96 -sub packet_txt_read {
97 - my ( $res, $buf ) = packet_bin_read();
98 - unless ( $res == -1 or $buf eq '' or $buf =~ s/\n$// ) {
96 +sub remove_final_lf_or_die {
97 + my $buf = shift;
98 + unless ( $buf =~ s/\n$// ) {
99 die "A non-binary line MUST be terminated by an LF.\n"
100 . "Received: '$buf'";
101 }
102 + return $buf;
103 +}
104 +
105 +sub packet_txt_read {
106 + my ( $res, $buf ) = packet_bin_read();
107 + unless ( $res == -1 or $buf eq '' ) {
108 + $buf = remove_final_lf_or_die($buf);
109 + }
110 return ( $res, $buf );
111 }
112