Files
git/t/test-lib-github-workflow-markup.sh
Harald Nordgren 470c6e9fe2 ci: point test failures and fixed known breakages at their file and line
A failing test gets an annotation in the Annotations list on its job's
summary page, naming it, for example:

    failed: t1060.17 partial clone of corrupted repository

with no indication of where that test lives.

Find the line a test is defined on by searching its script for the
test's own description as a fixed string, using the first match, and
add the file and line to the annotation's own message text:

    failed: t1060.17 partial clone of corrupted repository (t1060-object-corruption.sh:141)

Fall back to naming just the script, with no line, when the
description is not found verbatim, which happens when a test builds
its description at runtime instead of writing it out literally.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-10-06 09:20:39 -07:00

84 lines
2.8 KiB
Bash

# Library of functions to mark up test scripts' output suitable for
# pretty-printing it in GitHub workflows.
#
# Copyright (c) 2022 Johannes Schindelin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses/ .
#
# The idea is for `test-lib.sh` to source this file when run in GitHub
# workflows; these functions will then override (empty) functions
# that are called at the appropriate times during the test runs.
test_skip_test_preamble=t
start_test_output () {
test -n "$GIT_TEST_TEE_OUTPUT_FILE" ||
die "--github-workflow-markup requires --verbose-log"
github_markup_output="${GIT_TEST_TEE_OUTPUT_FILE%.out}.markup"
>$github_markup_output
GIT_TEST_TEE_OFFSET=0
github_markup_script_name=${0##*/}
}
find_test_case_line_ () {
# A description can contain characters like [ or * that would
# corrupt a regex search, so match it literally and take the first
# hit. The -- keeps a description starting with "-" from being read
# as an option.
grep -n -F -- "$1" "$TEST_DIRECTORY/$github_markup_script_name" |
head -n 1 | cut -d: -f1
}
# No need to override start_test_case_output
finalize_test_case_output () {
test_case_result=$1
shift
case "$test_case_result" in
ok|broken)
# Exit without printing the "ok" or "broken" tests
return
;;
esac
test_case_line=$(find_test_case_line_ "$1")
test_case_where="$github_markup_script_name${test_case_line:+:$test_case_line}"
case "$test_case_result" in
failure)
echo >>$github_markup_output "::error::failed: $this_test.$test_count $1 ($test_case_where)"
;;
fixed)
echo >>$github_markup_output "::notice::fixed: $this_test.$test_count $1 ($test_case_where)"
;;
esac
echo >>$github_markup_output "::group::$test_case_result: $this_test.$test_count $*"
test-tool >>$github_markup_output path-utils skip-n-bytes \
"$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
echo >>$github_markup_output "::endgroup::"
}
finalize_test_leak_output () {
echo >>$github_markup_output \
"::error::memory leak logged in $this_test ($github_markup_script_name)"
echo >>$github_markup_output "::group::leak: $this_test.$test_count"
cat "$TEST_RESULTS_SAN_FILE".* >>$github_markup_output
echo >>$github_markup_output "::endgroup::"
}
# No need to override finalize_test_output