From b584d4304d9b4230be464ff84f6dcd434d02290d Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 16:13:47 -0700 Subject: [PATCH 1/7] [start with tests] minor space fix in the codebase --- plugins/available/dirs.plugin.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index 283b51b0..2946d772 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -55,7 +55,6 @@ function dirs-help() { echo "9 : Chance to stack location 9." } - # ADD BOOKMARKing functionality # usage: From ce4562decccae4c4747c5a8708e190c43fc24611 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 16:31:58 -0700 Subject: [PATCH 2/7] rename lib/composure.{sh,bash} for consistency and to allow load helper work in tests --- lib/{composure.sh => composure.bash} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{composure.sh => composure.bash} (100%) diff --git a/lib/composure.sh b/lib/composure.bash similarity index 100% rename from lib/composure.sh rename to lib/composure.bash From a13719f28fd87de199ec886ac08c07b0089bacff Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 16:35:11 -0700 Subject: [PATCH 3/7] test lib#composure_keywords --- test/lib/composure.bats | 9 +++++ test/test_helper.bash | 87 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100755 test/lib/composure.bats create mode 100644 test/test_helper.bash diff --git a/test/lib/composure.bats b/test/lib/composure.bats new file mode 100755 index 00000000..f2a42191 --- /dev/null +++ b/test/lib/composure.bats @@ -0,0 +1,9 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure + +@test "composure_keywords()" { + run composure_keywords + assert_output "about author example group param version" +} diff --git a/test/test_helper.bash b/test/test_helper.bash new file mode 100644 index 00000000..da34c438 --- /dev/null +++ b/test/test_helper.bash @@ -0,0 +1,87 @@ +unset BASH_IT +unset BASH_IT_THEME +unset GIT_HOSTING +unset NGINX_PATH +unset IRC_CLIENT +unset TODO +unset SCM_CHECK + +BASH_IT_TEST_DIR="${BATS_TMPDIR}/bash_it" + +teardown() { + rm -rf "$BASH_IT_TEST_DIR" +} + +assert() { + if ! "$@"; then + flunk "failed: $@" + fi +} + +flunk() { + { if [ "$#" -eq 0 ]; then cat - + else echo "$@" + fi + } | sed "s:${BASH_IT_TEST_DIR}:TEST_DIR:g" >&2 + return 1 +} + +assert_success() { + if [ "$status" -ne 0 ]; then + flunk "command failed with exit status $status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_failure() { + if [ "$status" -eq 0 ]; then + flunk "expected failed exit status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_equal() { + if [ "$1" != "$2" ]; then + { echo "expected: $1" + echo "actual: $2" + } | flunk + fi +} + +assert_output() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + assert_equal "$expected" "$output" +} + +assert_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + assert_equal "$2" "${lines[$1]}" + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + flunk "expected line \`$1'" + fi +} + +refute_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + local num_lines="${#lines[@]}" + if [ "$1" -lt "$num_lines" ]; then + flunk "output has $num_lines lines" + fi + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then + flunk "expected to not find line \`$line'" + fi + done + fi +} From 28e5c99816b595502e594f7b2a7a9e92f018fcdf Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 18:21:52 -0700 Subject: [PATCH 4/7] added test example for plugin and lib --- test/lib/composure.bats | 2 +- test/plugins/ruby.plugin.bats | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 test/plugins/ruby.plugin.bats diff --git a/test/lib/composure.bats b/test/lib/composure.bats index f2a42191..af4bc8cf 100755 --- a/test/lib/composure.bats +++ b/test/lib/composure.bats @@ -3,7 +3,7 @@ load ../test_helper load ../../lib/composure -@test "composure_keywords()" { +@test "lib composure: composure_keywords()" { run composure_keywords assert_output "about author example group param version" } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats new file mode 100755 index 00000000..2328e6e8 --- /dev/null +++ b/test/plugins/ruby.plugin.bats @@ -0,0 +1,16 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure +load ../../plugins/available/ruby.plugin + +@test "plugins ruby: remove_gem is defined" { + run type remove_gem + assert_line 1 "remove_gem () " +} + + +@test "plugins ruby: PATH includes ~/.gem/ruby/bin" { + last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1); + [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] +} From 3c0db284acdf6a7445b0b82727ae95feeb4e8fc5 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 18:27:11 -0700 Subject: [PATCH 5/7] added test/README with small guides about testing framework --- test/README.md | 4 ++++ test/plugins/ruby.plugin.bats | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test/README.md diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..281b1b6f --- /dev/null +++ b/test/README.md @@ -0,0 +1,4 @@ +## Testing with [Bats](https://github.com/sstephenson/bats#installing-bats-from-source) +``` +bats test/{lib,plugins} +``` diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 2328e6e8..d3bbd70d 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -9,7 +9,6 @@ load ../../plugins/available/ruby.plugin assert_line 1 "remove_gem () " } - @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1); [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] From 62d705ab50a3092fafffb67e219330e258b1957c Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 18:50:05 -0700 Subject: [PATCH 6/7] added travis.ci support --- .travis.yml | 4 ++++ test/run | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 .travis.yml create mode 100755 test/run diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a1745beb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +sudo: false +install: git clone --depth 1 https://github.com/sstephenson/bats.git +script: PATH="./bats/bin:$PATH" test/run +language: c diff --git a/test/run b/test/run new file mode 100755 index 00000000..1fb11518 --- /dev/null +++ b/test/run @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +exec bats ${CI:+--tap} test/{lib,plugins} From c079458fd523500017bd9b0c54cb5c0fdc11ce0e Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 28 Mar 2015 18:57:51 -0700 Subject: [PATCH 7/7] added travis build status to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d903facd..5d3e9e10 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bash it -[![Join the chat at https://gitter.im/Bash-it/bash-it](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/ipoval/bash-it.svg?branch=master)](https://travis-ci.org/ipoval/bash-it) [![Join the chat at https://gitter.im/Bash-it/bash-it](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) **Bash it** is a collection of community bash commands and scripts. (And a shameless ripoff of [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh). :)