Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve import lib feedback on error #64

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion import_norlab_shell_script_tools_lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function n2st::source_lib(){

if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
# This script is being run, ie: __name__="__main__"
echo "${MSG_ERROR_FORMAT}[ERROR]${MSG_END_FORMAT} This script must be sourced from an other script"
echo -e "${MSG_ERROR_FORMAT}[ERROR]${MSG_END_FORMAT} This script must be sourced i.e.: $ source $( basename "$0" )" 1>&2
exit 1
else
# This script is being sourced, ie: __name__="__source__"
n2st::source_lib
Expand Down
4 changes: 2 additions & 2 deletions tests/test_import_lib.bats
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ teardown() {

@test "run \"bash $TESTED_FILE\" › expect fail" {
run bash "$TESTED_FILE"
assert_success
assert_output --partial "This script must be sourced from an other script"
assert_failure
assert_output --regexp "[ERROR]".*"This script must be sourced i.e.:".*"source".*"$TESTED_FILE"
}