-
Notifications
You must be signed in to change notification settings - Fork 0
/
test02.sh
103 lines (81 loc) · 2.13 KB
/
test02.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
94
95
96
97
98
99
100
101
102
103
#!/bin/dash
# if .girt directory exist already, remove it for testing
if test -d ".girt/"
then
rm -r ".girt/"
fi
failed=0
###testing girt-commit error messages with functionality and different options###
echo ""
echo "<<<<<<<<<<<<<<<START>>>>>>>>>>>>>>>"
echo ""
# error - calling girt-commit before init - exit 1
sh girt-commit -m "message"
test $? -eq 1 || failed=1
sh girt-init
test $? -eq 0 || failed=1
# error - output correct usage - exit 1
sh girt-commit
test $? -eq 1 || failed=1
sh girt-commit -m -m "message"
test $? -eq 1 || failed=1
# nothgin to commit - exit 0
sh girt-commit -m "message"
test $? -eq 0 || failed=1
# creating files - add them - make the first commit
seq 1 10 >> a
seq 1 10 >> b
sh girt-add a b
test $? -eq 0 || failed=1
# makes commit with message commit-0 - exit 0
sh girt-commit -m "commit-0"
test $? -eq 0 || failed=1
# check the files exist in commit repo and they have the same content as index
for committed_file in ".girt/commit/0/"*
do
base_name=$(echo "$committed_file" | cut -d'/' -f4)
if diff ".girt/index/$base_name" "$committed_file" >/dev/null
then
echo "$base_name same as repo"
else
echo "ERROR: $committed_file not commited properly"
fi
done
# nothing to commit - exit 0
sh girt-commit -m "commit-1"
test $? -eq 0 || failed=1
# change b
seq 11 20 >> b
# add b to index
sh girt-add b
test $? -eq 0 || failed=1
# new commit as the contents of index are changed
sh girt-commit -m "commit-1"
test $? -eq 0 || failed=1
# check the files exist in commit repo and they have the same content as index
for committed_file in ".girt/commit/1/"*
do
base_name=$(echo "$committed_file" | cut -d'/' -f4)
if diff ".girt/index/$base_name" "$committed_file" >/dev/null
then
echo "$base_name same as repo"
else
echo "ERROR: $committed_file not commited properly"
fi
done
# clean-up
rm a b
rm -r .girt
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