From f9ffb73a7ed4ea0b6d4f99dbd5b43e294d1a5f2e Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Mon, 10 Aug 2026 21:19:47 +0300 Subject: [PATCH] test_helper: support here-document to `assert_success/failure`; + assert_output_glob --- test/rehash.bats | 3 ++- test/test_helper.bash | 53 +++++++++++++++++++++++++++++-------- test/version-file-read.bats | 6 ++--- test/versions.bats | 10 +++---- test/which.bats | 4 +-- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/test/rehash.bats b/test/rehash.bats index c1476e6c..342d7e0c 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -23,7 +23,8 @@ load test_helper touch "${PYENV_ROOT}/shims/.pyenv-shim" #avoid failure due to a localized error message LANG=C run pyenv-rehash - assert_failure <&2; return 1;; + esac + then + { diff -u --label expected --label actual <(echo "$2") <(echo "$3") | cat -te } | flunk fi } -assert_output() { - local expected - if [ $# -eq 0 ]; then expected="$(cat -)" - else expected="$1" +_assert_output_if_provided() { + if [ "$#" -gt 0 ]; then + assert_output "$1" + elif [ ! -t 0 ]; then + local expected=$(cat -) + if [[ -n $expected ]]; then + assert_output "$expected" + fi fi - assert_equal "$expected" "$output" +} + +assert_output() { + _assert_output_as text "$@" +} + +assert_output_glob() { + _assert_output_as glob "$@" +} + +_assert_output_as() { + local kind="${1:?}"; shift + local expected + if [ $# -eq 0 ] + then expected="$(cat -)" + else expected="$1" + fi + _assert_equal_as "$kind" "$expected" "$output" } assert_line() { diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 6563eb6f..d20dfd2c 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -90,13 +90,13 @@ IN } @test "skips glob path traversal" { - cat > my-version < my-version <<'IN' ../* 3.9.3 IN run pyenv-version-file-read my-version - assert_success <