From 10ea42dc75179cc6111581eb0b50df33d76798c3 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 29 Mar 2015 14:02:31 -0700 Subject: [PATCH 1/4] whitespace fixes in base.plugin.bash --- plugins/available/base.plugin.bash | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 10f5a2bf..8c8a2c50 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -25,7 +25,6 @@ function myip () echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" } - function pickfrom () { about 'picks random line from file' @@ -92,7 +91,6 @@ function lsgrep () ls | grep "$*" } - function pman () { about 'view man documentation in Preview' @@ -102,7 +100,6 @@ function pman () man -t "${1}" | open -f -a $PREVIEW } - function pcurl () { about 'download file and Preview it' @@ -125,16 +122,16 @@ function quiet () { about 'what *does* this do?' group 'base' - $* &> /dev/null & + $* &> /dev/null & } function banish-cookies () { about 'redirect .adobe and .macromedia files to /dev/null' group 'base' - rm -r ~/.macromedia ~/.adobe - ln -s /dev/null ~/.adobe - ln -s /dev/null ~/.macromedia + rm -r ~/.macromedia ~/.adobe + ln -s /dev/null ~/.adobe + ln -s /dev/null ~/.macromedia } function usage () @@ -184,7 +181,6 @@ function command_exists () mkiso () { - about 'creates iso from current dir in the parent dir (unless defined)' param '1: ISO name' param '2: dest/path' From 839cf4429a69a56fd4cc5aaac069d20915e76597 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 29 Mar 2015 16:31:05 -0700 Subject: [PATCH 2/4] start with tests for base.plugin --- test/plugins/base.plugin.bats | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 test/plugins/base.plugin.bats diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats new file mode 100755 index 00000000..fe936e60 --- /dev/null +++ b/test/plugins/base.plugin.bats @@ -0,0 +1,19 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure +load ../../plugins/available/base.plugin + +@test 'plugins base: ips()' { + declare -r localhost='127.0.0.1' + run ips + assert_success + assert_line $localhost +} + +@test 'plugins base: myip()' { + run myip + assert_success + declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?') + [[ $mask_ip == 'Your public IP is: ?.?.?.?' ]] +} From cbcdd66863756c48df97b446efed69a250a1938b Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 29 Mar 2015 17:21:28 -0700 Subject: [PATCH 3/4] test base.plugin#pickfrom --- test/plugins/base.plugin.bats | 9 +++++++++ test/test_helper.bash | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index fe936e60..41c9ea5c 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -17,3 +17,12 @@ load ../../plugins/available/base.plugin 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? ]] +} diff --git a/test/test_helper.bash b/test/test_helper.bash index da34c438..faf2b081 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,4 +1,3 @@ -unset BASH_IT unset BASH_IT_THEME unset GIT_HOSTING unset NGINX_PATH @@ -6,7 +5,18 @@ unset IRC_CLIENT unset TODO 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 HOME="${BASH_IT_TEST_DIR}/home" + export BASH_IT=$BASH_IT_TEST_DIR + + PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin + PATH="${BASH_IT_TEST_DIR}/bin:$PATH" + export PATH +fi teardown() { rm -rf "$BASH_IT_TEST_DIR" From b3334bc9e586ae1bebb9f458f7f87ba635d03108 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sun, 29 Mar 2015 17:45:54 -0700 Subject: [PATCH 4/4] adjust env vars in test_helper to make CI pass --- test/plugins/base.plugin.bats | 8 ++++++++ test/test_helper.bash | 5 ----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 41c9ea5c..9bc9f0e6 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -5,6 +5,10 @@ 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 @@ -12,6 +16,10 @@ load ../../plugins/available/base.plugin } @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]' '?') diff --git a/test/test_helper.bash b/test/test_helper.bash index faf2b081..850b6161 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -10,12 +10,7 @@ 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 HOME="${BASH_IT_TEST_DIR}/home" export BASH_IT=$BASH_IT_TEST_DIR - - PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - PATH="${BASH_IT_TEST_DIR}/bin:$PATH" - export PATH fi teardown() {