-
Notifications
You must be signed in to change notification settings - Fork 0
/
test01.sh
94 lines (72 loc) · 1.73 KB
/
test01.sh
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
#!/bin/dash
# if .girt directory exist already, remove it for testing
if test -d ".girt/"
then
rm -r ".girt/"
fi
failed=0
###testing girt-add error messages and functionality###
echo ""
echo "<<<<<<<<<<<<<<<START>>>>>>>>>>>>>>>"
echo ""
# error - calling before init - exit 1
sh girt-add
test $? -eq 1 || failed=1
# initialising .girt
sh girt-init
test $? -eq 0 || failed=1
# creating files to add
seq 1 10 >> a
seq 1 10 >> b
seq 1 10 >> c
# error - girt-add needs filenames - output usage - exit 1
sh girt-add
test $? -eq 1 || failed=1
# error - file cannot open - exit 1
sh girt-add d
test $? -eq 1 || failed=1
# error - invalid filenames regardless of whetehr or not they exit - exit 1
touch .e
sh girt-add .e
test $? -eq 1 || failed=1
sh girt-add _f
test $? -eq 1 || failed=1
# add file or files to index regardless of whether they are changed - exit 0
sh girt-add a
test $? -eq 0 || failed=1
sh girt-add b c
test $? -eq 0 || failed=1
sh girt-add a b
test $? -eq 0 || failed=1
# add files to index after they are changed - exit 0
seq 11 20 >> a
seq 20 30 >> b
sh girt-add a b
test $? -eq 0 || failed=1
# check contents of the files in index are same as the one in cwd
for indexed_file in ".girt/index/"*
do
base_name=$(echo "$indexed_file" | cut -d'/' -f3)
if diff "$base_name" "$indexed_file" >/dev/null
then
echo "$base_name is added correctly"
else
echo "ERROR: $base_name is not added correctly" 1>&2
fi
done
# clean-up
rm -r .girt
rm a b c .e
echo ""
echo "<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>"
echo ""
if test "$failed" -eq 1
then
echo "***************TEST FAILED***************" 1>&2
echo ""
exit 1
else
echo "***************TEST PASSED***************" 1>&2
echo ""
exit 0
fi