]>
Commit | Line | Data |
---|---|---|
238b439d ES |
1 | #!/bin/sh |
2 | ||
3 | test_description='git bugreport' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | # Headers "[System Info]" will be followed by a non-empty line if we put some | |
8 | # information there; we can make sure all our headers were followed by some | |
9 | # information to check if the command was successful. | |
10 | HEADER_PATTERN="^\[.*\]$" | |
11 | ||
12 | check_all_headers_populated () { | |
13 | while read -r line | |
14 | do | |
15 | if test "$(grep "$HEADER_PATTERN" "$line")" | |
16 | then | |
17 | echo "$line" | |
18 | read -r nextline | |
19 | if test -z "$nextline"; then | |
20 | return 1; | |
21 | fi | |
22 | fi | |
23 | done | |
24 | } | |
25 | ||
26 | test_expect_success 'creates a report with content in the right places' ' | |
27 | test_when_finished rm git-bugreport-check-headers.txt && | |
28 | git bugreport -s check-headers && | |
29 | check_all_headers_populated <git-bugreport-check-headers.txt | |
30 | ' | |
31 | ||
32 | test_expect_success 'dies if file with same name as report already exists' ' | |
33 | test_when_finished rm git-bugreport-duplicate.txt && | |
34 | >>git-bugreport-duplicate.txt && | |
35 | test_must_fail git bugreport --suffix duplicate | |
36 | ' | |
37 | ||
38 | test_expect_success '--output-directory puts the report in the provided dir' ' | |
39 | test_when_finished rm -fr foo/ && | |
40 | git bugreport -o foo/ && | |
41 | test_path_is_file foo/git-bugreport-* | |
42 | ' | |
43 | ||
44 | test_expect_success 'incorrect arguments abort with usage' ' | |
45 | test_must_fail git bugreport --false 2>output && | |
46 | test_i18ngrep usage output && | |
47 | test_path_is_missing git-bugreport-* | |
48 | ' | |
49 | ||
50 | test_expect_success 'runs outside of a git dir' ' | |
51 | test_when_finished rm non-repo/git-bugreport-* && | |
52 | nongit git bugreport | |
53 | ' | |
54 | ||
55 | test_expect_success 'can create leading directories outside of a git dir' ' | |
56 | test_when_finished rm -fr foo/bar/baz && | |
57 | nongit git bugreport -o foo/bar/baz | |
58 | ' | |
59 | ||
788a7760 ES |
60 | test_expect_success 'indicates populated hooks' ' |
61 | test_when_finished rm git-bugreport-hooks.txt && | |
62 | test_when_finished rm -fr .git/hooks && | |
63 | rm -fr .git/hooks && | |
64 | mkdir .git/hooks && | |
65 | for hook in applypatch-msg prepare-commit-msg.sample | |
66 | do | |
67 | write_script ".git/hooks/$hook" <<-EOF || return 1 | |
68 | echo "hook $hook exists" | |
69 | EOF | |
70 | done && | |
71 | git bugreport -s hooks && | |
72 | grep applypatch-msg git-bugreport-hooks.txt && | |
73 | ! grep prepare-commit-msg git-bugreport-hooks.txt | |
74 | ' | |
238b439d ES |
75 | |
76 | test_done |