Merge pull request #442 from ipoval/test_some_functions_in_base_plugin

start with tests for base.plugin.bash
pull/446/head
Nils Winkler 2015-03-30 13:24:19 +02:00
commit 25ec6ee6f3
3 changed files with 47 additions and 10 deletions

View File

@ -25,7 +25,6 @@ function myip ()
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
} }
function pickfrom () function pickfrom ()
{ {
about 'picks random line from file' about 'picks random line from file'
@ -92,7 +91,6 @@ function lsgrep ()
ls | grep "$*" ls | grep "$*"
} }
function pman () function pman ()
{ {
about 'view man documentation in Preview' about 'view man documentation in Preview'
@ -102,7 +100,6 @@ function pman ()
man -t "${1}" | open -f -a $PREVIEW man -t "${1}" | open -f -a $PREVIEW
} }
function pcurl () function pcurl ()
{ {
about 'download file and Preview it' about 'download file and Preview it'
@ -184,7 +181,6 @@ function command_exists ()
mkiso () mkiso ()
{ {
about 'creates iso from current dir in the parent dir (unless defined)' about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name' param '1: ISO name'
param '2: dest/path' param '2: dest/path'

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../plugins/available/base.plugin
@test 'plugins base: ips()' {
if [[ $CI ]]; then
skip 'ifconfig probably requires sudo on TravisCI'
fi
declare -r localhost='127.0.0.1'
run ips
assert_success
assert_line $localhost
}
@test 'plugins base: myip()' {
if [[ ! $CI ]]; then
skip 'myip is slow - run only on CI'
fi
run myip
assert_success
declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?')
[[ $mask_ip == 'Your public IP is: ?.?.?.?' ]]
}
@test 'plugins base: pickfrom()' {
mkdir -p $BASH_IT_ROOT
stub_file="${BASH_IT_ROOT}/stub_file"
printf "l1\nl2\nl3" > $stub_file
run pickfrom $stub_file
assert_success
[[ $output == l? ]]
}

View File

@ -1,4 +1,3 @@
unset BASH_IT
unset BASH_IT_THEME unset BASH_IT_THEME
unset GIT_HOSTING unset GIT_HOSTING
unset NGINX_PATH unset NGINX_PATH
@ -6,7 +5,13 @@ unset IRC_CLIENT
unset TODO unset TODO
unset SCM_CHECK unset SCM_CHECK
BASH_IT_TEST_DIR="${BATS_TMPDIR}/bash_it" BASH_IT_TEST_DIR="${BATS_TMPDIR}/.bash_it"
# guard against executing this block twice due to bats internals
if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then
export BASH_IT_ROOT="${BASH_IT_TEST_DIR}/root"
export BASH_IT=$BASH_IT_TEST_DIR
fi
teardown() { teardown() {
rm -rf "$BASH_IT_TEST_DIR" rm -rf "$BASH_IT_TEST_DIR"