Skip to content

Commit 554f3e2

Browse files
authored
Merge pull request #514 from TypedDevs/feat/add-learn-mode-and-common-patterns
Add learn mode and common patterns
2 parents 92cacd6 + 003fb32 commit 554f3e2

12 files changed

Lines changed: 2007 additions & 3 deletions

.github/workflows/static_analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
- name: Run ShellCheck
2525
uses: ludeeus/action-shellcheck@master
2626
env:
27-
SHELLCHECK_OPTS: -e SC1091 -e SC2155
27+
SHELLCHECK_OPTS: -e SC1091 -e SC2155 -e SC2016
2828

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Added
6+
- Add `--learn` interactive tutorial with 10 progressive lessons for hands-on learning
7+
- Add comprehensive "Common Patterns" documentation with real-world testing examples
8+
9+
### Fixed
510
- Pass arguments to mocked functions
611
- Fix lifecycle hooks not catching failing commands (exit code errors)
712

bashunit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ source "$BASHUNIT_ROOT_DIR/src/reports.sh"
5656
source "$BASHUNIT_ROOT_DIR/src/runner.sh"
5757
source "$BASHUNIT_ROOT_DIR/src/bashunit.sh"
5858
source "$BASHUNIT_ROOT_DIR/src/init.sh"
59+
source "$BASHUNIT_ROOT_DIR/src/learn.sh"
5960
source "$BASHUNIT_ROOT_DIR/src/main.sh"
6061

6162
_ASSERT_FN=""
@@ -141,6 +142,10 @@ while [[ $# -gt 0 ]]; do
141142
fi
142143
trap '' EXIT && exit 0
143144
;;
145+
--learn)
146+
learn::start
147+
trap '' EXIT && exit 0
148+
;;
144149
-h|--help)
145150
console_header::print_help
146151
trap '' EXIT && exit 0

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function build::dependencies() {
104104
"src/reports.sh"
105105
"src/runner.sh"
106106
"src/init.sh"
107+
"src/learn.sh"
107108
"src/bashunit.sh"
108109
"src/main.sh"
109110
)

docs/.vitepress/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export default defineConfig({
8787
}, {
8888
text: 'Custom asserts',
8989
link: '/custom-asserts'
90+
}, {
91+
text: 'Common patterns',
92+
link: '/common-patterns',
9093
}, {
9194
text: 'Examples',
9295
link: '/examples'

docs/command-line.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,58 @@ When a custom directory is used, bashunit writes `BASHUNIT_BOOTSTRAP=<dir>/boots
399399
```
400400
:::
401401

402+
## Learn
403+
404+
> `bashunit --learn`
405+
406+
Starts an interactive learning tutorial that teaches you how to use bashunit step by step through hands-on exercises.
407+
408+
The tutorial covers:
409+
- Writing your first test
410+
- Using different assertions
411+
- Setup and teardown functions
412+
- Testing functions and scripts
413+
- Mocking external dependencies
414+
- Using spies to verify calls
415+
- Parameterized testing with data providers
416+
- Testing exit codes
417+
- A complete real-world challenge
418+
419+
Your progress is saved automatically, and you can resume at any time.
420+
421+
::: code-group
422+
```bash [Example]
423+
./bashunit --learn
424+
```
425+
```[Output]
426+
bashunit - Interactive Learning
427+
428+
Choose a lesson:
429+
430+
1. Basics - Your First Test
431+
2. Assertions - Testing Different Conditions
432+
3. Setup & Teardown - Managing Test Lifecycle
433+
4. Testing Functions - Unit Testing Patterns
434+
5. Testing Scripts - Integration Testing
435+
6. Mocking - Test Doubles and Mocks
436+
7. Spies - Verifying Function Calls
437+
8. Data Providers - Parameterized Tests
438+
9. Exit Codes - Testing Success and Failure
439+
10. Complete Challenge - Real World Scenario
440+
441+
p. Show Progress
442+
r. Reset Progress
443+
q. Quit
444+
445+
Enter your choice:
446+
```
447+
:::
448+
449+
::: tip
450+
The learn mode is perfect for new users getting started with bashunit.
451+
It provides practical, hands-on experience with immediate feedback.
452+
:::
453+
402454
## Help
403455

404456
> `bashunit --help`

0 commit comments

Comments
 (0)