2016-04-24 08:11:33 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
load test_helpers
|
2016-04-24 08:11:33 -07:00
|
|
|
|
|
|
|
setup() {
|
2016-06-28 20:56:33 -07:00
|
|
|
setup_asdf_dir
|
2016-07-23 17:03:43 -07:00
|
|
|
install_dummy_plugin
|
|
|
|
install_dummy_version "0.1.0"
|
|
|
|
install_dummy_version "0.2.0"
|
|
|
|
|
2016-07-24 17:12:40 -07:00
|
|
|
PROJECT_DIR=$HOME/project
|
2016-07-23 17:03:43 -07:00
|
|
|
mkdir -p $PROJECT_DIR
|
2016-04-24 08:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2016-06-28 20:56:33 -07:00
|
|
|
clean_asdf_dir
|
2016-04-24 08:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "check_if_version_exists should exit with 1 if plugin does not exist" {
|
2016-07-23 17:03:43 -07:00
|
|
|
run check_if_version_exists "inexistent" "1.0.0"
|
2016-04-24 08:11:33 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2016-07-23 17:03:43 -07:00
|
|
|
[ "$output" = "version 1.0.0 is not installed for inexistent" ]
|
2016-04-24 08:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "check_if_version_exists should exit with 1 if version does not exist" {
|
2016-07-23 17:03:43 -07:00
|
|
|
run check_if_version_exists "dummy" "1.0.0"
|
2016-04-24 08:11:33 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2016-07-23 17:03:43 -07:00
|
|
|
[ "$output" = "version 1.0.0 is not installed for dummy" ]
|
2016-04-24 08:11:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "check_if_version_exists should be noop if version exists" {
|
2016-07-23 17:03:43 -07:00
|
|
|
run check_if_version_exists "dummy" "0.1.0"
|
2016-04-24 08:11:33 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
}
|
2016-07-05 16:19:15 -07:00
|
|
|
|
|
|
|
@test "check_if_plugin_exists should exit with 1 when plugin is empty string" {
|
|
|
|
run check_if_plugin_exists
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "No such plugin" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "check_if_plugin_exists should be noop if plugin exists" {
|
2016-07-23 17:03:43 -07:00
|
|
|
run check_if_plugin_exists "dummy"
|
2016-07-05 16:19:15 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "" ]
|
|
|
|
}
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
@test "find_version should return .tool-versions if legacy is disabled" {
|
|
|
|
echo "dummy 0.1.0" > $PROJECT_DIR/.tool-versions
|
|
|
|
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
run find_version "dummy" $PROJECT_DIR
|
2016-07-24 17:12:40 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2016-08-27 21:43:54 -07:00
|
|
|
[ "$output" = "0.1.0:$PROJECT_DIR/.tool-versions" ]
|
2016-07-24 17:12:40 -07:00
|
|
|
}
|
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
@test "find_version should return the legacy file if supported" {
|
|
|
|
echo "legacy_version_file = yes" > $HOME/.asdfrc
|
|
|
|
echo "dummy 0.1.0" > $HOME/.tool-versions
|
|
|
|
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
run find_version "dummy" $PROJECT_DIR
|
2016-07-24 17:12:40 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2016-08-27 21:43:54 -07:00
|
|
|
[ "$output" = "0.2.0:$PROJECT_DIR/.dummy-version" ]
|
2016-07-24 17:12:40 -07:00
|
|
|
}
|
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
@test "find_version skips .tool-version file that don't list the plugin" {
|
|
|
|
echo "dummy 0.1.0" > $HOME/.tool-versions
|
|
|
|
echo "another_plugin 0.3.0" > $PROJECT_DIR/.tool-versions
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
run find_version "dummy" $PROJECT_DIR
|
2016-07-24 17:12:40 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2016-08-27 21:43:54 -07:00
|
|
|
[ "$output" = "0.1.0:$HOME/.tool-versions" ]
|
2016-07-24 17:12:40 -07:00
|
|
|
}
|
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
@test "find_version should return .tool-versions if unsupported" {
|
|
|
|
echo "dummy 0.1.0" > $HOME/.tool-versions
|
|
|
|
echo "0.2.0" > $PROJECT_DIR/.dummy-version
|
|
|
|
echo "legacy_version_file = yes" > $HOME/.asdfrc
|
|
|
|
rm $ASDF_DIR/plugins/dummy/bin/list-legacy-filenames
|
2016-07-24 17:12:40 -07:00
|
|
|
|
2016-08-27 21:15:56 -07:00
|
|
|
run find_version "dummy" $PROJECT_DIR
|
2016-07-24 17:12:40 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2016-08-27 21:43:54 -07:00
|
|
|
[ "$output" = "0.1.0:$HOME/.tool-versions" ]
|
2016-07-24 17:12:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "get_preset_version_for returns the current version" {
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo "dummy 0.2.0" > .tool-versions
|
|
|
|
run get_preset_version_for "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "0.2.0" ]
|
|
|
|
}
|
2016-10-29 04:08:54 -07:00
|
|
|
|
|
|
|
@test "get_preset_version_for returns the global version from home when project is outside of home" {
|
|
|
|
echo "dummy 0.1.0" > $HOME/.tool-versions
|
|
|
|
PROJECT_DIR=$BASE_DIR/project
|
|
|
|
mkdir -p $PROJECT_DIR
|
|
|
|
run get_preset_version_for "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "0.1.0" ]
|
|
|
|
}
|
2016-11-10 12:01:19 -07:00
|
|
|
|
|
|
|
@test "get_preset_version_for returns the tool version from env if ASDF_{TOOL}_VERSION is defined" {
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo "dummy 0.2.0" > .tool-versions
|
|
|
|
ASDF_DUMMY_VERSION=3.0.0 run get_preset_version_for "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "3.0.0" ]
|
|
|
|
}
|