-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeatures.bats
499 lines (406 loc) · 12.8 KB
/
features.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
#!/usr/bin/env bats
# Acceptance test suite, made with BATS.
# https://github.com/bats-core/bats-core
# Run:
# make test-acceptance
# We use git-spend's own repo as fixture for tests. (🐕 woof)
# We copy this project into a temporary fixture dir (in RAM),
# and then have it check out the appropriate fixture-XX tag,
# and finally run integration testing on that temporary repo.
# See the setup() BATS hook defined at the bottom of this file.
# THIS DIRECTORY WILL BE `RM -RF` SO BEWARE OF WHAT'S IN THERE.
TMP_FIXTURE_DIR="/tmp/git-spend-fixture"
@test "git-spend" {
run "${git_spend}"
assert_success
assert_output --partial 'Manage time-tracking /spent directives in commit messages'
}
@test "git-spend hohohoooo should fail" {
run "${git_spend}" hohohoooo
assert_failure
}
@test "git-spend help sum" {
run "${git_spend}" help sum
assert_success
}
@test "git-spend sum --help" {
run "${git_spend}" sum --help
assert_success
assert_output --partial 'The /spend and /spent directives will be parsed and summed'
}
@test "git-spend sum" {
run "${git_spend}" sum
assert_success
assert_output "1 week 3 hours"
}
@test "git-spend sum --target <dir>" {
cd "${PROJECT_DIR}"
run "${git_spend}" sum --target "${TMP_FIXTURE_DIR}"
assert_success
assert_output "1 week 3 hours"
}
@test "git-spend sum --target <404 dir> should fail" {
run "${git_spend}" sum --target "/to/code/or/not/to/code"
assert_failure
}
@test "git-spend sum --minutes" {
run "${git_spend}" sum --minutes
assert_success
assert_output "2580"
}
@test "git-spend sum --hours" {
run "${git_spend}" sum --hours
assert_success
assert_output "43"
}
@test "git-spend sum --days" {
run "${git_spend}" sum --days
assert_success
assert_output "5"
}
@test "git-spend sum --weeks" {
run "${git_spend}" sum --weeks
assert_success
assert_output "1"
}
@test "git-spend sum --months" {
run "${git_spend}" sum --months
assert_success
assert_output "0"
}
@test "git-spend sum unit formats are mutually exclusive" {
run "${git_spend}" sum --months --days
assert_failure
run "${git_spend}" sum --hours --minutes --weeks
assert_failure
}
@test "git-spend sum --author Goutte" {
run "${git_spend}" sum --author Goutte
assert_success
assert_output "1 week 3 hours"
}
@test "git-spend sum --author antoine@goutenoir.com" {
run "${git_spend}" sum --author antoine@goutenoir.com
assert_success
assert_output "1 week 3 hours"
}
@test "git-spend sum --author notfound (should fail)" {
run "${git_spend}" sum --author notfound
# shouldn't we fail, here? TBD
#assert_failure
assert_success # …meanwhile
assert_output --partial "No time-tracking /spend directives found in commits"
}
@test "git-spend sum --since <commit>" {
run "${git_spend}" sum --since 786a30642fe37368b0b65cbca8ca1a5c4b6c97b8
assert_success
assert_output "1 day 6 hours 3 minutes"
}
@test "git-spend sum --since <commit short>" {
run "${git_spend}" sum --since 786a3064
assert_success
assert_output "1 day 6 hours 3 minutes"
}
@test "git-spend sum --since <tag>" {
run "${git_spend}" sum --since 0.2.0
assert_success
assert_output "1 day 6 hours 3 minutes"
}
@test "git-spend sum --since <absent commit short>" {
run "${git_spend}" sum --since caca999
assert_failure
}
@test "git-spend sum --since <wrong> (should fail)" {
run "${git_spend}" sum --since lololololo
assert_failure
}
@test "git-spend sum --until <commit>" {
run "${git_spend}" sum --until 786a30642fe37368b0b65cbca8ca1a5c4b6c97b8
assert_success
assert_output "3 days 4 hours 57 minutes"
}
@test "git-spend sum --until <commit short>" {
run "${git_spend}" sum --until 786a3064
assert_success
assert_output "3 days 4 hours 57 minutes"
}
@test "git-spend sum --until <tag>" {
run "${git_spend}" sum --until 0.2.0
assert_success
assert_output "3 days 4 hours 57 minutes"
}
@test "git-spend sum --until <absent commit short>" {
run "${git_spend}" sum --until caca666
assert_failure
}
@test "git-spend sum --until <wrong>" {
run "${git_spend}" sum --until trololololo
assert_failure
}
@test "git-spend sum --until 0.1.0" {
run "${git_spend}" sum --until 0.1.0
assert_success
assert_output "1 day 7 hours 57 minutes"
}
@test "git-spend sum --until tags/<tag>" {
run "${git_spend}" sum --until tags/0.1.0
assert_success
assert_output "1 day 7 hours 57 minutes"
}
@test "git-spend sum --since 0.1.0" {
run "${git_spend}" sum --since 0.1.0
assert_success
assert_output "3 days 3 hours 3 minutes"
}
@test "git-spend sum --since 0.1.0 --until 0.1.1" {
run "${git_spend}" sum --since 0.1.0 --until 0.1.1
assert_success
assert_output "30 minutes"
}
@test "git-spend sum --since <date>" {
run "${git_spend}" sum --since 2023-03-27
assert_success
assert_output "2 hours"
}
@test "git-spend sum --since <date time>" {
run "${git_spend}" sum --since "2023-03-26 22:15:00"
assert_success
assert_output "2 hours 1 minute"
# Want to tolerate missing minutes, but no cigar ; time parsing in Golang is quite peculiar
# This can still be done, and would be nice, but I find my solution to be … inelegant. #mr-welcome
#run "${git_spend}" sum --since "2023-03-26 22:15"
#run "${git_spend}" sum --since "2023-03" # and perhaps this as well?
#assert_success
}
@test "git-spend sum --since <date rfc3339>" {
run "${git_spend}" sum --since 2023-03-26T22:15:00Z
assert_success
assert_output "2 hours 1 minute"
}
@test "git-spend sum --until <date>" {
run "${git_spend}" sum --until 2023-03-25
assert_success
assert_output "1 day 3 hours 55 minutes"
}
@test "git-spend sum --since <date> --until <date>" {
run "${git_spend}" sum --since "2023-03-25 03:30:00" --until "2023-03-25 13:37:00"
assert_success
assert_output "2 hours 15 minutes"
}
@test "git-spend sum but nothing was found" {
run "${git_spend}" sum --since "2023-03-25" --until "2023-03-25"
assert_success
assert_output --partial "No time-tracking /spend directives found in commits"
}
@test "git-spend sum does not accept mixed dates and refs in ranges" {
run "${git_spend}" sum --until 2023-03-27 --since 0.1.0
assert_failure
run "${git_spend}" sum --since 2023-03-24 --until 0.2.0
assert_failure
}
@test "git-spend sum ignores stdin by default" {
run bash -c "cat 0.1.0.log | $git_spend sum"
assert_success
assert_output "1 week 3 hours" # and not "1 day 7 hours 57 minutes" for 0.1.0
}
@test "git-spend sum --stdin using |" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin"
assert_success
assert_output "1 week 3 hours"
run bash -c "cat 0.1.0.log | $git_spend sum --stdin"
assert_success
assert_output "1 day 7 hours 57 minutes" # and not "1 week 3 hours"
}
@test "git-spend sum --stdin using <" {
run bash -c "$git_spend sum --stdin < fixture-00.log"
assert_success
assert_output "1 week 3 hours"
run bash -c "$git_spend sum --stdin < 0.1.0.log"
assert_success
assert_output "1 day 7 hours 57 minutes"
}
@test "git-spend sum --stdin does not accept --target" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin --target ${PROJECT_DIR}"
assert_failure
}
@test "git-spend sum --stdin does not accept --no-merges" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin --no-merges"
assert_failure
}
@test "git-spend sum --stdin does not accept --author" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin --author Goutte"
assert_failure
}
@test "git-spend sum --stdin does not accept --since" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin --since 0.1.0"
assert_failure
}
@test "git-spend sum --stdin does not accept --until" {
run bash -c "cat fixture-00.log | $git_spend sum --stdin --until 0.1.0"
assert_failure
}
@test "Support for GIT_SPEND_MINUTES_IN_ONE_HOUR" {
export GIT_SPEND_MINUTES_IN_ONE_HOUR=10
run "${git_spend}" sum --since HEAD~1 --minutes
assert_success
assert_output "20" # instead of 120 (converted from 2h)
}
@test "Support for alias GIT_SPEND_MINUTES_PER_HOUR" {
export GIT_SPEND_MINUTES_PER_HOUR=30
run "${git_spend}" sum --since HEAD~1 --minutes
assert_success
assert_output "60" # instead of 120 (converted from 2h)
}
@test "LANGUAGE=fr_FR git-spend" {
# shellcheck disable=SC2030
export LANGUAGE=fr_FR
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "LANGUAGE=fr git-spend" {
# shellcheck disable=SC2030
export LANGUAGE=fr
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "LC_ALL=fr_FR git-spend" {
unset LANGUAGE
# shellcheck disable=SC2030
export LC_ALL=fr_FR
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "LANG=fr_FR git-spend" {
unset LANGUAGE
unset LC_ALL
# shellcheck disable=SC2030
export LANG=fr_FR
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "LANG=fr git-spend sum" {
unset LANGUAGE
unset LC_ALL
# shellcheck disable=SC2030
export LANG=fr
run "${git_spend}" sum --until tags/0.1.0
assert_success
assert_output '1 jour 7 heures 57 minutes'
}
@test "LC_ALL has priority over LANG" {
unset LANGUAGE
export LANG=en_US
# shellcheck disable=SC2030
export LC_ALL=fr_FR
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "LANGUAGE has priority over LC_ALL" {
# shellcheck disable=SC2030
export LANGUAGE=fr_FR
export LC_ALL=en_US
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "Default language is english" {
unset LANGUAGE
unset LC_ALL
unset LANG
run "${git_spend}"
assert_success
assert_output --partial 'Manage time-tracking /spent directives in commit messages'
}
@test "Unhandled language falls back to english" {
# shellcheck disable=SC2030
export LANGUAGE="es_CL"
run "${git_spend}"
assert_success
assert_output --partial 'Manage time-tracking /spent directives in commit messages'
}
@test "Unhandled locale should fallback to default locale if language is handled" {
export LANGUAGE="fr_CA"
run "${git_spend}"
assert_success
assert_output --partial 'Gérer les directives /spend inscrites dans les messages de commit'
}
@test "Generate man pages" {
run "${git_spend}" man
assert_success
}
@test "Generating man pages" {
run "${git_spend}" man --output /usr/local/share/man/man8
run "${git_spend}" man --install
# no assertions for now (CI runs root-like)
}
@test "Installing man pages requires sudo" {
skip # hehe, CI is root, I forgot ; coverage will lower, but that's OK
run "${git_spend}" man --output /usr/local/share/man/man8
assert_failure
assert_output --partial 'permission denied'
run "${git_spend}" man --output /usr/share/man/man8
assert_failure
assert_output --partial 'permission denied'
run "${git_spend}" man --install
assert_failure
assert_output --partial 'permission denied'
}
@test "Rewrite /spend HEAD" {
skip # wip
# 1. Install the hooks
run "${git_spend}" hook --install
# 2.a. Add a commit, but pretend it was 5 minutes ago
touch some_new_file && git add some_new_file
minutes_ago=$(date -d "-5minutes" --iso-8601=minutes)
git commit --date "$minutes_ago" -vm 'test
/spend 7m'
# 2.b. Check that adding that commit went well
run "${git_spend}" sum --since HEAD~1 --minutes
assert_success
assert_output '7'
run git log HEAD~1..HEAD
assert_success
assert_output --partial '/spend 7m'
# 3.a. Add another commit, this time using "/spend HEAD"
touch some_other_file && git add some_other_file
git commit -vm 'test: another
/spend HEAD'
# 3.b. Hopefully the rewrite hook did its job
run git log HEAD~1..HEAD
assert_success
assert_output --partial '/spend 5m'
}
# ---
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
export TZ="Europe/Paris"
TESTS_DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR="$( dirname "$TESTS_DIR" )"
COVERAGE_DIR="${PROJECT_DIR}/test-coverage"
git_spend="${PROJECT_DIR}/build/git-spend"
cd "${PROJECT_DIR}" || exit
if [ "$GIT_SPEND_COVERAGE" == "1" ] ; then
echo "Setting up coverage in ${COVERAGE_DIR}"
mkdir -p "${COVERAGE_DIR}"
export GOCOVERDIR=${COVERAGE_DIR}
git_spend="${git_spend}-coverage"
fi
cp -R "${PROJECT_DIR}" "${TMP_FIXTURE_DIR}"
cd "${TMP_FIXTURE_DIR}" || exit
git stash
git checkout tags/fixture-00 -b fixture-00
echo "success: ignore the unable to rmdir warning above (benign)"
git log > fixture-00.log
git log 0.1.0 > 0.1.0.log
}
teardown() {
rm -rf $TMP_FIXTURE_DIR
rm -f fixture-00.log
rm -f 0.1.0.log
}