-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·118 lines (105 loc) · 2.44 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
P="$(pwd)/hashsum"
T=test-directory
setup_files ()
{
d=$1
printf abcd > $d/x
mkdir $d/bar
printf 1234 > $d/bar/y
}
verify_output ()
{
diff -u - $1 <<EOF
81dc9bdb52d04dc20036dbd8313ed055 bar/y
e2fc714c4727ee9395f324cd2e7f331f x
EOF
}
rm -rf $T
mkdir $T
cd $T
# Basic operation.
mkdir t0
setup_files t0
$P t0 -C t0.md5cache > t0.md5sum
verify_output t0.md5sum
# Garbage cache file (short).
mkdir t1
printf garbage > t1.md5cache
setup_files t1
$P t1 -C t1.md5cache > t1.md5sum 2> t1.stderr
verify_output t1.md5sum
diff -u - t1.stderr <<EOF
Could not load cachefile:
Could not read file header
EOF
# Garbage cache file (longer).
mkdir t2
printf garbagegarbagegarbage > t2.md5cache
setup_files t2
$P t2 -C t2.md5cache > t2.md5sum 2> t2.stderr
verify_output t2.md5sum
diff -u - t2.stderr <<EOF
Could not load cachefile:
Wrong magic number (expected 0x7206fab738a48740, got 0x6765676162726167)
EOF
# Garbage cache file (decryption error).
mkdir t3
python3 <<EOF
import struct
with open('t3.md5cache', 'wb') as f:
f.write(struct.pack('<QL', 0x7206fab738a48740, 4711))
EOF
setup_files t3
$P t3 -C t3.md5cache > t3.md5sum 2> t3.stderr
verify_output t3.md5sum
diff -u - t3.stderr <<EOF
Could not load cachefile:
Error -5 while decompressing data
EOF
# Garbage cache file (wrong version).
mkdir t4
python3 <<EOF
import struct, zlib
with open('t4.md5cache', 'wb') as f:
f.write(struct.pack('<QL', 0x7206fab738a48740, 4711))
f.write(zlib.compress(b'foobar'))
EOF
setup_files t4
$P t4 -C t4.md5cache > t4.md5sum 2> t4.stderr
verify_output t4.md5sum
diff -u - t4.stderr <<EOF
Could not load cachefile:
Unsupported version (4711)
EOF
# Garbage cache file (pickle error).
mkdir t5
python3 <<EOF
import pickle, struct, zlib
with open('t5.md5cache', 'wb') as f:
f.write(struct.pack('<QL', 0x7206fab738a48740, 0))
f.write(zlib.compress(b'foobar'))
EOF
setup_files t5
$P t5 -C t5.md5cache > t5.md5sum 2> t5.stderr
verify_output t5.md5sum
diff -u - t5.stderr <<EOF
Malformed cachefile
EOF
# Cache file in nonexisting directory.
mkdir t6
setup_files t6
$P t6 -C /doesntexist/t6.md5cache > t6.md5sum 2> t6.stderr
verify_output t6.md5sum
diff -u - t6.stderr <<EOF
Could not write cachefile:
[Errno 2] No such file or directory: '/doesntexist/t6.md5cache'
EOF
# Test that cachefiles can be read back.
mkdir t7
setup_files t7
$P t7 -C t7.md5cache > t7.md5sum
verify_output t7.md5sum
$P t7 -C t7.md5cache > t7.md5sum
verify_output t7.md5sum
printf "Done\n"