asdf

Форк
0
/
plugin_add_command.bats 
176 строк · 5.2 Кб
1
#!/usr/bin/env bats
2
# shellcheck disable=SC2030,SC2031
3

4
load test_helpers
5

6
setup() {
7
  setup_asdf_dir
8
}
9

10
teardown() {
11
  clean_asdf_dir
12
}
13

14
@test "plugin_add command with plugin name matching all valid regex chars succeeds" {
15
  install_mock_plugin_repo "plugin_with-all-valid-chars-123"
16

17
  run asdf plugin add "plugin_with-all-valid-chars-123" "${BASE_DIR}/repo-plugin_with-all-valid-chars-123"
18
  [ "$status" -eq 0 ]
19

20
  run asdf plugin list
21
  [ "$output" = "plugin_with-all-valid-chars-123" ]
22
}
23

24
@test "plugin_add command with LANG=sv_SE.UTF-8 and plugin name matching all valid regex chars succeeds" {
25
  ORIGINAL_LANG="$LANG"
26
  LANG=sv_SE.UTF-8
27

28
  install_mock_plugin_repo "plugin-with-w"
29

30
  # https://stackoverflow.com/questions/52570103/regular-expression-a-za-z-seems-to-not-include-letter-w-and-wA
31
  # https://github.com/asdf-vm/asdf/issues/1237
32
  run asdf plugin add "plugin-with-w" "${BASE_DIR}/repo-plugin-with-w"
33
  [ "$status" -eq 0 ]
34

35
  run asdf plugin-list
36
  [ "$output" = "plugin-with-w" ]
37

38
  LANG="$ORIGINAL_LANG"
39
}
40

41
@test "plugin_add command with plugin name not matching valid regex fails 1" {
42
  run asdf plugin add "invalid\$plugin\$name"
43
  [ "$status" -eq 1 ]
44
  [ "$output" = "invalid\$plugin\$name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
45
}
46

47
@test "plugin_add command with plugin name not matching valid regex fails 2" {
48
  run asdf plugin add "#invalid#plugin#name"
49
  [ "$status" -eq 1 ]
50
  [ "$output" = "#invalid#plugin#name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
51
}
52

53
@test "plugin_add command with plugin name not matching valid regex fails 3" {
54
  run asdf plugin add "Ruby"
55
  [ "$status" -eq 1 ]
56
  [ "$output" = "Ruby is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
57
}
58

59
@test "plugin_add command with no URL specified adds a plugin using repo" {
60
  run asdf plugin add "elixir"
61
  [ "$status" -eq 0 ]
62

63
  run asdf plugin list
64
  [ "$output" = "elixir" ]
65
}
66

67
@test "plugin_add command with no URL specified adds a plugin when short name repository is enabled" {
68
  export ASDF_CONFIG_DEFAULT_FILE="$HOME/.asdfrc"
69
  echo "disable_plugin_short_name_repository=no" >"$ASDF_CONFIG_DEFAULT_FILE"
70

71
  run asdf plugin add "elixir"
72
  [ "$status" -eq 0 ]
73

74
  local expected="elixir"
75
  run asdf plugin list
76
  [ "$output" = "$expected" ]
77
}
78

79
@test "plugin_add command with no URL specified fails to add a plugin when disabled" {
80
  export ASDF_CONFIG_DEFAULT_FILE="$HOME/.asdfrc"
81
  echo "disable_plugin_short_name_repository=yes" >"$ASDF_CONFIG_DEFAULT_FILE"
82
  local expected="Short-name plugin repository is disabled"
83

84
  run asdf plugin add "elixir"
85
  [ "$status" -eq 1 ]
86
  [ "$output" = "$expected" ]
87
}
88

89
@test "plugin_add command with URL specified adds a plugin using repo" {
90
  install_mock_plugin_repo "dummy"
91

92
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
93
  [ "$status" -eq 0 ]
94

95
  run asdf plugin list
96
  # whitespace between 'elixir' and url is from printf %-15s %s format
97
  [ "$output" = "dummy" ]
98
}
99

100
@test "plugin_add command with URL specified twice returns success on second time" {
101
  install_mock_plugin_repo "dummy"
102

103
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
104
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
105
  [ "$status" -eq 0 ]
106
  [ "$output" = "Plugin named dummy already added" ]
107
}
108

109
@test "plugin_add command with no URL specified fails if the plugin doesn't exist" {
110
  run asdf plugin add "does-not-exist"
111
  [ "$status" -eq 1 ]
112
  echo "$output" | grep "plugin does-not-exist not found in repository"
113
}
114

115
@test "plugin_add command executes post-plugin add script" {
116
  install_mock_plugin_repo "dummy"
117

118
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
119
  [ "$output" = "plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy" ]
120
}
121

122
@test "plugin_add command executes configured pre hook (generic)" {
123
  install_mock_plugin_repo "dummy"
124

125
  cat >"$HOME/.asdfrc" <<-'EOM'
126
pre_asdf_plugin_add = echo ADD ${@}
127
EOM
128

129
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
130

131
  local expected_output="ADD dummy
132
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
133
  [ "$output" = "${expected_output}" ]
134
}
135

136
@test "plugin_add command executes configured pre hook (specific)" {
137
  install_mock_plugin_repo "dummy"
138

139
  cat >"$HOME/.asdfrc" <<-'EOM'
140
pre_asdf_plugin_add_dummy = echo ADD
141
EOM
142

143
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
144

145
  local expected_output="ADD
146
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
147
  [ "$output" = "${expected_output}" ]
148
}
149

150
@test "plugin_add command executes configured post hook (generic)" {
151
  install_mock_plugin_repo "dummy"
152

153
  cat >"$HOME/.asdfrc" <<-'EOM'
154
post_asdf_plugin_add = echo ADD ${@}
155
EOM
156

157
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
158

159
  local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
160
ADD dummy"
161
  [ "$output" = "${expected_output}" ]
162
}
163

164
@test "plugin_add command executes configured post hook (specific)" {
165
  install_mock_plugin_repo "dummy"
166

167
  cat >"$HOME/.asdfrc" <<-'EOM'
168
post_asdf_plugin_add_dummy = echo ADD
169
EOM
170

171
  run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
172

173
  local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
174
ADD"
175
  [ "$output" = "${expected_output}" ]
176
}
177

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.