Skip to content

Commit

Permalink
Moved all unit tests into test/unit/.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Sep 27, 2021
1 parent 43c84d6 commit a02854f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/pkg/*.tar.gz
/pkg/*.tar.bz2
/pkg/*.zip
/test/fixtures/root/opt/rubies
/test/fixtures/root/home/.zcompdump
/test/fixtures/ruby_versions/.ruby-version
/test/fixtures/ruby_versions/modified_version/.ruby-version
/test/unit/fixtures/root/opt/rubies
/test/unit/fixtures/root/home/.zcompdump
/test/unit/fixtures/ruby_versions/.ruby-version
/test/unit/fixtures/ruby_versions/modified_version/.ruby-version
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ check:
shellcheck share/$(NAME)/*.sh

configure_tests:
./test/configure
./test/unit/configure

test: configure_tests
SHELL=`command -v bash` ./test/runner
SHELL=`command -v zsh` ./test/runner
SHELL=`command -v bash` ./test/unit/runner
SHELL=`command -v zsh` ./test/unit/runner

tag:
git push origin master
Expand Down
4 changes: 2 additions & 2 deletions test/chruby_auto_test.sh → test/unit/chruby_auto_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
. ./share/chruby/auto.sh
. ./test/helper.sh
. ./test/unit/helper.sh

test_auto_version_dir="$test_fixtures_dir/ruby_versions"

Expand Down Expand Up @@ -161,7 +161,7 @@ function test_chruby_auto_ruby_version_containing_options()

function tearDown()
{
cd "$test_dir"
cd "$original_pwd"
rm -rf "$test_auto_version_dir"
}

Expand Down
2 changes: 1 addition & 1 deletion test/chruby_exec_test.sh → test/unit/chruby_exec_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. ./test/helper.sh
. ./test/unit/helper.sh

function test_chruby_exec_no_arguments()
{
Expand Down
12 changes: 6 additions & 6 deletions test/chruby_reset_test.sh → test/unit/chruby_reset_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
. ./test/helper.sh
. ./test/unit/helper.sh

function setUp()
{
chruby_use "$test_ruby_root" >/dev/null

export PATH="$GEM_HOME/bin:$GEM_ROOT/bin:$RUBY_ROOT/bin:$test_path"
export PATH="$GEM_HOME/bin:$GEM_ROOT/bin:$RUBY_ROOT/bin:$original_path"
}

function test_chruby_reset_hash_table()
Expand Down Expand Up @@ -33,7 +33,7 @@ function test_chruby_reset_env_variables()
assertNull "GEM_HOME was not unset" "$GEM_HOME"
assertNull "GEM_PATH was not unset" "$GEM_PATH"

assertEquals "PATH was not sanitized" "$test_path" "$PATH"
assertEquals "PATH was not sanitized" "$original_path" "$PATH"
}

function test_chruby_reset_duplicate_path()
Expand All @@ -42,7 +42,7 @@ function test_chruby_reset_duplicate_path()

chruby_reset

assertEquals "PATH was not sanitized" "$test_path" "$PATH"
assertEquals "PATH was not sanitized" "$original_path" "$PATH"
}

function test_chruby_reset_modified_gem_path()
Expand All @@ -60,11 +60,11 @@ function test_chruby_reset_no_gem_root_or_gem_home()
{
export GEM_HOME=""
export GEM_ROOT=""
export PATH="$test_path:/bin"
export PATH="$original_path:/bin"

chruby_reset

assertEquals "PATH was messed up" "$test_path:/bin" "$PATH"
assertEquals "PATH was messed up" "$original_path:/bin" "$PATH"
}

SHUNIT_PARENT=$0 . $SHUNIT2
2 changes: 1 addition & 1 deletion test/chruby_test.sh → test/unit/chruby_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. ./test/helper.sh
. ./test/unit/helper.sh

function setUp()
{
Expand Down
4 changes: 2 additions & 2 deletions test/chruby_use_test.sh → test/unit/chruby_use_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. ./test/helper.sh
. ./test/unit/helper.sh

function test_chruby_clears_hash_table()
{
Expand All @@ -25,7 +25,7 @@ function test_chruby_use_env_variables()
assertEquals "invalid GEM_ROOT" "$test_ruby_root/lib/ruby/gems/$test_ruby_api" "$GEM_ROOT"
assertEquals "invalid GEM_HOME" "$test_gem_home" "$GEM_HOME"
assertEquals "invalid GEM_PATH" "$GEM_HOME:$GEM_ROOT" "$GEM_PATH"
assertEquals "invalid PATH" "$test_gem_home/bin:$test_gem_root/bin:$test_ruby_root/bin:$__shunit_tmpDir:$test_path" "$PATH"
assertEquals "invalid PATH" "$test_gem_home/bin:$test_gem_root/bin:$test_ruby_root/bin:$__shunit_tmpDir:$original_path" "$PATH"

assertEquals "could not find ruby in $PATH" \
"$test_ruby_root/bin/ruby" \
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/configure → test/unit/configure
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [[ "\$1" == "-e" ]]; then
echo -n 2.2.5
;;
*)
echo "error: no stub for ruby expression: \$2" >&2
echo "error: no stub for ruby expression: '\$2'" >&2
exit -1
;;
esac
Expand All @@ -47,7 +47,7 @@ else
elif [[ "\$line" == *"puts \\"export GEM_ROOT=#{Gem.default_dir.inspect};\\""* ]]; then
echo "export GEM_ROOT=$test_gem_root;"
else
echo "error: no stub for ruby statement: \$line" >&2
echo "error: no stub for ruby statement: '\$line'" >&2
exit -1
fi
done
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if [ -f /etc/bashrc ]; then
fi

# User specific aliases and functions
. $PWD/test/helper.sh
. $PWD/share/chruby/chruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ setopt COMPLETE_IN_WORD

# autoload -U colors
#colors
. $PWD/test/helper.sh

. $PWD/share/chruby/chruby.sh
12 changes: 7 additions & 5 deletions test/helper.sh → test/unit/helper.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
[[ -z "$SHUNIT2" ]] && SHUNIT2=/usr/share/shunit2/shunit2
[[ -n "$ZSH_VERSION" ]] && setopt shwordsplit

test_dir="$PWD"
test_fixtures_dir="$test_dir/test/fixtures"
test_dir="$PWD/test/unit"
test_fixtures_dir="$test_dir/fixtures"
test_root_dir="$test_fixtures_dir/root"

export PREFIX="$test_root_dir"
export HOME="$test_root_dir/home"
export PATH="$PWD/bin:$PATH"
hash -r

unset GEM_HOME GEM_PATH

. ./test/config.sh
. ./test/unit/config.sh
. ./share/chruby/chruby.sh
chruby_reset

# Capture the PATH after chruby_reset
test_path="$PATH"
# Capture certain env variables so we can restore them
original_path="$PATH"
original_pwd="$PWD"

setUp() { return; }
tearDown() { return; }
Expand Down
5 changes: 3 additions & 2 deletions test/runner → test/unit/runner
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ function log() {
fi
}

test_dir="${0%/*}"
error=0

for test in ${0%/*}/*_test.sh; do
for test in "$test_dir/"*_test.sh; do
log "Running $test under $SHELL (interactive) ..."
"$SHELL" $* -i "$test" || error=1
echo
done

for test in ${0%/*}/*_test.sh; do
for test in "$test_dir"/*_test.sh; do
log "Running $test under $SHELL (non-interactive) ..."
"$SHELL" $* "$test" || error=1
echo
Expand Down

0 comments on commit a02854f

Please sign in to comment.