modules: Switch from declare
to readonly, export
#44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Encountered in the course of implementing #36. While writing the upcoming
@go.log_add_output_file
function in thelog
module, which includes a call to. "$_GO_USE_MODULES" 'file'
, a test that made multiple calls to this new function would fail with the message:This error message is part of
@go.open_file_or_duplicate_fd
, and includes a reference to$_GO_MAX_FILE_DESCRIPTORS
, which was previously declared as:The fact that no value appeared for "$_GO_MAX_FILE_DESCRIPTORS" was suspicous. Moving the
. "$_GO_USE_MODULES" 'file'
call outside of the function to the top level of the module got the test to pass; I understood this to be because:declare
statements cause variables to be scoped to thefunction sourcing the file.
these variables aren't redeclared for subsequent calls.
After deciding that it should be permissible for a function to call
. "$_GO_USE_MODULES"
and have it work across multiple calls, I eventually learned that substituingreadonly
fordeclare -r
did what I originally intended. The same also holds forexport
vsdeclare
ordeclare -x
. Making these updates to thefile
module allowed the test to pass; only minor changes were required to other tests when applying the updates to every module.For now, this update applies only to module code. I may look into how to apply
readonly
andexport
to other code as well, but an initial experiment with replacing values ingo-core.bash
caused./go test vars
to fail.