summaryrefslogtreecommitdiff
path: root/t/t0021/rot13-filter.pl
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2017-11-05 21:38:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-07 00:54:41 (GMT)
commit4a9ef1bbc19f362a63c3e3ab88c651f97cbd1c1d (patch)
tree9dfc8ca6b2bab4c61f6e0ece7aaca66652a4112d /t/t0021/rot13-filter.pl
parent25cbfe34656d4cf25e1bf16ac61f981cb3d5c1b3 (diff)
downloadgit-4a9ef1bbc19f362a63c3e3ab88c651f97cbd1c1d.zip
git-4a9ef1bbc19f362a63c3e3ab88c651f97cbd1c1d.tar.gz
git-4a9ef1bbc19f362a63c3e3ab88c651f97cbd1c1d.tar.bz2
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>
Diffstat (limited to 't/t0021/rot13-filter.pl')
-rw-r--r--t/t0021/rot13-filter.pl14
1 files changed, 11 insertions, 3 deletions
diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl
index 2f74ab2..d47b7f5 100644
--- a/t/t0021/rot13-filter.pl
+++ b/t/t0021/rot13-filter.pl
@@ -93,12 +93,20 @@ sub packet_bin_read {
}
}
-sub packet_txt_read {
- my ( $res, $buf ) = packet_bin_read();
- unless ( $res == -1 or $buf eq '' or $buf =~ s/\n$// ) {
+sub remove_final_lf_or_die {
+ my $buf = shift;
+ unless ( $buf =~ s/\n$// ) {
die "A non-binary line MUST be terminated by an LF.\n"
. "Received: '$buf'";
}
+ return $buf;
+}
+
+sub packet_txt_read {
+ my ( $res, $buf ) = packet_bin_read();
+ unless ( $res == -1 or $buf eq '' ) {
+ $buf = remove_final_lf_or_die($buf);
+ }
return ( $res, $buf );
}