Skip to content

Commit

Permalink
Fix tests; allow output checking with wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
native-api committed Nov 24, 2024
1 parent 4de2bf0 commit f4e7425
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
8 changes: 7 additions & 1 deletion bin/pyenv-virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,13 @@ STATUS=0
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
if [ -n "${USE_CONDA}" ]; then
pyenv-exec conda create $QUIET $VERBOSE --name "${VIRTUALENV_PATH##*/}" --yes "${VIRTUALENV_OPTIONS[@]}" --file <(pyenv-exec conda list python --full-name --export) || STATUS="$?"
if [ -z "$VIRTUALENV_PYTHON" ]; then
#process substitution doesn't seem to work unless it's directly inserted to the command line
#if we add it to VIRTUALENV_OPTIONS instead, "broken pipe" happens
pyenv-exec conda create $QUIET $VERBOSE --name "${VIRTUALENV_PATH##*/}" --yes "${VIRTUALENV_OPTIONS[@]}" --file <(pyenv-exec conda list python --full-name --export) || STATUS="$?"
else
pyenv-exec conda create $QUIET $VERBOSE --name "${VIRTUALENV_PATH##*/}" --yes "${VIRTUALENV_OPTIONS[@]}" || STATUS="$?"
fi
else
if [ -n "${USE_M_VENV}" ]; then
pyenv-exec "${M_VENV_PYTHON_BIN:-python}" -m venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
Expand Down
8 changes: 4 additions & 4 deletions test/conda.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ unstub_pyenv() {
run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes python
assert_output_wildcards <<OUT
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes --file /dev/fd/*
rehashed
OUT

Expand All @@ -56,7 +56,7 @@ OUT

assert_success
assert_output <<OUT
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes python=3.5 python
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes python=3.5
rehashed
OUT

Expand All @@ -79,7 +79,7 @@ OUT

assert_success
assert_output <<OUT
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes python=3.5 python
PYENV_VERSION=miniconda3-3.16.0 conda create --name venv --yes python=3.5
rehashed
OUT

Expand Down
2 changes: 1 addition & 1 deletion test/deactivate.bats
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bats
#!/usr/bin/env bats

load test_helper

Expand Down
18 changes: 18 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ assert_equal() {
fi
}

assert_equal_wildcards() {
if [[ $1 != $2 ]]; then
{ echo "expected:"
echo "$2"
echo "actual:"
echo "$1"
} | flunk
fi
}

assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
Expand All @@ -91,6 +101,14 @@ assert_output() {
assert_equal "$expected" "$output"
}

assert_output_wildcards() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal_wildcards "$output" "$expected"
}

assert_output_contains() {
local expected="$1"
echo "$output" | grep -F "$expected" >/dev/null || {
Expand Down

0 comments on commit f4e7425

Please sign in to comment.