/
plugin_extension_command.bats
115 lines (91 loc) · 3.08 KB
/
plugin_extension_command.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bats
load test_helpers
setup() {
setup_asdf_dir
install_dummy_plugin
local plugin_path
plugin_path="$(get_plugin_path dummy)"
mkdir -p "$plugin_path/lib/commands"
}
teardown() {
clean_asdf_dir
}
@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
listed_cmds=$(echo "$output" | grep "asdf dummy" | wc -l)
[ "$listed_cmds" -eq 3 ]
echo "$output" | grep "asdf dummy foo bar" # should present commands without hipens
}
@test "asdf help shows extension commands for plugin with hyphens in the name" {
cd $PROJECT_DIR
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"* ]]
# shellcheck disable=SC2154
listed_cmds=$(grep -c "asdf $plugin_name" <<<"${output}")
[[ $listed_cmds -eq 3 ]]
[[ "$output" == *"asdf $plugin_name foo"* ]]
[[ "$output" == *"asdf $plugin_name foo bar"* ]]
}
@test "asdf can execute plugin bin commands" {
plugin_path="$(get_plugin_path dummy)"
# this plugin defines a new `asdf dummy foo` command
cat <<'EOF' > "$plugin_path/lib/commands/command-foo.bash"
#!/usr/bin/env bash
echo this is an executable $*
EOF
chmod +x "$plugin_path/lib/commands/command-foo.bash"
expected="this is an executable bar"
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
echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' > "$plugin_path/lib/commands/command-foo.bash"
expected="sourced script has asdf utils $plugin_path bar"
run asdf dummy foo bar
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}
@test "asdf can execute plugin default command without arguments" {
plugin_path="$(get_plugin_path dummy)"
# this plugin defines a new `asdf dummy` command
cat <<'EOF' > "$plugin_path/lib/commands/command.bash"
#!/usr/bin/env bash
echo hello
EOF
chmod +x "$plugin_path/lib/commands/command.bash"
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
cat <<'EOF' > "$plugin_path/lib/commands/command.bash"
#!/usr/bin/env bash
echo hello $*
EOF
chmod +x "$plugin_path/lib/commands/command.bash"
expected="hello world"
run asdf dummy world
[ "$status" -eq 0 ]
[ "$output" = "$expected" ]
}