tests: use the new C rot13-filter helper to avoid PERL prereq
The previous commit implemented a C version of the t0021/rot13-filter.pl script. Let's use this new C helper to eliminate the PERL prereq from various tests, and also remove the superseded Perl script. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matheus Tavares committed
Aug 14, 2022 at 22:06 UTC
4d1d843be7a15717b425ad39f8cd4c4a510b4121
4 files changed
+37
-293
t/t0021-conversion.sh
+33
-36
@@ -17,9 +17,6 @@ tr \
17
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
18
EOF
19
20
-write_script rot13-filter.pl "$PERL_PATH" \
21
- <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
22
-
20
generate_random_characters () {
21
LEN=$1
22
NAME=$2
@@ -365,8 +362,8 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' '
362
test_line_count = 0 count
363
'
364
368
-test_expect_success PERL 'required process filter should filter data' '
369
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
365
+test_expect_success 'required process filter should filter data' '
366
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
367
test_config_global filter.protocol.required true &&
368
rm -rf repo &&
369
mkdir repo &&
@@ -450,8 +447,8 @@ test_expect_success PERL 'required process filter should filter data' '
447
)
448
'
449
453
-test_expect_success PERL 'required process filter should filter data for various subcommands' '
454
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
450
+test_expect_success 'required process filter should filter data for various subcommands' '
451
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
452
test_config_global filter.protocol.required true &&
453
(
454
cd repo &&
@@ -561,9 +558,9 @@ test_expect_success PERL 'required process filter should filter data for various
558
)
559
'
560
564
-test_expect_success PERL 'required process filter takes precedence' '
561
+test_expect_success 'required process filter takes precedence' '
562
test_config_global filter.protocol.clean false &&
566
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
563
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" &&
564
test_config_global filter.protocol.required true &&
565
rm -rf repo &&
566
mkdir repo &&
@@ -587,8 +584,8 @@ test_expect_success PERL 'required process filter takes precedence' '
584
)
585
'
586
590
-test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
591
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
587
+test_expect_success 'required process filter should be used only for "clean" operation only' '
588
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" &&
589
rm -rf repo &&
590
mkdir repo &&
591
(
@@ -622,8 +619,8 @@ test_expect_success PERL 'required process filter should be used only for "clean
619
)
620
'
621
625
-test_expect_success PERL 'required process filter should process multiple packets' '
626
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
622
+test_expect_success 'required process filter should process multiple packets' '
623
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
624
test_config_global filter.protocol.required true &&
625
626
rm -rf repo &&
@@ -687,8 +684,8 @@ test_expect_success PERL 'required process filter should process multiple packet
684
)
685
'
686
690
-test_expect_success PERL 'required process filter with clean error should fail' '
691
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
687
+test_expect_success 'required process filter with clean error should fail' '
688
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
689
test_config_global filter.protocol.required true &&
690
rm -rf repo &&
691
mkdir repo &&
@@ -706,8 +703,8 @@ test_expect_success PERL 'required process filter with clean error should fail'
703
)
704
'
705
709
-test_expect_success PERL 'process filter should restart after unexpected write failure' '
710
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
706
+test_expect_success 'process filter should restart after unexpected write failure' '
707
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
708
rm -rf repo &&
709
mkdir repo &&
710
(
@@ -761,8 +758,8 @@ test_expect_success PERL 'process filter should restart after unexpected write f
758
)
759
'
760
764
-test_expect_success PERL 'process filter should not be restarted if it signals an error' '
765
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
761
+test_expect_success 'process filter should not be restarted if it signals an error' '
762
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
763
rm -rf repo &&
764
mkdir repo &&
765
(
@@ -804,8 +801,8 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
801
)
802
'
803
807
-test_expect_success PERL 'process filter abort stops processing of all further files' '
808
- test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
804
+test_expect_success 'process filter abort stops processing of all further files' '
805
+ test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
806
rm -rf repo &&
807
mkdir repo &&
808
(
@@ -861,10 +858,10 @@ test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
858
)
859
'
860
864
-test_expect_success PERL 'delayed checkout in process filter' '
865
- test_config_global filter.a.process "rot13-filter.pl a.log clean smudge delay" &&
861
+test_expect_success 'delayed checkout in process filter' '
862
+ test_config_global filter.a.process "test-tool rot13-filter --log=a.log clean smudge delay" &&
863
test_config_global filter.a.required true &&
867
- test_config_global filter.b.process "rot13-filter.pl b.log clean smudge delay" &&
864
+ test_config_global filter.b.process "test-tool rot13-filter --log=b.log clean smudge delay" &&
865
test_config_global filter.b.required true &&
866
867
rm -rf repo &&
@@ -940,8 +937,8 @@ test_expect_success PERL 'delayed checkout in process filter' '
937
)
938
'
939
943
-test_expect_success PERL 'missing file in delayed checkout' '
944
- test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
940
+test_expect_success 'missing file in delayed checkout' '
941
+ test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" &&
942
test_config_global filter.bug.required true &&
943
944
rm -rf repo &&
@@ -960,8 +957,8 @@ test_expect_success PERL 'missing file in delayed checkout' '
957
grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
958
'
959
963
-test_expect_success PERL 'invalid file in delayed checkout' '
964
- test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
960
+test_expect_success 'invalid file in delayed checkout' '
961
+ test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" &&
962
test_config_global filter.bug.required true &&
963
964
rm -rf repo &&
@@ -990,10 +987,10 @@ do
987
mode_prereq='UTF8_NFD_TO_NFC' ;;
988
esac
989
993
- test_expect_success PERL,SYMLINKS,$mode_prereq \
990
+ test_expect_success SYMLINKS,$mode_prereq \
991
"delayed checkout with $mode-collision don't write to the wrong place" '
992
test_config_global filter.delay.process \
996
- "\"$TEST_ROOT/rot13-filter.pl\" --always-delay delayed.log clean smudge delay" &&
993
+ "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
994
test_config_global filter.delay.required true &&
995
996
git init $mode-collision &&
@@ -1026,12 +1023,12 @@ do
1023
'
1024
done
1025
1029
-test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
1026
+test_expect_success SYMLINKS,CASE_INSENSITIVE_FS \
1027
"delayed checkout with submodule collision don't write to the wrong place" '
1028
git init collision-with-submodule &&
1029
(
1030
cd collision-with-submodule &&
1034
- git config filter.delay.process "\"$TEST_ROOT/rot13-filter.pl\" --always-delay delayed.log clean smudge delay" &&
1031
+ git config filter.delay.process "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
1032
git config filter.delay.required true &&
1033
1034
# We need Git to treat the submodule "a" and the
@@ -1062,11 +1059,11 @@ test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
1059
)
1060
'
1061
1065
-test_expect_success PERL 'setup for progress tests' '
1062
+test_expect_success 'setup for progress tests' '
1063
git init progress &&
1064
(
1065
cd progress &&
1069
- git config filter.delay.process "rot13-filter.pl delay-progress.log clean smudge delay" &&
1066
+ git config filter.delay.process "test-tool rot13-filter --log=delay-progress.log clean smudge delay" &&
1067
git config filter.delay.required true &&
1068
1069
echo "*.a filter=delay" >.gitattributes &&
@@ -1132,12 +1129,12 @@ do
1129
'
1130
done
1131
1135
-test_expect_success PERL 'delayed checkout correctly reports the number of updated entries' '
1132
+test_expect_success 'delayed checkout correctly reports the number of updated entries' '
1133
rm -rf repo &&
1134
git init repo &&
1135
(
1136
cd repo &&
1140
- git config filter.delay.process "../rot13-filter.pl delayed.log clean smudge delay" &&
1137
+ git config filter.delay.process "test-tool rot13-filter --log=delayed.log clean smudge delay" &&
1138
git config filter.delay.required true &&
1139
1140
echo "*.a filter=delay" >.gitattributes &&
t/t0021/rot13-filter.pl
deleted
-247
@@ -1,247 +0,0 @@
1
-#
2
-# Example implementation for the Git filter protocol version 2
3
-# See Documentation/gitattributes.txt, section "Filter Protocol"
4
-#
5
-# Usage: rot13-filter.pl [--always-delay] <log path> <capabilities>
6
-#
7
-# Log path defines a debug log file that the script writes to. The
8
-# subsequent arguments define a list of supported protocol capabilities
9
-# ("clean", "smudge", etc).
10
-#
11
-# When --always-delay is given all pathnames with the "can-delay" flag
12
-# that don't appear on the list bellow are delayed with a count of 1
13
-# (see more below).
14
-#
15
-# This implementation supports special test cases:
16
-# (1) If data with the pathname "clean-write-fail.r" is processed with
17
-# a "clean" operation then the write operation will die.
18
-# (2) If data with the pathname "smudge-write-fail.r" is processed with
19
-# a "smudge" operation then the write operation will die.
20
-# (3) If data with the pathname "error.r" is processed with any
21
-# operation then the filter signals that it cannot or does not want
22
-# to process the file.
23
-# (4) If data with the pathname "abort.r" is processed with any
24
-# operation then the filter signals that it cannot or does not want
25
-# to process the file and any file after that is processed with the
26
-# same command.
27
-# (5) If data with a pathname that is a key in the DELAY hash is
28
-# requested (e.g. "test-delay10.a") then the filter responds with
29
-# a "delay" status and sets the "requested" field in the DELAY hash.
30
-# The filter will signal the availability of this object after
31
-# "count" (field in DELAY hash) "list_available_blobs" commands.
32
-# (6) If data with the pathname "missing-delay.a" is processed that the
33
-# filter will drop the path from the "list_available_blobs" response.
34
-# (7) If data with the pathname "invalid-delay.a" is processed that the
35
-# filter will add the path "unfiltered" which was not delayed before
36
-# to the "list_available_blobs" response.
37
-#
38
-
39
-use 5.008;
40
-sub gitperllib {
41
- # Git assumes that all path lists are Unix-y colon-separated ones. But
42
- # when the Git for Windows executes the test suite, its MSYS2 Bash
43
- # calls git.exe, and colon-separated path lists are converted into
44
- # Windows-y semicolon-separated lists of *Windows* paths (which
45
- # naturally contain a colon after the drive letter, so splitting by
46
- # colons simply does not cut it).
47
- #
48
- # Detect semicolon-separated path list and handle them appropriately.
49
-
50
- if ($ENV{GITPERLLIB} =~ /;/) {
51
- return split(/;/, $ENV{GITPERLLIB});
52
- }
53
- return split(/:/, $ENV{GITPERLLIB});
54
-}
55
-use lib (gitperllib());
56
-use strict;
57
-use warnings;
58
-use IO::File;
59
-use Git::Packet;
60
-
61
-my $MAX_PACKET_CONTENT_SIZE = 65516;
62
-
63
-my $always_delay = 0;
64
-if ( $ARGV[0] eq '--always-delay' ) {
65
- $always_delay = 1;
66
- shift @ARGV;
67
-}
68
-
69
-my $log_file = shift @ARGV;
70
-my @capabilities = @ARGV;
71
-
72
-open my $debug, ">>", $log_file or die "cannot open log file: $!";
73
-
74
-my %DELAY = (
75
- 'test-delay10.a' => { "requested" => 0, "count" => 1 },
76
- 'test-delay11.a' => { "requested" => 0, "count" => 1 },
77
- 'test-delay20.a' => { "requested" => 0, "count" => 2 },
78
- 'test-delay10.b' => { "requested" => 0, "count" => 1 },
79
- 'missing-delay.a' => { "requested" => 0, "count" => 1 },
80
- 'invalid-delay.a' => { "requested" => 0, "count" => 1 },
81
-);
82
-
83
-sub rot13 {
84
- my $str = shift;
85
- $str =~ y/A-Za-z/N-ZA-Mn-za-m/;
86
- return $str;
87
-}
88
-
89
-print $debug "START\n";
90
-$debug->flush();
91
-
92
-packet_initialize("git-filter", 2);
93
-
94
-my %remote_caps = packet_read_and_check_capabilities("clean", "smudge", "delay");
95
-packet_check_and_write_capabilities(\%remote_caps, @capabilities);
96
-
97
-print $debug "init handshake complete\n";
98
-$debug->flush();
99
-
100
-while (1) {
101
- my ( $res, $command ) = packet_key_val_read("command");
102
- if ( $res == -1 ) {
103
- print $debug "STOP\n";
104
- exit();
105
- }
106
- print $debug "IN: $command";
107
- $debug->flush();
108
-
109
- if ( $command eq "list_available_blobs" ) {
110
- # Flush
111
- packet_compare_lists([1, ""], packet_bin_read()) ||
112
- die "bad list_available_blobs end";
113
-
114
- foreach my $pathname ( sort keys %DELAY ) {
115
- if ( $DELAY{$pathname}{"requested"} >= 1 ) {
116
- $DELAY{$pathname}{"count"} = $DELAY{$pathname}{"count"} - 1;
117
- if ( $pathname eq "invalid-delay.a" ) {
118
- # Send Git a pathname that was not delayed earlier
119
- packet_txt_write("pathname=unfiltered");
120
- }
121
- if ( $pathname eq "missing-delay.a" ) {
122
- # Do not signal Git that this file is available
123
- } elsif ( $DELAY{$pathname}{"count"} == 0 ) {
124
- print $debug " $pathname";
125
- packet_txt_write("pathname=$pathname");
126
- }
127
- }
128
- }
129
-
130
- packet_flush();
131
-
132
- print $debug " [OK]\n";
133
- $debug->flush();
134
- packet_txt_write("status=success");
135
- packet_flush();
136
- } else {
137
- my ( $res, $pathname ) = packet_key_val_read("pathname");
138
- if ( $res == -1 ) {
139
- die "unexpected EOF while expecting pathname";
140
- }
141
- print $debug " $pathname";
142
- $debug->flush();
143
-
144
- # Read until flush
145
- my ( $done, $buffer ) = packet_txt_read();
146
- while ( $buffer ne '' ) {
147
- if ( $buffer eq "can-delay=1" ) {
148
- if ( exists $DELAY{$pathname} and $DELAY{$pathname}{"requested"} == 0 ) {
149
- $DELAY{$pathname}{"requested"} = 1;
150
- } elsif ( !exists $DELAY{$pathname} and $always_delay ) {
151
- $DELAY{$pathname} = { "requested" => 1, "count" => 1 };
152
- }
153
- } elsif ($buffer =~ /^(ref|treeish|blob)=/) {
154
- print $debug " $buffer";
155
- } else {
156
- # In general, filters need to be graceful about
157
- # new metadata, since it's documented that we
158
- # can pass any key-value pairs, but for tests,
159
- # let's be a little stricter.
160
- die "Unknown message '$buffer'";
161
- }
162
-
163
- ( $done, $buffer ) = packet_txt_read();
164
- }
165
- if ( $done == -1 ) {
166
- die "unexpected EOF after pathname '$pathname'";
167
- }
168
-
169
- my $input = "";
170
- {
171
- binmode(STDIN);
172
- my $buffer;
173
- my $done = 0;
174
- while ( !$done ) {
175
- ( $done, $buffer ) = packet_bin_read();
176
- $input .= $buffer;
177
- }
178
- if ( $done == -1 ) {
179
- die "unexpected EOF while reading input for '$pathname'";
180
- }
181
- print $debug " " . length($input) . " [OK] -- ";
182
- $debug->flush();
183
- }
184
-
185
- my $output;
186
- if ( exists $DELAY{$pathname} and exists $DELAY{$pathname}{"output"} ) {
187
- $output = $DELAY{$pathname}{"output"}
188
- } elsif ( $pathname eq "error.r" or $pathname eq "abort.r" ) {
189
- $output = "";
190
- } elsif ( $command eq "clean" and grep( /^clean$/, @capabilities ) ) {
191
- $output = rot13($input);
192
- } elsif ( $command eq "smudge" and grep( /^smudge$/, @capabilities ) ) {
193
- $output = rot13($input);
194
- } else {
195
- die "bad command '$command'";
196
- }
197
-
198
- if ( $pathname eq "error.r" ) {
199
- print $debug "[ERROR]\n";
200
- $debug->flush();
201
- packet_txt_write("status=error");
202
- packet_flush();
203
- } elsif ( $pathname eq "abort.r" ) {
204
- print $debug "[ABORT]\n";
205
- $debug->flush();
206
- packet_txt_write("status=abort");
207
- packet_flush();
208
- } elsif ( $command eq "smudge" and
209
- exists $DELAY{$pathname} and
210
- $DELAY{$pathname}{"requested"} == 1 ) {
211
- print $debug "[DELAYED]\n";
212
- $debug->flush();
213
- packet_txt_write("status=delayed");
214
- packet_flush();
215
- $DELAY{$pathname}{"requested"} = 2;
216
- $DELAY{$pathname}{"output"} = $output;
217
- } else {
218
- packet_txt_write("status=success");
219
- packet_flush();
220
-
221
- if ( $pathname eq "${command}-write-fail.r" ) {
222
- print $debug "[WRITE FAIL]\n";
223
- $debug->flush();
224
- die "${command} write error";
225
- }
226
-
227
- print $debug "OUT: " . length($output) . " ";
228
- $debug->flush();
229
-
230
- while ( length($output) > 0 ) {
231
- my $packet = substr( $output, 0, $MAX_PACKET_CONTENT_SIZE );
232
- packet_bin_write($packet);
233
- # dots represent the number of packets
234
- print $debug ".";
235
- if ( length($output) > $MAX_PACKET_CONTENT_SIZE ) {
236
- $output = substr( $output, $MAX_PACKET_CONTENT_SIZE );
237
- } else {
238
- $output = "";
239
- }
240
- }
241
- packet_flush();
242
- print $debug " [OK]\n";
243
- $debug->flush();
244
- packet_flush();
245
- }
246
- }
247
-}
t/t2080-parallel-checkout-basics.sh
+2
-5
@@ -230,12 +230,9 @@ test_expect_success SYMLINKS 'parallel checkout checks for symlinks in leading d
230
# check the final report including sequential, parallel, and delayed entries
231
# all at the same time. So we must have finer control of the parallel checkout
232
# variables.
233
-test_expect_success PERL '"git checkout ." report should not include failed entries' '
234
- write_script rot13-filter.pl "$PERL_PATH" \
235
- <"$TEST_DIRECTORY"/t0021/rot13-filter.pl &&
236
-
233
+test_expect_success '"git checkout ." report should not include failed entries' '
234
test_config_global filter.delay.process \
238
- "\"$(pwd)/rot13-filter.pl\" --always-delay delayed.log clean smudge delay" &&
235
+ "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
236
test_config_global filter.delay.required true &&
237
test_config_global filter.cat.clean cat &&
238
test_config_global filter.cat.smudge cat &&
t/t2082-parallel-checkout-attributes.sh
+2
-5
@@ -138,12 +138,9 @@ test_expect_success 'parallel-checkout and external filter' '
138
# The delayed queue is independent from the parallel queue, and they should be
139
# able to work together in the same checkout process.
140
#
141
-test_expect_success PERL 'parallel-checkout and delayed checkout' '
142
- write_script rot13-filter.pl "$PERL_PATH" \
143
- <"$TEST_DIRECTORY"/t0021/rot13-filter.pl &&
144
-
141
+test_expect_success 'parallel-checkout and delayed checkout' '
142
test_config_global filter.delay.process \
146
- "\"$(pwd)/rot13-filter.pl\" --always-delay \"$(pwd)/delayed.log\" clean smudge delay" &&
143
+ "test-tool rot13-filter --always-delay --log=\"$(pwd)/delayed.log\" clean smudge delay" &&
144
test_config_global filter.delay.required true &&
145
146
echo "abcd" >original &&