@matheusbsbs / matheus-bagliano / commits / e726715a52
Fork 0

Add deltifier test.

This test kicks in only if you built test-delta executable, and makes sure that the basic delta routine is working properly even on empty files. This commit is to make sure we have a test to catch the breakage. The delitifier code is still broken, which will be fixed with the next commit. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 12, 2005 at 12:28 UTC e726715a52e25d8035c89d4ea09398599610737e
2 files changed +52 -2
t/t0001-delta.sh new
+43
@@ -0,0 +1,43 @@
1 +#!/bin/sh
2 +
3 +test_description='Deltification regression test'
4 +
5 +../test-delta 2>/dev/null
6 +test $? == 127 && {
7 + echo "* Skipping test-delta regression test."
8 + exit 0
9 +}
10 +
11 +. ./test-lib.sh
12 +
13 +>empty
14 +echo small >small
15 +echo smallish >smallish
16 +cat ../../COPYING >large
17 +sed -e 's/GNU/G.N.U/g' large >largish
18 +
19 +test_expect_success 'No regression in deltify code' \
20 +'
21 +fail=0
22 +for src in empty small smallish large largish
23 +do
24 + for dst in empty small smallish large largish
25 + do
26 + if test-delta -d $src $dst delta-$src-$dst &&
27 + test-delta -p $src delta-$src-$dst out-$src-$dst &&
28 + cmp $dst out-$src-$dst
29 + then
30 + echo "* OK ($src->$dst deitify and apply)"
31 + else
32 + echo "* FAIL ($src->$dst deitify and apply)"
33 + fail=1
34 + fi
35 + done
36 +done
37 +case "$fail" in
38 +0) (exit 0) ;;
39 +*) (exit $fail) ;;
40 +esac
41 +'
42 +
43 +test_done
test-delta.c
+9 -2
@@ -38,7 +38,10 @@ int main(int argc, char *argv[])
38 return 1;
39 }
40 from_size = st.st_size;
41 - from_buf = mmap(NULL, from_size, PROT_READ, MAP_PRIVATE, fd, 0);
41 + if (from_size)
42 + from_buf = mmap(NULL, from_size, PROT_READ, MAP_PRIVATE, fd, 0);
43 + else
44 + from_buf = "";
45 if (from_buf == MAP_FAILED) {
46 perror(argv[2]);
47 close(fd);
@@ -52,7 +55,11 @@ int main(int argc, char *argv[])
55 return 1;
56 }
57 data_size = st.st_size;
55 - data_buf = mmap(NULL, data_size, PROT_READ, MAP_PRIVATE, fd, 0);
58 +
59 + if (data_size)
60 + data_buf = mmap(NULL, data_size, PROT_READ, MAP_PRIVATE, fd, 0);
61 + else
62 + data_buf = "";
63 if (data_buf == MAP_FAILED) {
64 perror(argv[3]);
65 close(fd);