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 <jrnieder@gmail.com>
Jonathan Nieder committed
Jan 2, 2011 at 18:52 UTC
7b990c90514b24097ee71edbc02cb3a497a9476b
2 files changed
+20
-17
t/t0081-line-buffer.sh
+13
-14
@@ -7,45 +7,44 @@ test_description="Test the svn importer's input handling routines.
7
test_expect_success 'read greeting' '
8
echo HELLO >expect &&
9
test-line-buffer <<-\EOF >actual &&
10
- read 5
10
+ read 6
11
HELLO
12
EOF
13
test_cmp expect actual
14
'
15
16
test_expect_success '0-length read, send along greeting' '
17
- printf "%s\n" "" HELLO >expect &&
17
+ echo HELLO >expect &&
18
test-line-buffer <<-\EOF >actual &&
19
read 0
20
-
21
- copy 5
20
+ copy 6
21
HELLO
22
EOF
23
test_cmp expect actual
24
'
25
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 &&
28
q_to_nul <<-\EOF | test-line-buffer >actual &&
30
- read 1
29
+ read 2
30
Q
31
EOF
32
test_cmp expect actual
33
'
34
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 &&
37
q_to_nul <<-\EOF | test-line-buffer >actual &&
39
- read 0
40
-
41
- copy 1
38
+ skip 2
39
+ Q
40
+ copy 2
41
Q
42
EOF
43
test_cmp expect actual
44
'
45
46
test_expect_success 'long reads are truncated' '
48
- printf "%s\n" foo "" >expect &&
47
+ echo foo >expect &&
48
test-line-buffer <<-\EOF >actual &&
49
read 5
50
foo
@@ -56,7 +55,7 @@ test_expect_success 'long reads are truncated' '
55
test_expect_success 'long copies are truncated' '
56
printf "%s\n" "" foo >expect &&
57
test-line-buffer <<-\EOF >actual &&
59
- read 0
58
+ read 1
59
60
copy 5
61
foo
test-line-buffer.c
+7
-3
@@ -19,14 +19,18 @@ static void handle_command(const char *command, const char *arg, struct line_buf
19
switch (*command) {
20
case 'c':
21
if (!prefixcmp(command, "copy ")) {
22
- buffer_copy_bytes(buf, strtouint32(arg) + 1);
22
+ buffer_copy_bytes(buf, strtouint32(arg));
23
return;
24
}
25
case 'r':
26
if (!prefixcmp(command, "read ")) {
27
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));
34
return;
35
}
36
default: