t0021/rot13-filter: fix list comparison

Since edcc8581 ("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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Nov 5, 2017 at 22:38 UTC 0a268826214ae8e50ba504f44067899976f48716
1 file changed +28 -7
t/t0021/rot13-filter.pl
+28 -7
@@ -55,6 +55,20 @@ sub rot13 {
55 return $str;
56 }
57
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 +
72 sub packet_bin_read {
73 my $buffer;
74 my $bytes_read = read STDIN, $buffer, 4;
@@ -110,18 +124,25 @@ sub packet_flush {
124 print $debug "START\n";
125 $debug->flush();
126
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";
133
134 packet_txt_write("git-filter-server");
135 packet_txt_write("version=2");
136 packet_flush();
137
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";
146
147 foreach (@capabilities) {
148 packet_txt_write( "capability=" . $_ );