Better tests, more resilience and a bug fix

pull/715/head
Konstantin Gredeskoul 2016-05-12 04:04:51 -07:00
parent 81e3f1121b
commit db5061cf80
3 changed files with 38 additions and 8 deletions

View File

@ -98,7 +98,7 @@ _bash-it-search-component() {
[[ "${term:0:1}" == "-" ]] && negative_terms=(${negative_terms[@]} ${term:1}) && continue [[ "${term:0:1}" == "-" ]] && negative_terms=(${negative_terms[@]} ${term:1}) && continue
# print asterisk next to each result that is already enabled by the user # print asterisk next to each result that is already enabled by the user
local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | cut -b -30 | sed 's/ *\[ \]//g;s/ *\[x\]/*/g;' )) local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | egrep '\[( |x)\]' | cut -b -30 | sed 's/ *\[ \]//g;s/ *\[x\]/*/g;' ))
[[ "${#term_match[@]}" -gt 0 ]] && { [[ "${#term_match[@]}" -gt 0 ]] && {
matches=(${matches[@]} ${term_match[@]}) # append to the list of results matches=(${matches[@]} ${term_match[@]}) # append to the list of results
} }

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bats
load ../../lib/composure
load ../../plugins/available/base.plugin
cite _about _param _example _group _author _version
load ../../lib/helpers
## TODO: write some tests.

View File

@ -15,19 +15,39 @@ NO_COLOR=true
[[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]] [[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]]
} }
@test "helpers search all ruby et al" { @test "helpers search ruby gem bundle rake rails" {
# first disable them all, so that the output does not appear with a checkbox
# and we can compoare the result
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
# Now perform the search
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
[[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] # And verify
[[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto ruby' ]] [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \
[[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto ruby' ]] && \
[[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]] [[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]]
} }
@test "search enable and disable" { @test "search ruby gem bundle -chruby rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _bash-it-search 'ruby' 'gem' 'bundle' '-chruby' 'rake' 'rails'
[[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \
[[ "${lines[1]/✓/}" == ' plugins => ruby' ]] && \
[[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]]
}
@test "search (rails enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _enable-alias 'rails' run _enable-alias 'rails'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
[[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] [[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] && \
[[ "${lines[1]}" == ' plugins => chruby chruby-auto ruby' ]] [[ "${lines[1]}" == ' plugins => chruby chruby-auto ruby' ]] && \
[[ "${lines[2]}" == ' completions => bundler gem rake' ]] [[ "${lines[2]}" == ' completions => bundler gem rake' ]]
} }
@test "search (all enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails'
[[ "${lines[0]}" == ' aliases => ✓bundler ✓rails' ]] && \
[[ "${lines[1]}" == ' plugins => ✓ruby' ]] && \
[[ "${lines[2]}" == ' completions => ✓bundler ✓gem ✓rake' ]]
}