t0091-bugreport.sh: actually verify some content of report
A message that is not in the archive (sent off-list or not yet received): AN0heSrMCnygWUC5Sh1UA9v2JGtjcxYDKPFE0xUPddGEW29c3w@mail.gmail.com
PATCH v3 1/1 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 788a776069 ("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.)
--- t/t0091-bugreport.sh | 67 +++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 23 deletions(-)
t/t0091-bugreport.sh +44 -23
@@ -5,29 +5,50 @@ test_description='git bugreport' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh -# Headers "[System Info]" will be followed by a non-empty line if we put some -# information there; we can make sure all our headers were followed by some -# information to check if the command was successful. -HEADER_PATTERN="^\[.*\]$" - -check_all_headers_populated () { - while read -r line - do - if test "$(grep "$HEADER_PATTERN" "$line")" - then - echo "$line" - read -r nextline - if test -z "$nextline"; then - return 1; - fi - fi - done -} - -test_expect_success 'creates a report with content in the right places' ' - test_when_finished rm git-bugreport-check-headers.txt && - git bugreport -s check-headers && - check_all_headers_populated <git-bugreport-check-headers.txt +test_expect_success 'create a report' ' + git bugreport -s format && + test_file_not_empty git-bugreport-format.txt +' + +test_expect_success 'report contains wanted template (before first section)' ' + sed -ne "/^\[/q;p" git-bugreport-format.txt >actual && + cat >expect <<-\EOF && + Thank you for filling out a Git bug report! + Please answer the following questions to help us understand your issue. + + What did you do before the bug happened? (Steps to reproduce your issue) + + What did you expect to happen? (Expected behavior) + + What happened instead? (Actual behavior) + + What'\''s different between what you expected and what actually happened? + + Anything else you want to add: + + Please review the rest of the bug report below. + You can delete any lines you don'\''t wish to share. + + + EOF + test_cmp expect actual +' + +test_expect_success 'sanity check "System Info" section' ' + test_when_finished rm -f git-bugreport-format.txt && + + sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system && + + # The beginning should match "git version --build-info" verbatim, + # but rather than checking bit-for-bit equality, just test some basics. + grep "git version [0-9]." system && + grep "shell-path: ." system && + + # After the version, there should be some more info. + # This is bound to differ from environment to environment, + # so we just do some rather high-level checks. + grep "uname: ." system && + grep "compiler info: ." system ' test_expect_success 'dies if file with same name as report already exists' '
Signature · 1 line
2.41.0.404.g5b50783d6b
Quoted 2 lines · Martin Ågren
In the first test in this script, 'creates a report with content in the
This v3 has the wrong In-Reply-To. I've resent to the original thread,
https://lore.kernel.org/git/[email protected]/
Sorry about the noise,
Martin
t/t0091-bugreport.sh test_description='git bugreport' · line 11
Quoted 4 lines · Martin Ågren
t/t0091-bugreport.sh +4
-0+test_expect_success 'create a report' ' + git bugreport -s format && + test_file_not_empty git-bugreport-format.txt +'
OK.
Quoted 13 lines
t/t0091-bugreport.sh +13
-0+test_expect_success 'report contains wanted template (before first section)' ' + sed -ne "/^\[/q;p" git-bugreport-format.txt >actual && + cat >expect <<-\EOF && + Thank you for filling out a Git bug report! + Please answer the following questions to help us understand your issue. + + What did you do before the bug happened? (Steps to reproduce your issue) + + What did you expect to happen? (Expected behavior) + + What happened instead? (Actual behavior) + + What'\''s different between what you expected and what actually happened?
t/t0091-bugreport.sh test_description='git bugreport' · line 35
Quoted 10 lines
t/t0091-bugreport.sh +10
-0+ + Anything else you want to add: + + Please review the rest of the bug report below. + You can delete any lines you don'\''t wish to share. + + + EOF + test_cmp expect actual +'
I am not sure about the value of the bit-for-bit test here, but OK. It is not like we will be changing this piece of text every week.
t/t0091-bugreport.sh test_description='git bugreport' · line 47
Quoted 11 lines
t/t0091-bugreport.sh +11
-0+test_expect_success 'sanity check "System Info" section' ' + test_when_finished rm -f git-bugreport-format.txt && + + sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system && + + # The beginning should match "git version --build-info" verbatim, + # but rather than checking bit-for-bit equality, just test some basics. + grep "git version [0-9]." system && + grep "shell-path: ." system && + + # After the version, there should be some more info.
Do you want to assert the "after" part? "grep" alone does not do anything of that sort.
t/t0091-bugreport.sh test_description='git bugreport' · line 52
Quoted 5 lines
t/t0091-bugreport.sh +4
-0+ # This is bound to differ from environment to environment, + # so we just do some rather high-level checks. + grep "uname: ." system && + grep "compiler info: ." system '
Don't we at least want to anchor all these patterns with "^" or something?
Alternatively, since we do not expect the values of the fields are useful at all, perhaps doing something like this
sed -n -e '/^\[System Info\]/,/\[Enabled Hooks]/s/^\([^:]*):.*/\1/p' >names
to ensure that we have the fields we expect in the output makes more sense?
I notice that "git version:" does not have its value on its line. Isn't it a bug we would rather fix before writing this "sanity check" test, I have to wonder.
Thanks.
Quoted 3 lines · Junio C Hamano
I notice that "git version:" does not have its value on its line. Isn't it a bug we would rather fix before writing this "sanity check" test, I have to wonder.
builtin/bugreport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/bugreport.c +1 -1
@@ -19,7 +19,7 @@ static void get_system_info(struct strbuf *sys_info)char *shell =NULL ;/* get git version from native cmd */ -strbuf_addstr (sys_info,_ ("git version:\n" )); +strbuf_addstr (sys_info,_ ("git version: " ));get_version_info (sys_info,1 );/* system call for other version info */
Quoted 17 lines · Junio C Hamano
t/t0091-bugreport.sh test_description='git bugreport' · line 47
Quoted 11 lines · Martin Ågren
t/t0091-bugreport.sh +11
-0+test_expect_success 'sanity check "System Info" section' ' + test_when_finished rm -f git-bugreport-format.txt && + + sed -ne "/^\[System Info\]$/,/^$/p" <git-bugreport-format.txt >system && + + # The beginning should match "git version --build-info" verbatim, + # but rather than checking bit-for-bit equality, just test some basics. + grep "git version [0-9]." system && + grep "shell-path: ." system && + + # After the version, there should be some more info.Do you want to assert the "after" part? "grep" alone does not do anything of that sort.
Right, I remember thinking this 'after' could be useful to a human being reading along, but that the test isn't enforcing it, as you point out. If it's just misleading though, maybe we're better off either dropping the "After" or enforcing it.
Quoted 9 lines
t/t0091-bugreport.sh test_description='git bugreport' · line 52
Quoted 5 lines
t/t0091-bugreport.sh +4
-0+ # This is bound to differ from environment to environment, + # so we just do some rather high-level checks. + grep "uname: ." system && + grep "compiler info: ." system 'Don't we at least want to anchor all these patterns with "^" or something?
Quoted 6 lines
Alternatively, since we do not expect the values of the fields are useful at all, perhaps doing something like this
sed -n -e '/^\[System Info\]/,/\[Enabled Hooks]/s/^\([^:]*):.*/\1/p' >namesto ensure that we have the fields we expect in the output makes more sense?
The latter would make sense, yes. I could amend the patch to do something like that, but I see you've already merged it to next. I'll look into doing it as a patch on top during the weekend.
Quoted 3 lines
I notice that "git version:" does not have its value on its line. Isn't it a bug we would rather fix before writing this "sanity check" test, I have to wonder.
Yeah, I noticed this. In my case, there's this:
git version:
git version 2.41.0.428.gbd0ef4c9fd
cpu: x86_64
built from commit: bd0ef4c9fd591e9c2ea1310dae92fe07a51438c7
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: [...]
[...]
IMHO, "git version: git version 2.41.0.428.gbd0ef4c9fd" would look sort of weird. I tend to think "git version:" is more of a header for the first several lines. It could perhaps be something like this, after adding "--build-options" and indenting its output:
git version --build-options:
git version 2.41.0.428.gbd0ef4c9fd
cpu: x86_64
built from commit: bd0ef4c9fd591e9c2ea1310dae92fe07a51438c7
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: [...]
[...]
That's how I think of the contents. Actually changing the format would be out-of-scope for the test updates, of course. I also wonder if there are scripts out there trying to parse these reports and how they would cope with such a tweak to the format.
Martin