Skip to content

Testing — Menu-Driven CLI App

Test the CLI commands first, then the interactive menu.

CLI Commands

Add Tasks

cd ~/projects/taskman
bash taskman.sh add "Buy milk" --priority high
bash taskman.sh add "Write readme"
bash taskman.sh add "Clean desk" --priority low
[OK] Task added: #1 Buy milk [high] [OK] Task added: #2 Write readme [normal] [OK] Task added: #3 Clean desk [low]

List Tasks

bash taskman.sh list
ID Status Priority Task ---- ------ -------- ---- 1 ○ high Buy milk 2 ○ normal Write readme 3 ○ low Clean desk

Mark Done

bash taskman.sh done 1
bash taskman.sh list
[OK] Task #1 marked done ID Status Priority Task ---- ------ -------- ---- 1 ✓ high Buy milk 2 ○ normal Write readme 3 ○ low Clean desk

Delete a Task

bash taskman.sh delete 3
bash taskman.sh list
[OK] Task #3 deleted ID Status Priority Task ---- ------ -------- ---- 1 ✓ high Buy milk 2 ○ normal Write readme

Test Edge Cases

Add Without Description — Should Prompt

echo "Prompted task" | bash taskman.sh add
Task description: [OK] Task added: #4 Prompted task [normal]

Invalid Priority

bash taskman.sh add "Test" --priority urgent
echo "Exit: $?"
Error: priority must be low, normal, or high Exit: 1

Done on Non-Existent ID

bash taskman.sh done 999
echo "Exit: $?"
Error: task #999 not found Exit: 1

Empty Task Description

echo "" | bash taskman.sh add
echo "Exit: $?"
Task description: Error: description cannot be empty Exit: 1

Verify Database File

cat tasks.db
1:done:high:Buy milk 2:pending:normal:Write readme 4:pending:normal:Prompted task

IDs are never reused — ID 3 is gone, IDs are sequential from the max.

Test SHOW_DONE Setting

# Hide done tasks
SHOW_DONE=false bash taskman.sh list
ID Status Priority Task ---- ------ -------- ---- 2 ○ normal Write readme 4 ○ normal Prompted task

Test Piped Output (No Colors)

# When piped, ANSI codes should NOT appear
bash taskman.sh list | cat | grep -c '\033'
0

Interactive Menu Test (Manual)

bash taskman.sh

Navigate through the menu manually: 1. Select 1 to list tasks 2. Select 2 to add a task 3. Enter "Interactive task" as description 4. Select 6 to quit

Verify the new task appears in tasks.db.

Checklist

□ add creates a task with the correct ID, status, and priority □ list shows all tasks in a formatted table □ done marks the correct task (verified in tasks.db) □ delete removes the task (ID not reused) □ SHOW_DONE=false hides completed tasks □ Invalid priority returns exit code 1 with clear message □ Non-existent ID for done/delete returns exit code 1 □ Colors absent when output is piped □ Interactive menu reaches all commands □ shellcheck taskman.sh returns 0 warnings

implementation | enhancements