mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
ignores carriage returns
This commit is contained in:
parent
d90cb0ec85
commit
ea9214bb2e
2 changed files with 19 additions and 13 deletions
|
@ -8,14 +8,14 @@ VERSION_FILE="$1"
|
|||
if [ -e "$VERSION_FILE" ]; then
|
||||
# Read the first non-whitespace word from the specified version file.
|
||||
# Be careful not to load it whole in case there's something crazy in it.
|
||||
IFS="${IFS}"$'\r'
|
||||
words=( $(cut -b 1-1024 "$VERSION_FILE") )
|
||||
versions=("${words[@]}")
|
||||
|
||||
if [ -n "$versions" ]; then
|
||||
OLDIFS="$IFS"
|
||||
{ IFS=:
|
||||
echo "${versions[*]}"
|
||||
}
|
||||
IFS=:
|
||||
echo "${versions[*]}"
|
||||
IFS="$OLDIFS"
|
||||
exit
|
||||
fi
|
||||
|
|
|
@ -24,39 +24,39 @@ setup() {
|
|||
}
|
||||
|
||||
@test "reads simple version file" {
|
||||
cat > my-version <<<"3.3.3"
|
||||
cat > my-version <<<"3.3.5"
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "3.3.3"
|
||||
assert_success "3.3.5"
|
||||
}
|
||||
|
||||
@test "ignores leading spaces" {
|
||||
cat > my-version <<<" 3.3.3"
|
||||
cat > my-version <<<" 3.3.5"
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "3.3.3"
|
||||
assert_success "3.3.5"
|
||||
}
|
||||
|
||||
@test "reads only the first word from file" {
|
||||
cat > my-version <<<"3.3.3-p194@tag 2.7.6 hi"
|
||||
cat > my-version <<<"3.3.5 2.7.6 hi"
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "3.3.3-p194@tag:2.7.6:hi"
|
||||
assert_success "3.3.5:2.7.6:hi"
|
||||
}
|
||||
|
||||
@test "loads only the first line in file" {
|
||||
cat > my-version <<IN
|
||||
2.7.6 one
|
||||
3.3.3 two
|
||||
3.3.5 two
|
||||
IN
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "2.7.6:one:3.3.3:two"
|
||||
assert_success "2.7.6:one:3.3.5:two"
|
||||
}
|
||||
|
||||
@test "ignores leading blank lines" {
|
||||
cat > my-version <<IN
|
||||
|
||||
3.3.3
|
||||
3.3.5
|
||||
IN
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "3.3.3"
|
||||
assert_success "3.3.5"
|
||||
}
|
||||
|
||||
@test "handles the file with no trailing newline" {
|
||||
|
@ -64,3 +64,9 @@ IN
|
|||
run pyenv-version-file-read my-version
|
||||
assert_success "2.7.6"
|
||||
}
|
||||
|
||||
@test "ignores carriage returns" {
|
||||
cat > my-version <<< $'3.3.5\r'
|
||||
run pyenv-version-file-read my-version
|
||||
assert_success "3.3.5"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue