Skip to content

Commit 1aa92b8

Browse files
Martin Ågrengitster
authored andcommitted
t0091-bugreport.sh: actually verify some content of report
In the first test in this script, 'creates a report with content in the right places', we generate a report and pipe it into our helper `check_all_headers_populated()`. The idea of the helper is to find all lines that look like headers ("[Some Header Here]") and to check that the next line is non-empty. This is supposed to catch erroneous outputs such as the following: [A Header] something more here [Another Header] [Too Early Header] contents However, we provide the lines of the bug report as filenames to grep, meaning we mostly end up spewing errors: grep: : No such file or directory grep: [System Info]: No such file or directory grep: git version:: No such file or directory grep: git version 2.41.0.2.gfb7d80edca: No such file or directory This doesn't disturb the test, which tugs along and reports success, not really having verified the contents of the report at all. Note that after 788a776 ("bugreport: collect list of populated hooks", 2020-05-07), the bug report, which is created in our hook-less test repo, contains an empty section with the enabled hooks. Thus, even the intention of our helper is a bit misguided: there is nothing inherently wrong with having an empty section in the bug report. Let's instead split this test into three: first verify that we generate a report at all, then check that the introductory blurb looks the way it should, then verify that the "[System Info]" seems to contain the right things. (The "[Enabled Hooks]" section is tested later in the script.) Reported-by: SZEDER Gábor <[email protected]> Helped-by: Phillip Wood <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit 1aa92b8

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

t/t0091-bugreport.sh

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,50 @@ test_description='git bugreport'
55
TEST_PASSES_SANITIZE_LEAK=true
66
. ./test-lib.sh
77

8-
# Headers "[System Info]" will be followed by a non-empty line if we put some
9-
# information there; we can make sure all our headers were followed by some
10-
# information to check if the command was successful.
11-
HEADER_PATTERN="^\[.*\]$"
12-
13-
check_all_headers_populated () {
14-
while read -r line
15-
do
16-
if test "$(grep "$HEADER_PATTERN" "$line")"
17-
then
18-
echo "$line"
19-
read -r nextline
20-
if test -z "$nextline"; then
21-
return 1;
22-
fi
23-
fi
24-
done
25-
}
26-
27-
test_expect_success 'creates a report with content in the right places' '
28-
test_when_finished rm git-bugreport-check-headers.txt &&
29-
git bugreport -s check-headers &&
30-
check_all_headers_populated <git-bugreport-check-headers.txt
8+
test_expect_success 'create a report' '
9+
git bugreport -s format &&
10+
test_file_not_empty git-bugreport-format.txt
11+
'
12+
13+
test_expect_success 'report contains wanted template (before first section)' '
14+
sed -ne "/^\[/q;p" git-bugreport-format.txt >actual &&
15+
cat >expect <<-\EOF &&
16+
Thank you for filling out a Git bug report!
17+
Please answer the following questions to help us understand your issue.
18+
19+
What did you do before the bug happened? (Steps to reproduce your issue)
20+
21+
What did you expect to happen? (Expected behavior)
22+
23+
What happened instead? (Actual behavior)
24+
25+
What'\''s different between what you expected and what actually happened?
26+
27+
Anything else you want to add:
28+
29+
Please review the rest of the bug report below.
30+
You can delete any lines you don'\''t wish to share.
31+
32+
33+
EOF
34+
test_cmp expect actual
35+
'
36+
37+
test_expect_success 'sanity check "System Info" section' '
38+
test_when_finished rm -f git-bugreport-format.txt &&
39+
40+
sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system &&
41+
42+
# The beginning should match "git version --build-info" verbatim,
43+
# but rather than checking bit-for-bit equality, just test some basics.
44+
grep "git version [0-9]." system &&
45+
grep "shell-path: ." system &&
46+
47+
# After the version, there should be some more info.
48+
# This is bound to differ from environment to environment,
49+
# so we just do some rather high-level checks.
50+
grep "uname: ." system &&
51+
grep "compiler info: ." system
3152
'
3253

3354
test_expect_success 'dies if file with same name as report already exists' '

0 commit comments

Comments
 (0)