| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git bugreport' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'create a report' ' |
| 8 | git bugreport -s format && |
| 9 | test_file_not_empty git-bugreport-format.txt |
| 10 | ' |
| 11 | |
| 12 | test_expect_success 'report contains wanted template (before first section)' ' |
| 13 | sed -ne "/^\[/q;p" git-bugreport-format.txt >actual && |
| 14 | cat >expect <<-\EOF && |
| 15 | Thank you for filling out a Git bug report! |
| 16 | Please answer the following questions to help us understand your issue. |
| 17 | |
| 18 | What did you do before the bug happened? (Steps to reproduce your issue) |
| 19 | |
| 20 | What did you expect to happen? (Expected behavior) |
| 21 | |
| 22 | What happened instead? (Actual behavior) |
| 23 | |
| 24 | What'\''s different between what you expected and what actually happened? |
| 25 | |
| 26 | Anything else you want to add: |
| 27 | |
| 28 | Please review the rest of the bug report below. |
| 29 | You can delete any lines you don'\''t wish to share. |
| 30 | |
| 31 | |
| 32 | EOF |
| 33 | test_cmp expect actual |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'sanity check "System Info" section' ' |
| 37 | test_when_finished rm -f git-bugreport-format.txt && |
| 38 | |
| 39 | sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system && |
| 40 | |
| 41 | # The beginning should match "git version --build-options" verbatim, |
| 42 | # but rather than checking bit-for-bit equality, just test some basics. |
| 43 | grep "git version " system && |
| 44 | grep "shell-path: ." system && |
| 45 | |
| 46 | # After the version, there should be some more info. |
| 47 | # This is bound to differ from environment to environment, |
| 48 | # so we just do some rather high-level checks. |
| 49 | grep "uname: ." system && |
| 50 | grep "compiler info: ." system && |
| 51 | grep "zlib." system |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'dies if file with same name as report already exists' ' |
| 55 | test_when_finished rm git-bugreport-duplicate.txt && |
| 56 | >>git-bugreport-duplicate.txt && |
| 57 | test_must_fail git bugreport --suffix duplicate |
| 58 | ' |
| 59 | |
| 60 | test_expect_success '--output-directory puts the report in the provided dir' ' |
| 61 | test_when_finished rm -fr foo/ && |
| 62 | git bugreport -o foo/ && |
| 63 | test_path_is_file foo/git-bugreport-* |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'incorrect arguments abort with usage' ' |
| 67 | test_must_fail git bugreport --false 2>output && |
| 68 | test_grep usage output && |
| 69 | test_path_is_missing git-bugreport-* |
| 70 | ' |
| 71 | |
| 72 | test_expect_success 'incorrect positional arguments abort with usage and hint' ' |
| 73 | test_must_fail git bugreport false 2>output && |
| 74 | test_grep usage output && |
| 75 | test_grep false output && |
| 76 | test_path_is_missing git-bugreport-* |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'runs outside of a git dir' ' |
| 80 | test_when_finished rm non-repo/git-bugreport-* && |
| 81 | nongit git bugreport |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'can create leading directories outside of a git dir' ' |
| 85 | test_when_finished rm -fr foo/bar/baz && |
| 86 | nongit git bugreport -o foo/bar/baz |
| 87 | ' |
| 88 | |
| 89 | test_expect_success 'indicates populated hooks' ' |
| 90 | test_when_finished rm git-bugreport-hooks.txt && |
| 91 | |
| 92 | test_hook applypatch-msg <<-\EOF && |
| 93 | true |
| 94 | EOF |
| 95 | test_hook unknown-hook <<-\EOF && |
| 96 | true |
| 97 | EOF |
| 98 | git bugreport -s hooks && |
| 99 | |
| 100 | sort >expect <<-\EOF && |
| 101 | [Enabled Hooks] |
| 102 | applypatch-msg |
| 103 | EOF |
| 104 | |
| 105 | sed -ne "/^\[Enabled Hooks\]$/,/^$/p" <git-bugreport-hooks.txt >actual && |
| 106 | test_cmp expect actual |
| 107 | ' |
| 108 | |
| 109 | test_expect_success UNZIP '--diagnose creates diagnostics zip archive' ' |
| 110 | test_when_finished rm -rf report && |
| 111 | |
| 112 | git bugreport --diagnose -o report -s test >out && |
| 113 | |
| 114 | zip_path=report/git-diagnostics-test.zip && |
| 115 | grep "Available space" out && |
| 116 | test_path_is_file "$zip_path" && |
| 117 | |
| 118 | # Check zipped archive content |
| 119 | "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out && |
| 120 | test_file_not_empty out && |
| 121 | |
| 122 | "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && |
| 123 | grep ".git/objects" out && |
| 124 | |
| 125 | "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out && |
| 126 | grep "^Total: [0-9][0-9]*" out && |
| 127 | |
| 128 | # Should not include .git directory contents by default |
| 129 | ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/" |
| 130 | ' |
| 131 | |
| 132 | test_expect_success UNZIP '--diagnose=stats excludes .git dir contents' ' |
| 133 | test_when_finished rm -rf report && |
| 134 | |
| 135 | git bugreport --diagnose=stats -o report -s test >out && |
| 136 | |
| 137 | # Includes pack quantity/size info |
| 138 | "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out && |
| 139 | grep ".git/objects" out && |
| 140 | |
| 141 | # Does not include .git directory contents |
| 142 | ! "$GIT_UNZIP" -l "$zip_path" | grep ".git/" |
| 143 | ' |
| 144 | |
| 145 | test_expect_success UNZIP '--diagnose=all includes .git dir contents' ' |
| 146 | test_when_finished rm -rf report && |
| 147 | |
| 148 | git bugreport --diagnose=all -o report -s test >out && |
| 149 | |
| 150 | # Includes .git directory contents |
| 151 | "$GIT_UNZIP" -l "$zip_path" | grep ".git/" && |
| 152 | |
| 153 | "$GIT_UNZIP" -p "$zip_path" .git/HEAD >out && |
| 154 | test_file_not_empty out |
| 155 | ' |
| 156 | |
| 157 | test_done |