File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 6868# @go modules --imported
6969
7070declare __go_module_name
71+ declare __go_module_file
7172declare __go_loaded_module
7273
7374for __go_module_name in " $@ " ; do
@@ -77,17 +78,30 @@ for __go_module_name in "$@"; do
7778 fi
7879 done
7980
80- # Prevent self- and circular importing.
81+ # Prevent self- and circular importing by registering name before sourcing .
8182 _GO_IMPORTED_MODULES+=(" $__go_module_name " )
83+ __go_module_file=" $_GO_CORE_DIR /lib/$__go_module_name "
8284
83- # Convert <plugin>/<module> to _GO_SCRIPTS_DIR/plugins/<plugin>/lib/<module>
84- if ! . " $_GO_CORE_DIR /lib/$__go_module_name " 2> /dev/null &&
85- ! . " $_GO_SCRIPTS_DIR /plugins/${__go_module_name/ \/ // lib/ } " 2> /dev/null &&
86- ! . " $_GO_SCRIPTS_DIR /lib/$__go_module_name " 2> /dev/null; then
87- @go.printf " ERROR: Unknown module: $__go_module_name " >&2
85+ if [[ ! -f " $__go_module_file " ]]; then
86+ # Convert <plugin>/<module> to plugins/<plugin>/lib/<module>
87+ __go_module_file=" $_GO_SCRIPTS_DIR /plugins/${__go_module_name/ \/ // lib/ } "
88+
89+ if [[ ! -f " $__go_module_file " ]]; then
90+ __go_module_file=" $_GO_SCRIPTS_DIR /lib/$__go_module_name "
91+
92+ if [[ ! -f " $__go_module_file " ]]; then
93+ @go.printf " ERROR: Unknown module: $__go_module_name \n" >&2
94+ exit 1
95+ fi
96+ fi
97+ fi
98+
99+ if ! . " $__go_module_file " ; then
100+ @go.printf " ERROR: Module import failed for: $__go_module_file \n" >&2
88101 exit 1
89102 fi
90103done
91104
92105unset __go_loaded_module
106+ unset __go_module_file
93107unset __go_module_name
Original file line number Diff line number Diff line change 4343# 'f*/' All modules in all plugins that begin with 'f'
4444# 'f*/b*' Modules beginning with 'b' in all plugins that begin with 'f'
4545#
46- # For detailed information about the module system, run `{{go}} {{cmd}} help`
46+ # For detailed information about the module system, run `{{go}} {{cmd}} -- help`
4747# without a `<module-name>` argument.
4848
4949_@go.modules_help () {
Original file line number Diff line number Diff line change @@ -71,3 +71,14 @@ teardown() {
7171 local IFS=$' \n '
7272 assert_success " ${EXPECTED[*]} "
7373}
74+
75+ @test " $SUITE : error if module contains errors" {
76+ echo " This is a totally broken module." >> " ${TEST_MODULES[1]} "
77+ run " $TEST_GO_SCRIPT " " ${IMPORTS[@]} "
78+
79+ local expected=(" ${IMPORTS[0]##*/ } loaded"
80+ " ${TEST_MODULES[1]} : line 2: This: command not found"
81+ " ERROR: Module import failed for: ${TEST_MODULES[1]} " )
82+ local IFS=$' \n '
83+ assert_failure " ${expected[*]} "
84+ }
You can’t perform that action at this time.
0 commit comments