-
Notifications
You must be signed in to change notification settings - Fork 85
/
test-branches.sh
executable file
·104 lines (77 loc) · 1.8 KB
/
test-branches.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
104
scriptDir="$(cd "$(dirname "$0")"; pwd)"
source "$scriptDir/radar-base.sh"
tmpfile=""
cd_to_tmp() {
tmpfile="/tmp/git-prompt-tests-$(time_now)"
mkdir -p "$tmpfile"
cd "$tmpfile"
}
rm_tmp() {
cd $scriptDir
rm -rf /tmp/git-prompt-tests*
}
test_branch_name_in_repo() {
cd_to_tmp
git init --quiet
git checkout -b foo --quiet
assertEquals "foo" "$(branch_name)"
git checkout -b bar --quiet
assertEquals "bar" "$(branch_name)"
git checkout -b baz --quiet
assertEquals "baz" "$(branch_name)"
rm_tmp
}
test_branch_name_not_in_repo() {
cd_to_tmp
assertEquals "" "$(branch_name)"
rm_tmp
}
test_detached_from_branch() {
cd_to_tmp
git init --quiet
assertEquals "master" "$(branch_name)"
touch README
git add .
git commit -m "initial commit" --quiet
touch foo
git add .
git commit -m "foo" --quiet
git checkout --quiet HEAD^ >/dev/null
sha="$(commit_short_sha)"
assertNotEquals "master" "$(branch_name)"
assertEquals "$sha" "$(branch_ref)"
assertEquals "detached@$sha" "$(zsh_readable_branch_name)"
assertEquals "detached@$sha" "$(bash_readable_branch_name)"
assertEquals "detached@$sha" "$(readable_branch_name)"
rm_tmp
}
test_branch_name_returns_error() {
cd_to_tmp
git init --quiet
touch README
git add .
git commit -m "initial commit" --quiet
touch foo
git add .
git commit -m "foo" --quiet
git checkout --quiet HEAD^ >/dev/null
retcode="$(branch_name; echo $?)"
assertEquals "1" "$retcode"
rm_tmp
}
test_remote_branch_name_quiet_when_not_in_repo() {
cd_to_tmp
debug_output="$(
{
output="$(
remote_branch_name;
)"
} 2>&1
echo "$output"
)"
usages="$(echo "$debug_output" | grep -E "(usage|fatal):" | wc -l)"
echo "$debug_output"
assertEquals " 0" "$usages"
rm_tmp
}
. ./shunit/shunit2