-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.bats
executable file
·211 lines (158 loc) · 4.39 KB
/
tests.bats
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bats
load 'test/helpers/assert/load'
load 'test/helpers/support/load'
load 'test/helpers/mocks/stub'
stubs=(git)
cwd="$PWD"
tmp="$(mktemp -d)"
setup() {
# There might be leftovers from previous runs.
for stub in "${stubs[@]}"; do
unstub "$stub" 2> /dev/null || true
done
pushd "$tmp" > /dev/null
}
teardown() {
popd > /dev/null
rm -rf "$tmp"
for stub in "${stubs[@]}"; do
unstub "$stub" || true
done
}
@test 'no arguments' {
git init
git config --local user.name test
git config --local user.email [email protected]
run "$cwd/git-some"
assert_success
assert_line --partial --index 0 '[master (root-commit)'
assert [ -f A.txt ]
}
@test 'number of commits' {
git init
git config --local user.name test
git config --local user.email [email protected]
run "$cwd/git-some" 2
assert_success
assert_line --partial --index 0 '[master (root-commit)'
assert_line --partial --index 3 '[master '
assert [ -f A.txt ]
assert [ -f B.txt ]
}
@test 'number of commits is larger than can be represented by a single character' {
git init
git config --local user.name test
git config --local user.email [email protected]
run "$cwd/git-some" $((26 + 1))
assert_success
assert [ -f AA.txt ]
}
@test 'number of commits is much larger than can be represented by a single character' {
git init
git config --local user.name test
git config --local user.email [email protected]
run "$cwd/git-some" 100
assert_success
assert [ -f CV.txt ]
}
@test 'number of commits is negative' {
run "$cwd/git-some" -1
assert_failure 129
assert_line "error: unknown switch \`1'"
}
@test 'number of commits is a character' {
run "$cwd/git-some" a
assert_failure 1
assert_line 'Need a positive number for number of commits to generate, got: a'
}
@test 'number of commits is a numeric expression' {
run "$cwd/git-some" 1+1
assert_failure 1
assert_line 'Need a positive number for number of commits to generate, got: 1+1'
}
@test 'number of commits is non-numeric' {
run "$cwd/git-some" 42a
assert_failure 1
assert_line 'Need a positive number for number of commits to generate, got: 42a'
}
@test 'file to generate already exists' {
git init
git config --local user.name test
git config --local user.email [email protected]
touch A.txt
run "$cwd/git-some"
assert_failure 1
assert_line 'A.txt already exists but it should not.'
}
@test 'git add fails' {
git init
git config --local user.name test
git config --local user.email [email protected]
stub git \
"rev-parse : echo set -- --" \
"symbolic-ref : echo master" \
"rev-list : echo 0" \
'add : exit 1'
run "$cwd/git-some"
assert_failure 2
# There should be no leftovers.
refute [ -f *.txt ]
}
@test 'git commit fails' {
git init
git config --local user.name test
git config --local user.email [email protected]
# Need to reimplement with system git here, because the git stub cannot
# delegate to it.
git="$(which git)"
stub git \
"rev-parse : echo set -- --" \
"symbolic-ref : echo master" \
"rev-list : echo 0" \
"add : '$git' add ." \
'commit : exit 1' \
"rm : '$git' rm --force -- *.txt"
run "$cwd/git-some"
assert_failure 4
# There should be no leftovers.
refute [ -f *.txt ]
}
@test 'default commit message prefix on master' {
git init
git config --local user.name test
git config --local user.email [email protected]
"$cwd/git-some"
run git log --oneline --format=%s
assert_success
assert_line --partial 'master: '
}
@test 'default commit message prefix on topic' {
git init
git config --local user.name test
git config --local user.email [email protected]
git checkout -b topic
"$cwd/git-some"
run git log --oneline --format=%s
assert_success
assert_line --partial 'topic: '
}
@test 'default commit message prefix in detached HEAD state' {
git init
git config --local user.name test
git config --local user.email [email protected]
"$cwd/git-some"
git checkout --detach
"$cwd/git-some"
run git log --oneline --format=%s
assert_success
assert_line --partial 'detached HEAD: '
}
@test 'custom commit message prefix' {
git init
git config --local user.name test
git config --local user.email [email protected]
"$cwd/git-some" --message 'some prefix' 2
run git log --oneline --format=%s
assert_success
assert_line --partial 'some prefix: '
}