Skip to content

Implement POSIX test and [ builtin commands#18

Closed
AlexandreYang wants to merge 1 commit intomainfrom
dd/implement-posix-test-and-bracket-commands
Closed

Implement POSIX test and [ builtin commands#18
AlexandreYang wants to merge 1 commit intomainfrom
dd/implement-posix-test-and-bracket-commands

Conversation

@AlexandreYang
Copy link
Copy Markdown
Member

What does this PR do?

Implements the POSIX test and [ builtin commands for conditional expression evaluation. These commands evaluate expressions and exit with status 0 (true) or 1 (false), supporting string comparisons, integer comparisons, file tests, and logical operators.

Motivation

The test and [ commands are fundamental POSIX shell builtins used throughout shell scripts for conditional logic. This implementation enables proper shell script compatibility and enables control flow constructs like if [ -f file ] to work correctly.

Testing

  • Added comprehensive test suites covering:
    • String operators (-n, -z, =, !=, <, >)
    • Integer comparison operators (-eq, -ne, -gt, -ge, -lt, -le)
    • File test operators (-e, -f, -d, -s, -r, -w, -x, -L, -h, -nt, -ot, -ef)
    • Logical operators (!, -a, -o)
    • Parenthesized expressions for grouping
    • Bracket syntax ([ EXPR ])
    • Error cases (invalid integers, syntax errors, missing brackets)
    • GNU coreutils compatibility tests
    • Penetration testing edge cases (overflow, path traversal, nested expressions)
    • Unix-specific tests (symlinks, special files, permissions)
  • Added scenario tests covering typical use cases
  • All tests pass with proper exit codes and error messages

Checklist

  • Tests added/updated
  • Documentation updated (SHELL_COMMANDS.md)

PR by Bits
View session in Datadog

Comment @DataDog to request changes

Co-authored-by: AlexandreYang <49917914+AlexandreYang@users.noreply.github.com>
@datadog-prod-us1-5
Copy link
Copy Markdown
Contributor

datadog-prod-us1-5 Bot commented Mar 10, 2026

View session in Datadog

Bits Dev status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

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