Skip to content

Commit c8f6a4c

Browse files
committed
modules: List project modules before plugins
Part of #150. This is the first step towards updating the output to match _GO_USE_MODULES behavior. The next step will be to produce separate sections for internal and public project modules.
1 parent dfc37cf commit c8f6a4c

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

libexec/modules

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ _@go.modules_search() {
182182
_@go.modules_find_all_in_dir "$_GO_CORE_DIR" "$glob"
183183
__go_core_modules_end="${#__go_modules[@]}"
184184

185-
@go.search_plugins '_@go.modules_search_plugins'
186-
__go_plugin_modules_end="${#__go_modules[@]}"
187-
188185
_@go.modules_find_all_in_dir "$_GO_SCRIPTS_DIR" "$glob"
189186
__go_project_modules_end="${#__go_modules[@]}"
187+
188+
@go.search_plugins '_@go.modules_search_plugins'
189+
__go_plugin_modules_end="${#__go_modules[@]}"
190190
}
191191

192192
_@go.modules_emit_class() {
@@ -208,18 +208,18 @@ _@go.modules_list_by_class() {
208208
local action="$1"
209209
local __go_modules=()
210210
local __go_core_modules_end=0
211-
local __go_plugin_modules_end=0
212211
local __go_project_modules_end=0
212+
local __go_plugin_modules_end=0
213213
local __go_all_modules
214214

215215
_@go.modules_search
216216
__go_all_modules=("${__go_modules[@]}")
217217
_@go.modules_emit_class 'core framework library' "$action" \
218218
0 "$__go_core_modules_end"
219-
_@go.modules_emit_class 'installed plugin libraries' "$action" \
220-
"$__go_core_modules_end" "$__go_plugin_modules_end"
221219
_@go.modules_emit_class 'project library' "$action" \
222-
"$__go_plugin_modules_end" "$__go_project_modules_end"
220+
"$__go_core_modules_end" "$__go_project_modules_end"
221+
_@go.modules_emit_class 'installed plugin libraries' "$action" \
222+
"$__go_project_modules_end" "$__go_plugin_modules_end"
223223
}
224224

225225
_@go.modules_list() {

tests/modules/helpers.bash

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

8+
TEST_PROJECT_MODULES=('_frobozz' '_frotz')
9+
TEST_PROJECT_MODULES_PATHS=()
10+
811
# We start all the test plugin and module names with '_' to avoid collisions
912
# with any potential module names added to the core framework.
1013
TEST_PLUGINS=('_bar' '_baz' '_foo')
1114
TEST_PLUGIN_MODULES=(_{bar,baz,foo}/_{plugh,quux,xyzzy})
1215
TEST_PLUGIN_MODULES_PATHS=()
1316

14-
TEST_PROJECT_MODULES=('_frobozz' '_frotz')
15-
TEST_PROJECT_MODULES_PATHS=()
16-
1717
TOTAL_NUM_MODULES=0
1818

1919
setup_test_modules() {
@@ -28,19 +28,19 @@ setup_test_modules() {
2828
fi
2929
done
3030

31-
for module in "${TEST_PLUGIN_MODULES[@]}"; do
32-
module_file="$TEST_GO_PLUGINS_DIR/${module/\///lib/}"
31+
for module in "${TEST_PROJECT_MODULES[@]}"; do
32+
module_file="$TEST_GO_SCRIPTS_DIR/lib/$module"
3333
mkdir -p "${module_file%/*}"
3434
printf '# Summary for %s\n' "$module" > "$module_file"
35-
TEST_PLUGIN_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
35+
TEST_PROJECT_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
3636
((++TOTAL_NUM_MODULES))
3737
done
3838

39-
for module in "${TEST_PROJECT_MODULES[@]}"; do
40-
module_file="$TEST_GO_SCRIPTS_DIR/lib/$module"
39+
for module in "${TEST_PLUGIN_MODULES[@]}"; do
40+
module_file="$TEST_GO_PLUGINS_DIR/${module/\///lib/}"
4141
mkdir -p "${module_file%/*}"
4242
printf '# Summary for %s\n' "$module" > "$module_file"
43-
TEST_PROJECT_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
43+
TEST_PLUGIN_MODULES_PATHS+=("${module_file#$TEST_GO_ROOTDIR/}")
4444
((++TOTAL_NUM_MODULES))
4545
done
4646
}

tests/modules/main.bats

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ get_first_and_last_core_module_summaries() {
9191
local expected=('From the core framework library:'
9292
"${CORE_MODULES[@]/#/ }"
9393
''
94-
'From the installed plugin libraries:'
95-
"${TEST_PLUGIN_MODULES[@]/#/ }"
96-
''
9794
'From the project library:'
9895
"${TEST_PROJECT_MODULES[@]/#/ }"
96+
''
97+
'From the installed plugin libraries:'
98+
"${TEST_PLUGIN_MODULES[@]/#/ }"
9999
)
100100

101101
run "$TEST_GO_SCRIPT" modules
@@ -104,8 +104,8 @@ get_first_and_last_core_module_summaries() {
104104

105105
@test "$SUITE: list using glob, all modules" {
106106
local expected=("${CORE_MODULES[@]}"
107-
"${TEST_PLUGIN_MODULES[@]}"
108107
"${TEST_PROJECT_MODULES[@]}"
108+
"${TEST_PLUGIN_MODULES[@]}"
109109
)
110110

111111
run "$TEST_GO_SCRIPT" modules '*'
@@ -138,17 +138,17 @@ get_first_and_last_core_module_summaries() {
138138
assert_output_matches " ${CORE_MODULES[0]} +${CORE_MODULES_PATHS[0]}"$'\n'
139139
assert_output_matches " $LAST_CORE_MODULE +$LAST_CORE_MODULE_PATH"$'\n\n'
140140

141+
# Note the padding is relative to only the project modules.
142+
assert_output_matches $' _frobozz scripts/lib/_frobozz\n'
143+
assert_output_matches $' _frotz scripts/lib/_frotz\n\n'
144+
141145
# Note the padding is relative to only the plugin modules. Use a variable to
142-
# keep the assertion lines under 80 columns.
146+
# keep the assertion lines under 80 columns. Bats trims the last newline of
147+
# the output.
143148
local plugins='scripts/plugins'
144149
assert_output_matches " _bar/_plugh $plugins/_bar/lib/_plugh"$'\n'
145150
assert_output_matches " _foo/_quux $plugins/_foo/lib/_quux"$'\n'
146-
assert_output_matches " _foo/_xyzzy $plugins/_foo/lib/_xyzzy"$'\n\n'
147-
148-
# Note the padding is relative to only the project modules. Bats trims
149-
# the last newline of the output.
150-
assert_output_matches $' _frobozz scripts/lib/_frobozz\n'
151-
assert_output_matches " _frotz scripts/lib/_frotz$"
151+
assert_output_matches " _foo/_xyzzy $plugins/_foo/lib/_xyzzy$"
152152

153153
# Since the 'lines' array doesn't contain blank lines, we only add '3' to
154154
# account for the 'From the...' line starting each class section.
@@ -167,15 +167,15 @@ get_first_and_last_core_module_summaries() {
167167
assert_output_matches \
168168
$'\n'"$LAST_CORE_MODULE +$LAST_CORE_MODULE_PATH"$'\n'
169169
assert_output_matches \
170-
$'\n_bar/_plugh +scripts/plugins/_bar/lib/_plugh\n'
170+
$'\n_frobozz +scripts/lib/_frobozz\n'
171171
assert_output_matches \
172-
$'\n_foo/_quux +scripts/plugins/_foo/lib/_quux\n'
172+
$'\n_frotz +scripts/lib/_frotz\n'
173173
assert_output_matches \
174-
$'\n_foo/_xyzzy +scripts/plugins/_foo/lib/_xyzzy\n'
174+
$'\n_bar/_plugh +scripts/plugins/_bar/lib/_plugh\n'
175175
assert_output_matches \
176-
$'\n_frobozz +scripts/lib/_frobozz\n'
176+
$'\n_foo/_quux +scripts/plugins/_foo/lib/_quux\n'
177177
assert_output_matches \
178-
$'\n_frotz +scripts/lib/_frotz$'
178+
$'\n_foo/_xyzzy +scripts/plugins/_foo/lib/_xyzzy$'
179179

180180
assert_equal "$TOTAL_NUM_MODULES" "${#lines[@]}"
181181
}
@@ -189,15 +189,15 @@ get_first_and_last_core_module_summaries() {
189189
assert_output_matches " ${CORE_MODULES[0]} +$FIRST_CORE_MOD_SUMMARY"$'\n'
190190
assert_output_matches " $LAST_CORE_MODULE +$LAST_CORE_MOD_SUMMARY"$'\n\n'
191191

192-
# Note the padding is relative to only the plugin modules.
193-
assert_output_matches $' _bar/_plugh Summary for _bar/_plugh\n'
194-
assert_output_matches $' _foo/_quux Summary for _foo/_quux\n'
195-
assert_output_matches $' _foo/_xyzzy Summary for _foo/_xyzzy\n\n'
192+
# Note the padding is relative to only the project modules.
193+
assert_output_matches $' _frobozz Summary for _frobozz\n'
194+
assert_output_matches $' _frotz Summary for _frotz\n'
196195

197-
# Note the padding is relative to only the project modules. Bats trims
196+
# Note the padding is relative to only the plugin modules. Bats trims
198197
# the last newline of the output.
199-
assert_output_matches $' _frobozz Summary for _frobozz\n'
200-
assert_output_matches " _frotz Summary for _frotz$"
198+
assert_output_matches $' _bar/_plugh Summary for _bar/_plugh\n'
199+
assert_output_matches $' _foo/_quux Summary for _foo/_quux\n'
200+
assert_output_matches ' _foo/_xyzzy Summary for _foo/_xyzzy$'
201201

202202
# Since the 'lines' array doesn't contain blank lines, we only add '3' to
203203
# account for the 'From the...' line starting each class section.
@@ -214,18 +214,18 @@ get_first_and_last_core_module_summaries() {
214214
get_first_and_last_core_module_summaries
215215
assert_output_matches "${CORE_MODULES[0]} +$FIRST_CORE_MOD_SUMMARY"$'\n'
216216
assert_output_matches "$LAST_CORE_MODULE +$LAST_CORE_MOD_SUMMARY"$'\n'
217+
assert_output_matches $'_frobozz +Summary for _frobozz\n'
218+
assert_output_matches $'_frotz +Summary for _frotz\n'
217219
assert_output_matches $'_bar/_plugh +Summary for _bar/_plugh\n'
218220
assert_output_matches $'_foo/_quux +Summary for _foo/_quux\n'
219-
assert_output_matches $'_foo/_xyzzy +Summary for _foo/_xyzzy\n'
220-
assert_output_matches $'_frobozz +Summary for _frobozz\n'
221-
assert_output_matches $'_frotz +Summary for _frotz$'
221+
assert_output_matches $'_foo/_xyzzy +Summary for _foo/_xyzzy$'
222222

223223
assert_equal "$TOTAL_NUM_MODULES" "${#lines[@]}"
224224
}
225225

226226
@test "$SUITE: list only test modules" {
227227
run "$TEST_GO_SCRIPT" modules '_*'
228-
assert_success "${TEST_PLUGIN_MODULES[@]}" "${TEST_PROJECT_MODULES[@]}"
228+
assert_success "${TEST_PROJECT_MODULES[@]}" "${TEST_PLUGIN_MODULES[@]}"
229229
}
230230

231231
@test "$SUITE: list only test project modules" {

0 commit comments

Comments
 (0)