2016-07-24 08:47:17 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/current.sh
|
2017-08-18 21:56:28 -07:00
|
|
|
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh
|
2016-07-24 08:47:17 -07:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
2016-07-30 16:48:57 -07:00
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
install_dummy_version "1.2.0"
|
2018-10-10 07:00:59 -07:00
|
|
|
install_dummy_version "nightly-2000-01-01"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
|
|
|
PROJECT_DIR=$HOME/project
|
2016-07-30 16:48:57 -07:00
|
|
|
mkdir $PROJECT_DIR
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2016-07-30 16:48:57 -07:00
|
|
|
@test "current should derive from the current .tool-versions" {
|
2016-07-24 08:47:17 -07:00
|
|
|
cd $PROJECT_DIR
|
2016-07-30 16:48:57 -07:00
|
|
|
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
2016-07-24 08:47:17 -07:00
|
|
|
|
|
|
|
run current_command "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
2018-10-10 07:00:59 -07:00
|
|
|
[ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should handle long version name" {
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo "dummy nightly-2000-01-01" >> $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run current_command "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "nightly-2000-01-01 (set by $PROJECT_DIR/.tool-versions)" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
2018-11-10 04:32:02 -07:00
|
|
|
@test "current should handle multiple versions" {
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo "dummy 1.2.0 1.1.0" >> $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run current_command "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "1.2.0 1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-30 16:48:57 -07:00
|
|
|
@test "current should derive from the legacy file if enabled" {
|
|
|
|
cd $PROJECT_DIR
|
2016-07-24 08:47:17 -07:00
|
|
|
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
2016-07-30 16:48:57 -07:00
|
|
|
echo '1.2.0' >> $PROJECT_DIR/.dummy-version
|
2016-07-24 08:47:17 -07:00
|
|
|
|
|
|
|
run current_command "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
2018-10-10 07:00:59 -07:00
|
|
|
[ "$output" = "1.2.0 (set by $PROJECT_DIR/.dummy-version)" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should error when the plugin doesn't exist" {
|
|
|
|
run current_command "foobar"
|
|
|
|
[ "$status" -eq 1 ]
|
2018-04-30 09:49:40 -07:00
|
|
|
[ "$output" = "No such plugin: foobar" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should error when no version is set" {
|
2016-07-30 16:48:57 -07:00
|
|
|
cd $PROJECT_DIR
|
|
|
|
|
|
|
|
run current_command "dummy"
|
2018-04-09 11:35:51 -07:00
|
|
|
[ "$status" -eq 126 ]
|
2016-07-30 16:48:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should error when a version is set that isn't installed" {
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo 'dummy 9.9.9' >> $PROJECT_DIR/.tool-versions
|
2016-07-24 08:47:17 -07:00
|
|
|
|
|
|
|
run current_command "dummy"
|
|
|
|
[ "$status" -eq 1 ]
|
2016-07-30 16:48:57 -07:00
|
|
|
[ "$output" = "version 9.9.9 is not installed for dummy" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
2017-08-18 21:56:28 -07:00
|
|
|
|
|
|
|
@test "should output all plugins when no plugin passed" {
|
|
|
|
|
|
|
|
install_dummy_plugin
|
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
|
|
|
|
install_mock_plugin "foobar"
|
|
|
|
install_mock_plugin_version "foobar" "1.0.0"
|
|
|
|
|
2017-09-03 20:20:35 -07:00
|
|
|
install_mock_plugin "baz"
|
|
|
|
|
2017-08-18 21:56:28 -07:00
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
|
|
|
echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run current_command
|
2018-02-25 15:42:33 -07:00
|
|
|
expected="baz No version set for baz; please run \`asdf <global | local> baz <version>\`
|
2018-10-10 07:00:59 -07:00
|
|
|
dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions)
|
|
|
|
foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"
|
2017-08-18 21:56:28 -07:00
|
|
|
|
|
|
|
[ "$expected" = "$output" ]
|
|
|
|
}
|
2018-02-11 15:28:29 -07:00
|
|
|
|
|
|
|
@test "should always match the tool name exactly" {
|
|
|
|
install_dummy_plugin
|
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
|
|
|
|
install_mock_plugin "y"
|
|
|
|
install_mock_plugin_version "y" "2.1.0"
|
|
|
|
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
|
|
|
echo 'y 2.1.0' >> $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run current_command "y"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "2.1.0" ]]
|
|
|
|
}
|
|
|
|
|
2018-10-07 11:22:31 -07:00
|
|
|
@test "with no plugins prints an error" {
|
|
|
|
clean_asdf_dir
|
|
|
|
run current_command
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "$output" | grep "Oohes nooes ~! No plugins installed"
|
|
|
|
}
|