Skip to content

Commit 7b990c9

Browse files
committed
vcs-svn: tweak test-line-buffer to not assume line-oriented input
Do not expect an implicit newline after each input record. Use a separate command to exercise buffer_skip_bytes. Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 232087f commit 7b990c9

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

t/t0081-line-buffer.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,44 @@ test_description="Test the svn importer's input handling routines.
77
test_expect_success 'read greeting' '
88
echo HELLO >expect &&
99
test-line-buffer <<-\EOF >actual &&
10-
read 5
10+
read 6
1111
HELLO
1212
EOF
1313
test_cmp expect actual
1414
'
1515

1616
test_expect_success '0-length read, send along greeting' '
17-
printf "%s\n" "" HELLO >expect &&
17+
echo HELLO >expect &&
1818
test-line-buffer <<-\EOF >actual &&
1919
read 0
20-
21-
copy 5
20+
copy 6
2221
HELLO
2322
EOF
2423
test_cmp expect actual
2524
'
2625

27-
test_expect_success 'buffer_read_string copes with trailing null byte' '
28-
echo >expect &&
26+
test_expect_success 'buffer_read_string copes with null byte' '
27+
>expect &&
2928
q_to_nul <<-\EOF | test-line-buffer >actual &&
30-
read 1
29+
read 2
3130
Q
3231
EOF
3332
test_cmp expect actual
3433
'
3534

36-
test_expect_success '0-length read, copy null byte' '
37-
printf "%s\n" "" Q | q_to_nul >expect &&
35+
test_expect_success 'skip, copy null byte' '
36+
echo Q | q_to_nul >expect &&
3837
q_to_nul <<-\EOF | test-line-buffer >actual &&
39-
read 0
40-
41-
copy 1
38+
skip 2
39+
Q
40+
copy 2
4241
Q
4342
EOF
4443
test_cmp expect actual
4544
'
4645

4746
test_expect_success 'long reads are truncated' '
48-
printf "%s\n" foo "" >expect &&
47+
echo foo >expect &&
4948
test-line-buffer <<-\EOF >actual &&
5049
read 5
5150
foo
@@ -56,7 +55,7 @@ test_expect_success 'long reads are truncated' '
5655
test_expect_success 'long copies are truncated' '
5756
printf "%s\n" "" foo >expect &&
5857
test-line-buffer <<-\EOF >actual &&
59-
read 0
58+
read 1
6059
6160
copy 5
6261
foo

test-line-buffer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ static void handle_command(const char *command, const char *arg, struct line_buf
1919
switch (*command) {
2020
case 'c':
2121
if (!prefixcmp(command, "copy ")) {
22-
buffer_copy_bytes(buf, strtouint32(arg) + 1);
22+
buffer_copy_bytes(buf, strtouint32(arg));
2323
return;
2424
}
2525
case 'r':
2626
if (!prefixcmp(command, "read ")) {
2727
const char *s = buffer_read_string(buf, strtouint32(arg));
28-
printf("%s\n", s);
29-
buffer_skip_bytes(buf, 1); /* consume newline */
28+
fputs(s, stdout);
29+
return;
30+
}
31+
case 's':
32+
if (!prefixcmp(command, "skip ")) {
33+
buffer_skip_bytes(buf, strtouint32(arg));
3034
return;
3135
}
3236
default:

0 commit comments

Comments
 (0)