From 2c36d5a9b0e688c6766686e7eacec6da273de64a Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sun, 21 Dec 2025 01:41:52 +0300 Subject: [PATCH] fix powershell tests --- libexec/pyenv-init | 2 +- test/init.bats | 12 +++++++----- test/test_helper.bash | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libexec/pyenv-init b/libexec/pyenv-init index eb0115be..937caa07 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -200,7 +200,7 @@ function print_path() { echo 'end' ;; pwsh ) - echo 'if ( $Env:PATH -match "'"${PYENV_ROOT}/shims"'" ) {' + echo 'if ( $Env:PATH -notmatch "'"${PYENV_ROOT}/shims"'" ) {' print_path_prepend_shims echo '}' ;; diff --git a/test/init.bats b/test/init.bats index 54ae9a79..85ef01ec 100755 --- a/test/init.bats +++ b/test/init.bats @@ -66,7 +66,7 @@ OUT root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" run pyenv-init - pwsh assert_success - assert_line "iex (gc ${root}/test/../libexec/../completions/pyenv.pwsh -Raw)" + assert_line "iex (gc ${root}/completions/pyenv.pwsh -Raw)" } @test "pwsh instructions" { @@ -169,8 +169,9 @@ echo "\$PATH" @test "adds shims to PATH with --no-push-path if they're not on PATH (pwsh)" { command -v pwsh >/dev/null || skip "-- pwsh not installed" - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" - run pwsh -noni -c - </dev/null || skip "-- pwsh not installed" - export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:${PYENV_ROOT}/shims:/bin:/usr/local/bin" - run pwsh -noni -c - </dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done unset xdg_var + # Workaround for Powershell. When tests are run from a terminal, + # Powershell erroneously prints ANSI escape sequences + # even if its output is redirected, breaking the comparison logic + export NO_COLOR=1 + # If test specific setup exist, run it if [[ $(type -t _setup) == function ]];then _setup @@ -67,8 +72,8 @@ assert_failure() { assert_equal() { if [ "$1" != "$2" ]; then - { echo "expected: $1" - echo "actual: $2" + { echo "expected: \`$1'" + echo "actual: \`$2'" } | flunk fi }