Skip to content

fix: handle empty package lists, missing Homebrew and wrong shell - #2

Merged
batuhan-bas merged 1 commit into
mainfrom
fix/robustness
Oct 8, 2026
Merged

batuhan-bas merged 1 commit into
mainfrom
fix/robustness

Conversation

@batuhan-bas

Copy link
Copy Markdown
Owner

First PR of a series (bug fixes → descriptions from Homebrew → installed-vs-dependencies → CLI options → README + tap). It also adds tests and CI, so every following PR is covered.

Bugs fixed

Situation Before After
No casks installed empty "GUI Applications" section, total off by one section skipped, correct total
Homebrew not installed Total: 2 packages installed with empty sections brewshelf: Homebrew not found — install it from https://brew.sh, exit 1
Nothing installed empty shelf No Homebrew packages installed.
bash brewshelf.sh typeset: -g: invalid option requires zsh — run it as 'zsh brewshelf.sh'…, exit 1
1 package 1 packages 1 package

Root cause of the first two: ("${(@f)$(cmd)}") turns empty output into one empty element. Unquoted (${(f)"$(cmd)"}) drops it.

Cleanup: category_color() was defined but never called. The same mapping was duplicated inline, and the function is now used.

Tests

zsh tests/run.zsh runs the script against a fake brew (tests/bin/brew) with a PATH that excludes the real Homebrew, so results don't depend on the machine.

  • 17 checks: syntax, categories, descriptions, casks, totals, unknown packages, empty lists, missing Homebrew, wrong shell.
  • 7 of them fail on the current main, and all pass with this PR.
  • Output on a real machine (163 packages) is unchanged.

CI

GitHub Actions on macos-latest runs the tests on every PR and push to main.

- an empty `brew list` output produced a one-element array: phantom
  cask section, wrong total (e.g. "Total: 2" without Homebrew)
- exit with a clear message when Homebrew is not installed
- exit with a clear message when run with bash/sh instead of zsh
  (previously: "typeset: -g: invalid option")
- print "No Homebrew packages installed." instead of an empty shelf
- "1 package" instead of "1 packages"
- reuse category_color() instead of a duplicated case statement

Tests: tests/run.zsh runs the script against a fake brew
(tests/bin/brew) — 17 checks, 7 of them fail on the previous version.
CI runs them on macOS.
@batuhan-bas batuhan-bas self-assigned this Oct 8, 2026
@batuhan-bas
batuhan-bas merged commit cafcf84 into main Oct 8, 2026
1 check passed
@batuhan-bas
batuhan-bas deleted the fix/robustness branch October 8, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant