Merge pull request #440 from ipoval/master
start with tests using bats framework, put travisci onpull/441/head
commit
6759761201
|
|
@ -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
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Bash it
|
||||
|
||||
[](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/ipoval/bash-it) [](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). :)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ function dirs-help() {
|
|||
echo "9 : Chance to stack location 9."
|
||||
}
|
||||
|
||||
|
||||
# ADD BOOKMARKing functionality
|
||||
# usage:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
## Testing with [Bats](https://github.com/sstephenson/bats#installing-bats-from-source)
|
||||
```
|
||||
bats test/{lib,plugins}
|
||||
```
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
|
||||
@test "lib composure: composure_keywords()" {
|
||||
run composure_keywords
|
||||
assert_output "about author example group param version"
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#!/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 ]]
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
exec bats ${CI:+--tap} test/{lib,plugins}
|
||||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue