Skip to content

Commit 57dae94

Browse files
committed
modules: List internal, public project module
Closes #150. This is the second and last step towards updating the output to match _GO_USE_MODULES behavior.
1 parent f8a8970 commit 57dae94

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed

libexec/modules

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# List optional Bash modules available for import via `. "$_GO_USE_MODULES"`
44
#
55
# Usage:
6-
# A list of all available plugins by class (core, plugin, project):
6+
# A list of all available modules by class (core, internal, public, plugins):
77
# {{go}} {{cmd}} [--paths|--summaries]
88
#
99
# The paths or one-line summaries for all or individual modules:
@@ -125,6 +125,7 @@ _@go.modules_produce_listing() {
125125
local action="$1"
126126
local modules=("${__go_modules[@]#$_GO_CORE_DIR/lib/}")
127127
modules=("${modules[@]#$_GO_SCRIPTS_DIR/lib/}")
128+
modules=("${modules[@]#$_GO_ROOTDIR/lib/}")
128129

129130
if [[ -n "$_GO_PLUGINS_DIR" ]]; then
130131
modules=("${modules[@]#$_GO_PLUGINS_DIR/}")
@@ -183,7 +184,10 @@ _@go.modules_search() {
183184
__go_core_modules_end="${#__go_modules[@]}"
184185

185186
_@go.modules_find_all_in_dir "$_GO_SCRIPTS_DIR" "$glob"
186-
__go_project_modules_end="${#__go_modules[@]}"
187+
__go_internal_modules_end="${#__go_modules[@]}"
188+
189+
_@go.modules_find_all_in_dir "$_GO_ROOTDIR" "$glob"
190+
__go_public_modules_end="${#__go_modules[@]}"
187191

188192
@go.search_plugins '_@go.modules_search_plugins'
189193
__go_plugin_modules_end="${#__go_modules[@]}"
@@ -208,18 +212,21 @@ _@go.modules_list_by_class() {
208212
local action="$1"
209213
local __go_modules=()
210214
local __go_core_modules_end=0
211-
local __go_project_modules_end=0
215+
local __go_internal_modules_end=0
216+
local __go_public_modules_end=0
212217
local __go_plugin_modules_end=0
213218
local __go_all_modules
214219

215220
_@go.modules_search
216221
__go_all_modules=("${__go_modules[@]}")
217222
_@go.modules_emit_class 'core framework library' "$action" \
218223
0 "$__go_core_modules_end"
219-
_@go.modules_emit_class 'project library' "$action" \
220-
"$__go_core_modules_end" "$__go_project_modules_end"
224+
_@go.modules_emit_class 'internal project library' "$action" \
225+
"$__go_core_modules_end" "$__go_internal_modules_end"
226+
_@go.modules_emit_class 'public project library' "$action" \
227+
"$__go_internal_modules_end" "$__go_public_modules_end"
221228
_@go.modules_emit_class 'installed plugin libraries' "$action" \
222-
"$__go_project_modules_end" "$__go_plugin_modules_end"
229+
"$__go_public_modules_end" "$__go_plugin_modules_end"
223230
}
224231

225232
_@go.modules_list() {
@@ -323,6 +330,7 @@ _@go.modules_tab_completion() {
323330
if [[ ! "$glob" =~ / ]]; then
324331
_@go.modules_find_all_in_dir "$_GO_CORE_DIR" "$glob"
325332
_@go.modules_find_all_in_dir "$_GO_SCRIPTS_DIR" "$glob"
333+
_@go.modules_find_all_in_dir "$_GO_ROOTDIR" "$glob"
326334
fi
327335

328336
# The trick here is, if only one plugin matches, we want to return all of

tests/modules/arg-completion.bats

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ teardown() {
1616
@test "$SUITE: zero arguments" {
1717
run "$TEST_GO_SCRIPT" complete 1 modules ''
1818
local expected=('-h' '-help' '--help' '--paths' '--summaries' '--imported'
19-
"${CORE_MODULES[@]}" "${TEST_PROJECT_MODULES[@]}" "${TEST_PLUGINS[@]/%//}")
19+
"${CORE_MODULES[@]}" "${TEST_INTERNAL_MODULES[@]}"
20+
"${TEST_PUBLIC_MODULES[@]}" "${TEST_PLUGINS[@]/%//}")
2021
assert_success "${expected[@]}"
2122
}
2223

@@ -57,8 +58,8 @@ teardown() {
5758

5859
@test "$SUITE: return plugin dirs, core and project modules for flag" {
5960
# Note that plugins are offered last
60-
local expected=(
61-
"${CORE_MODULES[@]}" "${TEST_PROJECT_MODULES[@]}" "${TEST_PLUGINS[@]/%//}")
61+
local expected=("${CORE_MODULES[@]}" "${TEST_INTERNAL_MODULES[@]}"
62+
"${TEST_PUBLIC_MODULES[@]}" "${TEST_PLUGINS[@]/%//}")
6263
run "$TEST_GO_SCRIPT" complete 2 modules --help ''
6364
assert_success "${expected[@]}"
6465
}
@@ -71,7 +72,7 @@ teardown() {
7172

7273
@test "$SUITE: return only matching plugin names" {
7374
local expected=('_bar/' '_baz/')
74-
run "$TEST_GO_SCRIPT" complete 2 modules help '_b'
75+
run "$TEST_GO_SCRIPT" complete 2 modules help '_ba'
7576
assert_success "${expected[@]}"
7677
}
7778

@@ -116,7 +117,8 @@ teardown() {
116117
}
117118

118119
@test "$SUITE: don't complete plugins when all modules already present" {
119-
local expected=("${CORE_MODULES[@]}" '_frobozz' '_frotz' '_bar/' '_baz/')
120+
local expected=("${CORE_MODULES[@]}" '_frobozz' '_frotz' \
121+
'_blorple' '_rezrov' '_bar/' '_baz/')
120122
run "$TEST_GO_SCRIPT" complete 4 modules \
121123
'_foo/_plugh' '_foo/_quux' '_foo/_xyzzy' ''
122124
assert_success "${expected[@]}"

tests/modules/helpers.bash

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
CORE_MODULES=()
66
CORE_MODULES_PATHS=()
77

8-
TEST_PROJECT_MODULES=('_frobozz' '_frotz')
9-
TEST_PROJECT_MODULES_PATHS=()
8+
TEST_INTERNAL_MODULES=('_frobozz' '_frotz')
9+
TEST_INTERNAL_MODULES_PATHS=()
10+
11+
TEST_PUBLIC_MODULES=('_blorple' '_rezrov')
12+
TEST_PUBLIC_MODULES_PATHS=()
1013

1114
# We start all the test plugin and module names with '_' to avoid collisions
1215
# with any potential module names added to the core framework.
@@ -28,11 +31,19 @@ setup_test_modules() {
2831
fi
2932
done
3033

31-
for module in "${TEST_PROJECT_MODULES[@]}"; do
34+
for module in "${TEST_INTERNAL_MODULES[@]}"; do
3235
module_file="$TEST_GO_SCRIPTS_DIR/lib/$module"
3336
mkdir -p "${module_file%/*}"
3437
printf '# Summary for %s\n' "$module" > "$module_file"
35-
TEST_PROJECT_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
38+
TEST_INTERNAL_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
39+
((++TOTAL_NUM_MODULES))
40+
done
41+
42+
for module in "${TEST_PUBLIC_MODULES[@]}"; do
43+
module_file="$TEST_GO_ROOTDIR/lib/$module"
44+
mkdir -p "${module_file%/*}"
45+
printf '# Summary for %s\n' "$module" > "$module_file"
46+
TEST_PUBLIC_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
3647
((++TOTAL_NUM_MODULES))
3748
done
3849

tests/modules/main.bats

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ get_first_and_last_core_module_summaries() {
6868
@go.create_test_go_script \
6969
'. "$_GO_USE_MODULES" "complete" "_foo/_plugh"' \
7070
'. "$_GO_USE_MODULES" "_bar/_quux" "_foo/_plugh"' \
71-
'. "$_GO_USE_MODULES" "_frotz"' \
71+
'. "$_GO_USE_MODULES" "_frotz" "_blorple"' \
7272
'@go "$@"'
7373

7474
# The first will be an absolute path because the script's _GO_ROOTDIR doesn't
@@ -81,6 +81,8 @@ get_first_and_last_core_module_summaries() {
8181
"_bar/_quux scripts/plugins/_bar/lib/_quux"
8282
" go:4 main"
8383
"_frotz scripts/lib/_frotz"
84+
" go:5 main"
85+
"_blorple lib/_blorple"
8486
" go:5 main")
8587

8688
run "$TEST_GO_SCRIPT" modules --imported
@@ -91,8 +93,11 @@ get_first_and_last_core_module_summaries() {
9193
local expected=('From the core framework library:'
9294
"${CORE_MODULES[@]/#/ }"
9395
''
94-
'From the project library:'
95-
"${TEST_PROJECT_MODULES[@]/#/ }"
96+
'From the internal project library:'
97+
"${TEST_INTERNAL_MODULES[@]/#/ }"
98+
''
99+
'From the public project library:'
100+
"${TEST_PUBLIC_MODULES[@]/#/ }"
96101
''
97102
'From the installed plugin libraries:'
98103
"${TEST_PLUGIN_MODULES[@]/#/ }"
@@ -104,7 +109,8 @@ get_first_and_last_core_module_summaries() {
104109

105110
@test "$SUITE: list using glob, all modules" {
106111
local expected=("${CORE_MODULES[@]}"
107-
"${TEST_PROJECT_MODULES[@]}"
112+
"${TEST_INTERNAL_MODULES[@]}"
113+
"${TEST_PUBLIC_MODULES[@]}"
108114
"${TEST_PLUGIN_MODULES[@]}"
109115
)
110116

@@ -118,14 +124,16 @@ get_first_and_last_core_module_summaries() {
118124
)
119125

120126
rm "${TEST_PLUGIN_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}" \
121-
"${TEST_PROJECT_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}"
127+
"${TEST_INTERNAL_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}" \
128+
"${TEST_PUBLIC_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}"
122129
run "$TEST_GO_SCRIPT" modules
123130
assert_success "${expected[@]}"
124131
}
125132

126133
@test "$SUITE: list using glob, only core modules present" {
127134
rm "${TEST_PLUGIN_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}" \
128-
"${TEST_PROJECT_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}"
135+
"${TEST_INTERNAL_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}" \
136+
"${TEST_PUBLIC_MODULES_PATHS[@]/#/$TEST_GO_ROOTDIR/}"
129137
run "$TEST_GO_SCRIPT" modules '*'
130138
assert_success "${CORE_MODULES[@]}"
131139
}
@@ -141,6 +149,8 @@ get_first_and_last_core_module_summaries() {
141149
# Note the padding is relative to only the project modules.
142150
assert_output_matches $' _frobozz scripts/lib/_frobozz\n'
143151
assert_output_matches $' _frotz scripts/lib/_frotz\n\n'
152+
assert_output_matches $' _blorple lib/_blorple\n'
153+
assert_output_matches $' _rezrov lib/_rezrov\n\n'
144154

145155
# Note the padding is relative to only the plugin modules. Use a variable to
146156
# keep the assertion lines under 80 columns. Bats trims the last newline of
@@ -150,9 +160,9 @@ get_first_and_last_core_module_summaries() {
150160
assert_output_matches " _foo/_quux $plugins/_foo/lib/_quux"$'\n'
151161
assert_output_matches " _foo/_xyzzy $plugins/_foo/lib/_xyzzy$"
152162

153-
# Since the 'lines' array doesn't contain blank lines, we only add '3' to
163+
# Since the 'lines' array doesn't contain blank lines, we only add '4' to
154164
# account for the 'From the...' line starting each class section.
155-
assert_equal "$((TOTAL_NUM_MODULES + 3))" "${#lines[@]}"
165+
assert_equal "$((TOTAL_NUM_MODULES + 4))" "${#lines[@]}"
156166
}
157167

158168
@test "$SUITE: paths using glob, all modules" {
@@ -170,6 +180,10 @@ get_first_and_last_core_module_summaries() {
170180
$'\n_frobozz +scripts/lib/_frobozz\n'
171181
assert_output_matches \
172182
$'\n_frotz +scripts/lib/_frotz\n'
183+
assert_output_matches \
184+
$'\n_blorple +lib/_blorple\n'
185+
assert_output_matches \
186+
$'\n_rezrov +lib/_rezrov\n'
173187
assert_output_matches \
174188
$'\n_bar/_plugh +scripts/plugins/_bar/lib/_plugh\n'
175189
assert_output_matches \
@@ -192,16 +206,18 @@ get_first_and_last_core_module_summaries() {
192206
# Note the padding is relative to only the project modules.
193207
assert_output_matches $' _frobozz Summary for _frobozz\n'
194208
assert_output_matches $' _frotz Summary for _frotz\n'
209+
assert_output_matches $' _blorple Summary for _blorple\n'
210+
assert_output_matches $' _rezrov Summary for _rezrov\n'
195211

196212
# Note the padding is relative to only the plugin modules. Bats trims
197213
# the last newline of the output.
198214
assert_output_matches $' _bar/_plugh Summary for _bar/_plugh\n'
199215
assert_output_matches $' _foo/_quux Summary for _foo/_quux\n'
200216
assert_output_matches ' _foo/_xyzzy Summary for _foo/_xyzzy$'
201217

202-
# Since the 'lines' array doesn't contain blank lines, we only add '3' to
218+
# Since the 'lines' array doesn't contain blank lines, we only add '4' to
203219
# account for the 'From the...' line starting each class section.
204-
assert_equal "$((TOTAL_NUM_MODULES + 3))" "${#lines[@]}"
220+
assert_equal "$((TOTAL_NUM_MODULES + 4))" "${#lines[@]}"
205221
}
206222

207223
@test "$SUITE: summaries using glob, all modules" {
@@ -216,6 +232,8 @@ get_first_and_last_core_module_summaries() {
216232
assert_output_matches "$LAST_CORE_MODULE +$LAST_CORE_MOD_SUMMARY"$'\n'
217233
assert_output_matches $'_frobozz +Summary for _frobozz\n'
218234
assert_output_matches $'_frotz +Summary for _frotz\n'
235+
assert_output_matches $'_blorple +Summary for _blorple\n'
236+
assert_output_matches $'_rezrov +Summary for _rezrov\n'
219237
assert_output_matches $'_bar/_plugh +Summary for _bar/_plugh\n'
220238
assert_output_matches $'_foo/_quux +Summary for _foo/_quux\n'
221239
assert_output_matches $'_foo/_xyzzy +Summary for _foo/_xyzzy$'
@@ -225,12 +243,13 @@ get_first_and_last_core_module_summaries() {
225243

226244
@test "$SUITE: list only test modules" {
227245
run "$TEST_GO_SCRIPT" modules '_*'
228-
assert_success "${TEST_PROJECT_MODULES[@]}" "${TEST_PLUGIN_MODULES[@]}"
246+
assert_success "${TEST_INTERNAL_MODULES[@]}" "${TEST_PUBLIC_MODULES[@]}" \
247+
"${TEST_PLUGIN_MODULES[@]}"
229248
}
230249

231250
@test "$SUITE: list only test project modules" {
232-
run "$TEST_GO_SCRIPT" modules '_fr*'
233-
assert_success "${TEST_PROJECT_MODULES[@]}"
251+
run "$TEST_GO_SCRIPT" modules '_fr*' '_blor*' '_rezr*'
252+
assert_success "${TEST_INTERNAL_MODULES[@]}" "${TEST_PUBLIC_MODULES[@]}"
234253
}
235254

236255
@test "$SUITE: list only modules in the _bar and _baz plugins" {

0 commit comments

Comments
 (0)