Skip to content

Commit 0a26882

Browse files
chriscoolgitster
authored andcommitted
t0021/rot13-filter: fix list comparison
Since edcc858 ("convert: add filter.<driver>.process option", 2016-10-16) when t0021/rot13-filter.pl was created, list comparison in this perl script have been quite broken. packet_txt_read() returns a 2-element list, and the right hand side of "eq" also has a list with (two, elements), but "eq" takes the last element of the list on each side, and compares them. The first elements (0 or 1) on the right hand side lists do not matter, which means we do not require to see a flush at the end of the version -- a simple empty string or an EOF would do, which is definitely not what we want. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4843cde commit 0a26882

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

t/t0021/rot13-filter.pl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ sub rot13 {
5555
return $str;
5656
}
5757

58+
sub packet_compare_lists {
59+
my ($expect, @result) = @_;
60+
my $ix;
61+
if (scalar @$expect != scalar @result) {
62+
return undef;
63+
}
64+
for ($ix = 0; $ix < $#result; $ix++) {
65+
if ($expect->[$ix] ne $result[$ix]) {
66+
return undef;
67+
}
68+
}
69+
return 1;
70+
}
71+
5872
sub packet_bin_read {
5973
my $buffer;
6074
my $bytes_read = read STDIN, $buffer, 4;
@@ -110,18 +124,25 @@ sub packet_flush {
110124
print $debug "START\n";
111125
$debug->flush();
112126

113-
( packet_txt_read() eq ( 0, "git-filter-client" ) ) || die "bad initialize";
114-
( packet_txt_read() eq ( 0, "version=2" ) ) || die "bad version";
115-
( packet_bin_read() eq ( 1, "" ) ) || die "bad version end";
127+
packet_compare_lists([0, "git-filter-client"], packet_txt_read()) ||
128+
die "bad initialize";
129+
packet_compare_lists([0, "version=2"], packet_txt_read()) ||
130+
die "bad version";
131+
packet_compare_lists([1, ""], packet_bin_read()) ||
132+
die "bad version end";
116133

117134
packet_txt_write("git-filter-server");
118135
packet_txt_write("version=2");
119136
packet_flush();
120137

121-
( packet_txt_read() eq ( 0, "capability=clean" ) ) || die "bad capability";
122-
( packet_txt_read() eq ( 0, "capability=smudge" ) ) || die "bad capability";
123-
( packet_txt_read() eq ( 0, "capability=delay" ) ) || die "bad capability";
124-
( packet_bin_read() eq ( 1, "" ) ) || die "bad capability end";
138+
packet_compare_lists([0, "capability=clean"], packet_txt_read()) ||
139+
die "bad capability";
140+
packet_compare_lists([0, "capability=smudge"], packet_txt_read()) ||
141+
die "bad capability";
142+
packet_compare_lists([0, "capability=delay"], packet_txt_read()) ||
143+
die "bad capability";
144+
packet_compare_lists([1, ""], packet_bin_read()) ||
145+
die "bad capability end";
125146

126147
foreach (@capabilities) {
127148
packet_txt_write( "capability=" . $_ );

0 commit comments

Comments
 (0)