From b1481038d85e0b57ade737968300d2ce1516e609 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:07 +0200 Subject: [PATCH] Improved check for components that are already enabled --- lib/helpers.bash | 13 +++++-------- test/lib/helpers.bats | 12 ++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index eea442f6..7f12cde9 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -328,14 +328,11 @@ _enable-thing () plugin=$(basename $plugin) # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. - for f in $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin; do - if [ -e "$f" ] ; then - printf '%s\n' "$file_entity is already enabled." - return - fi - - break - done + typeset enabled_plugin=$(command ls $BASH_IT/$subdirectory/enabled/{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin,$plugin} 2>/dev/null | head -1) + if [ ! -z "$enabled_plugin" ] ; then + printf '%s\n' "$file_entity is already enabled." + return + fi mkdir -p $BASH_IT/$subdirectory/enabled diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 934cb261..c8a7d1ba 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -70,6 +70,18 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } +@test "enable the nvm plugin if it was enabled without a priority" { + __setup_plugin_tests + + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm is already enabled.' ] + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] +} + @test "enable the nvm plugin twice" { __setup_plugin_tests