-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathtest-lib.sh
70 lines (59 loc) · 1.67 KB
/
test-lib.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
# This file is meant to be sourced into other test scripts.
init_test_repo() {
local path="$1"
local description="$2"
delete_test_repo "$path" "$description"
mkdir -p "$path"
git init "$path"
echo "$description" >"$path/.git/description"
printf '%s\n' "/*.out" "/*.css" "/*.html" >"$path/.git/info/exclude"
git --git-dir="$path/.git" config user.name 'Loú User'
git --git-dir="$path/.git" config user.email '[email protected]'
# Reset the timestamp that will be used for commits:
TIME=1112911993
# This CSS file is only for convenience, to make the HTML diagrams
# viewable:
ln -s "$BASE/imerge.css" "$path"
}
delete_test_repo() {
local path="$1"
local description="$2"
if test -d "$path"
then
# Be very careful before running "rm -rf":
if test "x$(cat "$path/.git/description")" = "x$description"
then
echo "Removing directory $path" >&2
rm -rf "$path"
else
echo "Directory $path doesn't look like our test repo!" >&2
exit 1
fi
fi
}
delete_branches() {
for b in "$@"
do
git branch -D $b 2>/dev/null || true
done
}
modify() {
filename="$1"
text="$2"
echo "$text" >"$filename" &&
git add "$filename"
}
commit() {
TIME=$(( TIME + 1 ))
GIT_AUTHOR_DATE="@$TIME +0000" GIT_COMMITTER_DATE="@$TIME +0000" git commit "$@"
}
check_tree () {
local refname="$1"
local expected_tree="$2"
if ! test "$(git rev-parse "$refname^{tree}")" = "$expected_tree"
then
echo "error: the tree for $refname is incorrect!"
git diff "$expected_tree" "$refname"
exit 1
fi
}