From e0663dbf91773585c1a7a22111a4d57a8f459fcc Mon Sep 17 00:00:00 2001 From: Adirelle Date: Sat, 11 May 2024 11:25:42 +0200 Subject: [PATCH] test: improve GA annotations (again). --- e2e/assert.sh | 6 ++--- e2e/run_test | 2 +- e2e/style.sh | 61 +++++++++++++++++++++++---------------------------- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/e2e/assert.sh b/e2e/assert.sh index db25d5362..29dd0dc7e 100755 --- a/e2e/assert.sh +++ b/e2e/assert.sh @@ -4,7 +4,7 @@ source "$TEST_ROOT/style.sh" fail() { - err "$*" + title="assertion failed" err "$*" exit 1 } @@ -85,14 +85,14 @@ assert_matches() { skip_slow_test() { if [[ -z ${TEST_ALL:-} ]]; then - warn "skipping slow tests" + title="skipped test" warn "slow tests are disabled" exit 0 fi } require_cmd() { if ! type -p "$1" >/dev/null; then - warn "skipping test: cannot find ""$1"" in PATH ($PATH)" + title="skipped test" warn "the required command '$1' was not found in the PATH ($PATH)" exit 0 fi } diff --git a/e2e/run_test b/e2e/run_test index 6457c7d01..c39906d2e 100755 --- a/e2e/run_test +++ b/e2e/run_test @@ -76,7 +76,7 @@ run_test() { remove_isolated_env STATUS_MSG=":white_check_mark:" else - err "E2E Test Failed (code: $status)" + title="E2E test failed" err "Test exited with status code $status" STATUS_MSG=":x:" fi if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then diff --git a/e2e/style.sh b/e2e/style.sh index c86ff5d2f..f0ae538ea 100644 --- a/e2e/style.sh +++ b/e2e/style.sh @@ -1,49 +1,42 @@ # shellcheck shell=bash if [[ -n ${GITHUB_ACTION:-} ]]; then - # Use special GA formatting - # Use ANSI green color for the "ok" message so groups with no errors are kept collapsed - _STYLE_OK=$'\e[92m' - _STYLE_ERR="::error${MISE_TEST_SCRIPT:+ file=${MISE_TEST_SCRIPT#"$ROOT"/}}::" - _STYLE_WARN="::warning${MISE_TEST_SCRIPT:+ file=${MISE_TEST_SCRIPT#"$ROOT"/}}::" - _STYLE_RESET=$'\e[0m' - _GROUP_START='::group::' - _GROUP_END='::endgroup::' + # Output Github action annotations + annotate() { + : "${file:=${TEST_SCRIPT:-}}" + : "${title:=}" + echo "::${type:?}${file:+ file=${file}}${title:+ title=${title}}::$*" >&2 + } + err() { type=error annotate "$*"; } + warn() { type=warning annotate "$*"; } + start_group() { echo "::group::$*" >&2; } + end_group() { echo ::endgroup:: >&2; } + + # Yet use ANSI green color for the "ok" message + ok() { echo $'\e[92m'"$*"$'\e[0m' >&2; } + elif [[ -t 2 ]]; then # Use ANSI coloring in terminal - _STYLE_OK=$'\e[92m' # green - _STYLE_ERR=$'\e[91m' # red - _STYLE_WARN=$'\e[93m' # yellow - _STYLE_RESET=$'\e[0m' # full reset - _GROUP_START=$'\e[1m>>> ' # bold - _GROUP_END= + ok() { echo $'\e[92m'"$*"$'\e[0m' >&2; } + err() { echo $'\e[91m'"$*"$'\e[0m' >&2; } + warn() { echo $'\e[93m'"$*"$'\e[0m' >&2; } + start_group() { echo $'\e[1m'">>> $*"$'\e[0m' >&2; } + end_group() { echo >&2; } + else # No styling - _STYLE_OK='SUCCESS: ' - _STYLE_ERR='ERROR: ' - _STYLE_WARN='NOTICE: ' - _STYLE_RESET= - _GROUP_START='>>> ' - _GROUP_END= + ok() { echo "SUCCESS: $*" >&2; } + err() { echo "ERROR: $*" >&2; } + warn() { echo "wARNING: $*" >&2; } + start_group() { echo ">>> $*" >&2; } + end_group() { echo >&2; } fi -ok() { - echo "${_STYLE_OK}$*${_STYLE_RESET}" >&2 -} - -err() { - echo "${_STYLE_ERR}$*${_STYLE_RESET}" >&2 -} - -warn() { - echo "${_STYLE_WARN}$*${_STYLE_RESET}" >&2 -} - as_group() { local status=0 - echo "${_GROUP_START}$1${_STYLE_RESET}" >&2 + start_group "$1" shift "$*" || status=$? - echo "${_GROUP_END}${_STYLE_RESET}" >&2 + end_group return "$status" }