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

Nested source commands inside scripts under testing #306

Open
OleksandrKucherenko opened this issue Oct 4, 2023 · 0 comments
Open

Nested source commands inside scripts under testing #306

OleksandrKucherenko opened this issue Oct 4, 2023 · 0 comments

Comments

@OleksandrKucherenko
Copy link

Hi,

I try to write tests for my scripts - https://github.com/OleksandrKucherenko/e-bash

I have a situation when I rely on the chain of loading commands, when one of the scripts load/source the source of another and after that works with declared functions.

# file _commonns.sh

# shellcheck disable=SC1090  source=_colors.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_colors.sh"

# shellcheck disable=SC1090 source=_logger.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_logger.sh"
logger common "$@" # register own logger

in last line from code fragment I try to use function that is declared inside the _logger.sh file, and shellspec gives me the error:

.scripts/_commons.sh: line 21: pop_var_context: head of shell_variables not a function context

Unexpected output to stderr occurred at line 1-9 in 'spec/commons_spec.sh'

if I comment the logger line, everything is working. I understand that is possible to override the logic, but I need to understand why the nested source calls does not work as expected. Can it be fixed? maybe provided some kind of flag that will force the loading of the sub-script?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant