Use dummy plugin in version_commands test

This adds a helper to install dummy versions. Hopefully it makes the
test setup a little easier to reason about.
This commit is contained in:
Kevin Rockwood 2016-07-23 16:15:05 +09:00
parent ca1273e7d4
commit 0ce18100c5
2 changed files with 45 additions and 38 deletions

View File

@ -12,6 +12,11 @@ install_dummy_plugin() {
cp -r $BATS_TEST_DIRNAME/fixtures/dummy_plugin $ASDF_DIR/plugins/dummy
}
install_dummy_version() {
dummy_version=$1
mkdir -p $ASDF_DIR/installs/dummy/$dummy_version
}
clean_asdf_dir() {
rm -rf $BASE_DIR
unset ASDF_DIR

View File

@ -6,13 +6,18 @@ load test_helpers
setup() {
setup_asdf_dir
install_dummy_plugin
install_dummy_version "1.0.0"
install_dummy_version "1.1.0"
install_dummy_version "1.2.0"
OTHER_DIR=$BASE_DIR/other
mkdir -p $ASDF_DIR/plugins/foo $ASDF_DIR/plugins/bar $ASDF_DIR/installs/foo/1.0.0 $ASDF_DIR/installs/foo/1.1.0 $ASDF_DIR/installs/foo/1.2.0 $ASDF_DIR/installs/bar/1.0.0 $OTHER_DIR
PROJECT_DIR=$BASE_DIR/project
mkdir -p $PROJECT_DIR
cd $OTHER_DIR
echo 'foo 1.0.0' >> $HOME/.tool-versions
echo 'foo 1.1.0' >> .tool-versions
echo 'dummy 1.0.0' >> $HOME/.tool-versions
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
cd $PROJECT_DIR
}
teardown() {
@ -29,9 +34,9 @@ teardown() {
@test "global should emit an error when run in lookup mode and file does not exist" {
rm $HOME/.tool-versions
run global_command "foo"
run global_command "dummy"
[ "$status" -eq 1 ]
[ "$output" = "version not set for foo" ]
[ "$output" = "version not set for dummy" ]
}
@test "local should emit an error when plugin does not exist" {
@ -41,77 +46,74 @@ teardown() {
}
@test "local should emit an error when plugin version does not exist" {
run local_command "foo" "0.0.1"
run local_command "dummy" "0.0.1"
[ "$status" -eq 1 ]
[ "$output" = "version 0.0.1 is not installed for foo" ]
[ "$output" = "version 0.0.1 is not installed for dummy" ]
}
@test "local should return and set the local version" {
run local_command
[ "$status" -eq 0 ]
[ "$output" = "foo 1.1.0" ]
[ "$output" = "dummy 1.1.0" ]
run local_command foo "1.2.0"
run local_command dummy "1.2.0"
run local_command foo
run local_command dummy
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
run local_command bar
[ "$status" -eq 1 ]
run local_command bar 1.0.0
[ "$status" -eq 0 ]
run local_command bar
[ "$status" -eq 0 ]
[ "$output" = "1.0.0" ]
rm .tool-versions
run local_command foo 1.2.0
run local_command dummy 1.2.0
[ -f .tool-versions ]
run local_command foo
run local_command dummy
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
run global_command foo
run global_command dummy
[ "$output" = "1.0.0" ]
mkdir $BASE_DIR/other && cd $BASE_DIR/other
run local_command dummy
[ "$status" -eq 1 ]
run local_command dummy 1.0.0
[ "$status" -eq 0 ]
run local_command dummy
[ "$status" -eq 0 ]
[ "$output" = "1.0.0" ]
}
@test "local should fallback to legacy-file when enabled" {
echo 'legacy_version_file = yes' > $HOME/.asdfrc
mkdir -p $ASDF_DIR/plugins/foo/bin
echo 'echo 1.0.0' > $ASDF_DIR/plugins/foo/bin/get-version-from-legacy-file
echo '1.3.0' > .dummy-version
rm .tool-versions
run local_command foo
run local_command dummy
[ "$status" -eq 0 ]
[ "$output" = "1.0.0" ]
[ "$output" = "1.3.0" ]
}
@test "local should ignore legacy-file when disabled" {
mkdir -p $ASDF_DIR/plugins/foo/bin
echo 'cat 1.0.0' > $ASDF_DIR/plugins/foo/bin/get-version-from-legacy-file
rm .tool-versions
run local_command foo
run local_command dummy
[ "$status" -eq 1 ]
[ "$output" = "version not set for foo" ]
[ "$output" = "version not set for dummy" ]
}
@test "global should return and set the global version" {
run global_command
[ "$status" -eq 0 ]
[ "$output" = "foo 1.0.0" ]
[ "$output" = "dummy 1.0.0" ]
run global_command foo 1.2.0
run global_command dummy 1.2.0
[ "$status" -eq 0 ]
run global_command foo
run global_command dummy
[ "$status" -eq 0 ]
[ "$output" = "1.2.0" ]
}