Parcourir la source

reads only the first word from file

pull/150/merge
Yamashita Yuu il y a 10 ans
Parent
révision
34065dddbb
2 fichiers modifiés avec 5 ajouts et 7 suppressions
  1. +2
    -4
      libexec/pyenv-version-file-read
  2. +3
    -3
      test/version-file-read.bats

+ 2
- 4
libexec/pyenv-version-file-read Voir le fichier

@ -9,14 +9,12 @@ 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") )
words=( $(cut -b 1-1024 "$VERSION_FILE" | awk '{ print($1) }') )
versions=("${words[@]}")
if [ -n "$versions" ]; then
OLDIFS="$IFS"
IFS=:
IFS=":"
echo "${versions[*]}"
IFS="$OLDIFS"
exit
fi
fi

+ 3
- 3
test/version-file-read.bats Voir le fichier

@ -38,16 +38,16 @@ setup() {
@test "reads only the first word from file" {
cat > my-version <<<"3.3.5 2.7.6 hi"
run pyenv-version-file-read my-version
assert_success "3.3.5:2.7.6:hi"
assert_success "3.3.5"
}
@test "loads only the first line in file" {
@test "loads *not* only the first line in file" {
cat > my-version <<IN
2.7.6 one
3.3.5 two
IN
run pyenv-version-file-read my-version
assert_success "2.7.6:one:3.3.5:two"
assert_success "2.7.6:3.3.5"
}
@test "ignores leading blank lines" {

Chargement…
Annuler
Enregistrer