How typeddevs/bashunit works
Primary Components
• Command-Line Interface (CLI): The main entry point is in scripts like src/main.sh and bin/pre-commit.
• Core Testing Engine: This includes the test runner (src/runner.sh), which discovers and executes tests, along with modules for parallel testing (src/parallel.sh) and state management (src/state.sh).
• Assertions Library: A collection of assertion scripts (src/assert.sh, src/assertions.sh, src/assert_arrays.sh, etc.) which are the core of the framework’s testing capabilities.
• Reporting & Output: Components handling output and reporting (src/console_results.sh, src/console_header.sh, src/reports.sh) that format the results and possibly generate JUnit/HTML reports.
• Configuration & Environment: The project includes configuration examples (.env.example, Makefile, install.sh) and possibly uses the .github workflows for CI/CD automation.
• Documentation & Community Resources: The docs/ directory maintains the official documentation (powered by VitePress), examples, and blog posts, and the README outlines project information.
• Testing of the Framework: The tests directory is organized into unit, functional, and acceptance tests, which show how the framework’s different parts interact and validate each other.
Relationships and Interactions
• The CLI receives user commands which forward to src/main.sh.
• The main script then invokes the test runner (src/runner.sh), which discovers tests (from the tests directory) and sequentially or in parallel orchestrates the test execution.
• During test execution, various assertion scripts (e.g., src/assert.sh) are called to perform validations.
• Utility scripts assist in formatting output and handling some OS/environment checks (e.g., src/check_os.sh, src/env.sh).
• Feedback (results and reports) flows from the testing engine to reporting components, which then output to the terminal or generate HTML/JUnit reports.
• CI/CD and quality controls are managed by GitHub workflows (.github/workflows) and static analysis/linter tools, ensuring that changes follow coding standards.
Architectural Patterns and Design Principles
• Modular Design: Each functionality is separated into its own script (e.g., separate assertion scripts, utility scripts, etc.), emphasizing reusability and clarity.
• Layered Command Structure: There is a clear separation between the entry point, the business logic (test running and assertions), and the reporting/utility layers.
• Testing Hierarchy: The project itself is built with a rigorous internal testing structure (unit, functional, acceptance tests) to maintain robustness.
• Extensibility: With hundreds of assertions and functionalities like mocks, spies, and providers, the framework’s design is built for both ease-of-use and extension.