2019-11-25 01:24:46 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-27 05:17:41 -07:00
|
|
|
# shellcheck disable=SC2016
|
2019-11-25 01:24:46 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
2020-03-15 10:45:09 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
mkdir -p "$plugin_path/lib/commands"
|
2019-11-25 01:24:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2020-03-15 10:45:09 -07:00
|
|
|
@test "asdf help shows plugin extension commands" {
|
|
|
|
local plugin_path listed_cmds
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
touch "$plugin_path/lib/commands/command.bash"
|
|
|
|
touch "$plugin_path/lib/commands/command-foo.bash"
|
|
|
|
touch "$plugin_path/lib/commands/command-foo-bar.bash"
|
|
|
|
run asdf help
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "$output" | grep "PLUGIN dummy" # should present plugin section
|
2023-01-27 05:17:41 -07:00
|
|
|
listed_cmds=$(echo "$output" | grep -c "asdf dummy")
|
2020-03-15 10:45:09 -07:00
|
|
|
[ "$listed_cmds" -eq 3 ]
|
2022-07-05 06:40:33 -07:00
|
|
|
echo "$output" | grep "asdf dummy foo bar" # should present commands without hyphens
|
2020-03-15 10:45:09 -07:00
|
|
|
}
|
|
|
|
|
2021-09-23 11:47:26 -07:00
|
|
|
@test "asdf help shows extension commands for plugin with hyphens in the name" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
2021-09-23 11:47:26 -07:00
|
|
|
|
|
|
|
plugin_name=dummy-hyphenated
|
|
|
|
install_mock_plugin $plugin_name
|
|
|
|
|
|
|
|
plugin_path="$(get_plugin_path $plugin_name)"
|
|
|
|
mkdir -p "$plugin_path/lib/commands"
|
|
|
|
touch "$plugin_path/lib/commands/command.bash"
|
|
|
|
touch "$plugin_path/lib/commands/command-foo.bash"
|
|
|
|
touch "$plugin_path/lib/commands/command-foo-bar.bash"
|
|
|
|
|
|
|
|
run asdf help
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" == *"PLUGIN $plugin_name"* ]]
|
|
|
|
listed_cmds=$(grep -c "asdf $plugin_name" <<<"${output}")
|
|
|
|
[[ $listed_cmds -eq 3 ]]
|
|
|
|
[[ "$output" == *"asdf $plugin_name foo"* ]]
|
|
|
|
[[ "$output" == *"asdf $plugin_name foo bar"* ]]
|
|
|
|
}
|
|
|
|
|
2019-11-25 01:24:46 -07:00
|
|
|
@test "asdf can execute plugin bin commands" {
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
|
|
|
|
# this plugin defines a new `asdf dummy foo` command
|
2022-06-24 02:20:27 -07:00
|
|
|
cat <<'EOF' >"$plugin_path/lib/commands/command-foo.bash"
|
2019-11-25 01:24:46 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
echo this is an executable $*
|
|
|
|
EOF
|
2020-03-15 10:45:09 -07:00
|
|
|
chmod +x "$plugin_path/lib/commands/command-foo.bash"
|
2019-11-25 01:24:46 -07:00
|
|
|
|
|
|
|
expected="this is an executable bar"
|
2019-11-25 11:07:55 -07:00
|
|
|
|
2019-11-25 01:24:46 -07:00
|
|
|
run asdf dummy foo bar
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "asdf can source plugin bin scripts" {
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
|
|
|
|
# this plugin defines a new `asdf dummy foo` command
|
2022-06-24 02:20:27 -07:00
|
|
|
echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' >"$plugin_path/lib/commands/command-foo.bash"
|
2019-11-25 01:24:46 -07:00
|
|
|
|
|
|
|
expected="sourced script has asdf utils $plugin_path bar"
|
2019-11-25 11:07:55 -07:00
|
|
|
|
2019-11-25 01:24:46 -07:00
|
|
|
run asdf dummy foo bar
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|
2019-11-25 11:07:55 -07:00
|
|
|
|
|
|
|
@test "asdf can execute plugin default command without arguments" {
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
|
|
|
|
# this plugin defines a new `asdf dummy` command
|
2022-06-24 02:20:27 -07:00
|
|
|
cat <<'EOF' >"$plugin_path/lib/commands/command.bash"
|
2019-11-25 11:07:55 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
echo hello
|
|
|
|
EOF
|
2020-03-15 10:45:09 -07:00
|
|
|
chmod +x "$plugin_path/lib/commands/command.bash"
|
2019-11-25 11:07:55 -07:00
|
|
|
|
|
|
|
expected="hello"
|
|
|
|
|
|
|
|
run asdf dummy
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "asdf can execute plugin default command with arguments" {
|
|
|
|
plugin_path="$(get_plugin_path dummy)"
|
|
|
|
|
|
|
|
# this plugin defines a new `asdf dummy` command
|
2022-06-24 02:20:27 -07:00
|
|
|
cat <<'EOF' >"$plugin_path/lib/commands/command.bash"
|
2019-11-25 11:07:55 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
echo hello $*
|
|
|
|
EOF
|
2020-03-15 10:45:09 -07:00
|
|
|
chmod +x "$plugin_path/lib/commands/command.bash"
|
2019-11-25 11:07:55 -07:00
|
|
|
|
|
|
|
expected="hello world"
|
|
|
|
|
|
|
|
run asdf dummy world
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|