interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / test-lib-github-workflow-markup.sh

83 lines · 2831 bytes Raw Blame History
1# Library of functions to mark up test scripts' output suitable for
2# pretty-printing it in GitHub workflows.
3#
4# Copyright (c) 2022 Johannes Schindelin
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see https://www.gnu.org/licenses/ .
18#
19# The idea is for `test-lib.sh` to source this file when run in GitHub
20# workflows; these functions will then override (empty) functions
21# that are called at the appropriate times during the test runs.
22
23test_skip_test_preamble=t
24
25start_test_output () {
26 test -n "$GIT_TEST_TEE_OUTPUT_FILE" ||
27 die "--github-workflow-markup requires --verbose-log"
28 github_markup_output="${GIT_TEST_TEE_OUTPUT_FILE%.out}.markup"
29 >$github_markup_output
30 GIT_TEST_TEE_OFFSET=0
31 github_markup_script_name=${0##*/}
32}
33
34find_test_case_line_ () {
35 # A description can contain characters like [ or * that would
36 # corrupt a regex search, so match it literally and take the first
37 # hit. The -- keeps a description starting with "-" from being read
38 # as an option.
39 grep -n -F -- "$1" "$TEST_DIRECTORY/$github_markup_script_name" |
40 head -n 1 | cut -d: -f1
41}
42
43# No need to override start_test_case_output
44
45finalize_test_case_output () {
46 test_case_result=$1
47 shift
48
49 case "$test_case_result" in
50 ok|broken)
51 # Exit without printing the "ok" or "broken" tests
52 return
53 ;;
54 esac
55
56 test_case_line=$(find_test_case_line_ "$1")
57 test_case_where="$github_markup_script_name${test_case_line:+:$test_case_line}"
58
59 case "$test_case_result" in
60 failure)
61 echo >>$github_markup_output "::error::failed: $this_test.$test_count $1 ($test_case_where)"
62 ;;
63 fixed)
64 echo >>$github_markup_output "::notice::fixed: $this_test.$test_count $1 ($test_case_where)"
65 ;;
66 esac
67
68 echo >>$github_markup_output "::group::$test_case_result: $this_test.$test_count $*"
69 test-tool >>$github_markup_output path-utils skip-n-bytes \
70 "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
71 echo >>$github_markup_output "::endgroup::"
72}
73
74finalize_test_leak_output () {
75 echo >>$github_markup_output \
76 "::error::memory leak logged in $this_test ($github_markup_script_name)"
77
78 echo >>$github_markup_output "::group::leak: $this_test.$test_count"
79 cat "$TEST_RESULTS_SAN_FILE".* >>$github_markup_output
80 echo >>$github_markup_output "::endgroup::"
81}
82
83# No need to override finalize_test_output