As you will read below I have a workaround for setup of my module system before testing so this is a non-blocking issue for me for adoption.
BUT.....I did a bit of digging into bashunit and have some suggestions for improvement to make it more flexible to what a dev might need in the way of setup/environment/shell. In general one likes a "clean" environment/shell to do testing but the "ecosystem" might be critical to doing testing.
You can have the "sensible" default be "isolation" (i.e. new non-interactive, non-login shell with clean environment) but allowing flexibility would be again beneficial to adoption.
13. Bootstrap and Environment Issues
Status: Working solution implemented, but bashunit limitations identified
The Problem
Bashunit creates a clean, non-interactive shell for test execution. This causes issues for ucisms because:
- Non-interactive shell = ucisms not auto-loaded (only happens in interactive shells via
.bashrc) - Bootstrap file cannot receive arguments = Cannot tell bootstrap which module to test
- Tests run in subshells = Need proper export of functions/variables
How Bashunit Bootstrap Works
From source code analysis (src/main.sh lines 135-153):
# Optional bootstrap# shellcheck disable=SC1090
[[ -f"${BASHUNIT_BOOTSTRAP:-}" ]] &&source"$BASHUNIT_BOOTSTRAP"# Then later, tests executeset +euo pipefail
bashunit::main::exec_tests "$filter""${args[@]}"From src/runner.sh lines 389-418:
# Each test function runs in a subshell:
(
# Run set_up
bashunit::runner::run_set_up "$test_file"# Apply shell mode settingif bashunit::env::is_strict_mode_enabled;thenset -euo pipefail
elseset +euo pipefail
fi"$fn_name""$@"2>&1# ← Test runs here
)
Key Findings:
- Bootstrap sourced ONCE in main bashunit shell (line 142)
- Bootstrap runs BEFORE any test execution
- Tests run in subshells - each isolated
- Only exported variables/functions available to test subshells
Current Working Solution
Use environment variable to pass module name:
# In testing.mod:export TESTING_MODULE=$module bashunit test"$test_location" --env $bootstrap_file
# In test-bootstrap.sh:#!/usr/bin/env bash# Source ucisms (handles non-interactive shell)ifcommand -v ucisms &>/dev/null;thensource ucisms
# Load the module being tested
module_load -r $TESTING_MODULEelseecho"[ERROR] ucisms not found in PATH">&2exit 1
fi
Why this works:
- Environment variables (
$TESTING_MODULE) persist to subshells module_load exports functions making them available to tests- Bootstrap runs once, making module available to all tests
What Works
✅ Environment variables exported before bashunit runs
✅ source ucisms in bootstrap (ucisms in PATH)
✅ module_load -r $MODULE loads module fresh
✅ Exported functions available in test subshells
✅ setup() and teardown() hooks work correctly
What Doesn't Work
❌ Bootstrap file cannot receive arguments
❌ Cannot pass module name directly to bootstrap
❌ No option to inherit current shell environment
❌ Functions defined in bootstrap without export aren't visible
Recommendations for Bashunit
ISSUE #1: Bootstrap Argument Passing
Bootstrap file cannot receive arguments. Suggest one of:
Option A: Shell-style argument passing
# Current limitation:
bashunit test --env bootstrap.sh tests/
# Desired (like bash -c):
bashunit test --env "bootstrap.sh logger" tests/
Option B: Separate flag for bootstrap arguments
bashunit test --env bootstrap.sh --env-args "logger" tests/
Rationale:
- Common pattern: bootstrap needs to know what's being tested
- Avoids global environment variable workaround
- More explicit and testable
ISSUE #2: Environment Inheritance Option
Provide flag to inherit current shell environment:
# Similar to sudo -E (preserve environment):
bashunit test --preserve-env tests/
# OR
bashunit test --inherit-environment tests/
Rationale:
- Some tests want clean environment (current behavior)
- Some tests want to test in current context
- User should choose (like
sudo -E does)
ISSUE #3: Login Shell Option
Provide flag to run tests in a login shell:
# Run tests in login shell (sources profile, etc.):
bashunit test --login tests/
# OR
bashunit test -l tests/
Rationale:
- Login shells source
/etc/profile, ~/.bash_profile, etc. - Some environments/tools only available in login shells
- Developers may want to test with their full login environment
- Not necessary for ucisms (uses non-interactive sourcing)
- Useful for testing user profile configurations
ISSUE #4: Documentation Clarity
Document that:
- Bootstrap runs in main shell ONCE (not per-test)
- Tests run in isolated subshells
- Only exported variables/functions visible to tests
- Use
export for cross-test availability - Tests run in non-interactive, non-login shell by default
Rationale:
- Common source of confusion
- Not obvious from current docs
- Helps users understand bootstrap scope
- Explains why profile scripts don't run
Current Status
✅ WORKING - Environment variable solution is functional
Limitations accepted:
- Must use
$TESTING_MODULE environment variable - Cannot pass arguments directly to bootstrap
- Requires explicit export of functions/variables
Next Actions:
As you will read below I have a workaround for setup of my module system before testing so this is a non-blocking issue for me for adoption.
BUT.....I did a bit of digging into bashunit and have some suggestions for improvement to make it more flexible to what a dev might need in the way of setup/environment/shell. In general one likes a "clean" environment/shell to do testing but the "ecosystem" might be critical to doing testing.
You can have the "sensible" default be "isolation" (i.e. new non-interactive, non-login shell with clean environment) but allowing flexibility would be again beneficial to adoption.
13. Bootstrap and Environment Issues
Status: Working solution implemented, but bashunit limitations identified
The Problem
Bashunit creates a clean, non-interactive shell for test execution. This causes issues for ucisms because:
.bashrc)How Bashunit Bootstrap Works
From source code analysis (
src/main.shlines 135-153):From
src/runner.shlines 389-418:Key Findings:
Current Working Solution
Use environment variable to pass module name:
Why this works:
$TESTING_MODULE) persist to subshellsmodule_loadexports functions making them available to testsWhat Works
✅ Environment variables exported before bashunit runs
✅
source ucismsin bootstrap (ucisms in PATH)✅
module_load -r $MODULEloads module fresh✅ Exported functions available in test subshells
✅
setup()andteardown()hooks work correctlyWhat Doesn't Work
❌ Bootstrap file cannot receive arguments
❌ Cannot pass module name directly to bootstrap
❌ No option to inherit current shell environment
❌ Functions defined in bootstrap without export aren't visible
Recommendations for Bashunit
ISSUE #1: Bootstrap Argument Passing
Bootstrap file cannot receive arguments. Suggest one of:
Option A: Shell-style argument passing
Option B: Separate flag for bootstrap arguments
Rationale:
ISSUE #2: Environment Inheritance Option
Provide flag to inherit current shell environment:
Rationale:
sudo -Edoes)ISSUE #3: Login Shell Option
Provide flag to run tests in a login shell:
Rationale:
/etc/profile,~/.bash_profile, etc.ISSUE #4: Documentation Clarity
Document that:
exportfor cross-test availabilityRationale:
Current Status
✅ WORKING - Environment variable solution is functional
Limitations accepted:
$TESTING_MODULEenvironment variableNext Actions: