Skip to content

refactor(compat): replace [[ with [ ] for Bash 3.0+#610

Open
Chemaclass wants to merge 7 commits intomainfrom
refactor/bash3-compat-replace-double-brackets
Open

refactor(compat): replace [[ with [ ] for Bash 3.0+#610
Chemaclass wants to merge 7 commits intomainfrom
refactor/bash3-compat-replace-double-brackets

Conversation

@Chemaclass
Copy link
Member

Summary

  • Replace all ~410 [[ ]] test constructs across 28 source files with Bash 3.0+ compatible alternatives
  • [[ ]][ ] for simple tests, [ = ] for equality, grep -qE / sed for regex, case for glob matching
  • Compound conditions split from [[ A || B ]] to [ A ] || [ B ]

Test plan

  • All 910 tests pass (0 failures)
  • ShellCheck static analysis passes
  • EditorConfig lint passes
  • Pre-commit hooks pass
  • No [[ test constructs remaining in src/ (only inside regex patterns/grep/sed)

Replace all ~410 [[ ]] test constructs across 28 source files with
Bash 3.0+ compatible alternatives to ensure the framework works on
macOS default bash and older systems.

Replacements applied:
- [[ ]] → [ ] for simple tests (-f, -n, -z, -eq, -gt, etc.)
- [[ == ]] → [ = ] for string equality
- [[ =~ ]] → grep -qE / sed extraction for regex matching
- [[ == pattern* ]] → case statements for glob matching
- Compound [[ A || B ]] → [ A ] || [ B ]
- Compound [[ A && B ]] → [ A ] && [ B ]
@github-actions
Copy link
Contributor

✅ Contributor Report

User: @Chemaclass
Status: Trusted contributor (whitelisted)

This user is on the trusted contributors list and was automatically approved.

@Chemaclass Chemaclass self-assigned this Mar 16, 2026
In Bash 3.0, `command -v` prints errors to stderr for missing commands
unlike modern bash which is silent. Redirect stderr to /dev/null.
- Remove useless echo wrapping command -v output (SC2005)
- Quote variables in [ ] tests to prevent word splitting (SC2086)
- Suppress SC2001 for sed with backreferences (not replaceable by ${//})
- Replace inline `if case ... esac; then` patterns that may cause
  parse errors in unpatched Bash 3.0.0 with separate case + if
- Consolidate multiple single-pattern case statements into one
- Fix shfmt formatting while preserving editorconfig line limits
@Chemaclass Chemaclass force-pushed the refactor/bash3-compat-replace-double-brackets branch from bac86f7 to eca6361 Compare March 17, 2026 08:45
@Chemaclass Chemaclass force-pushed the refactor/bash3-compat-replace-double-brackets branch 3 times, most recently from 18cb87b to e19ca2b Compare March 17, 2026 09:38
In unpatched Bash 3.0.0, `return` in a sourced file inside a for loop
may not properly return from the source. Use if/else guard to prevent
test function definitions when running under Bash 3.0.

Also revert debug CI workflow changes.
@Chemaclass Chemaclass force-pushed the refactor/bash3-compat-replace-double-brackets branch from e19ca2b to 0fffb35 Compare March 17, 2026 09:46
The fixed filename temp_test_cases.txt caused race conditions when
running tests in parallel mode, leading to "No such file or directory"
errors when multiple subprocesses accessed the same file.
@Chemaclass Chemaclass force-pushed the refactor/bash3-compat-replace-double-brackets branch from f46a3b9 to 0989925 Compare March 17, 2026 10:13
Use explicit git -C $SANDBOX_DIR for all git operations instead of
relying on cd, and add --allow-empty to ensure the initial commit
always succeeds regardless of git version or configuration.
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