[PATCH] t0091-bugreport.sh: actually verify some content of report
- From
- Martin Ågren <martin.agren@gmail.com>
- Date
- Apr 11, 2021, 14:33 UTC
- Message-ID
- <20210411143354.25134-1-martin.agren@gmail.com>
- In-Reply-To
- <20210409212724.GE2947267@szeder.dev>
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.31.1.164.g984c2561cd: No such file
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 grep for some contents that we expect to find in a bug report. We won't verify that they appear in the right order, but at least we end up verifying the contents more than before this commit.
Reported-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> --- > It does scare me..
Maybe something like this?
t/t0091-bugreport.sh | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index 526304ff95..9111c4c26f 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -4,29 +4,13 @@ test_description='git bugreport' . ./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_expect_success 'creates a report with content' ' test_when_finished rm git-bugreport-check-headers.txt && git bugreport -s check-headers && - check_all_headers_populated <git-bugreport-check-headers.txt + grep "^Please answer " git-bugreport-check-headers.txt && + grep "^\[System Info\]$" git-bugreport-check-headers.txt && + grep "^git version:$" git-bugreport-check-headers.txt && + grep "^\[Enabled Hooks\]$" git-bugreport-check-headers.txt ' test_expect_success 'dies if file with same name as report already exists' '
-- 2.31.1.163.ga65ce7f831