Skip to content

Comments

feat: grep binary detection, awk %.6g and sorted for-in#240

Merged
chaliy merged 3 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD
Feb 24, 2026
Merged

feat: grep binary detection, awk %.6g and sorted for-in#240
chaliy merged 3 commits intomainfrom
claude/bashkit-bash-compatibility-BsDKD

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 24, 2026

Summary

  • Grep binary detection: auto-detect null bytes in content → print "Binary file X matches" instead of raw lines. Respects -a (text) and -z (null-delimited) flags
  • AWK %.6g formatting: format_awk_number() implements C's %.6g (6 significant digits, trim trailing zeros) matching real awk OFMT
  • AWK sorted for-in: deterministic iteration order — numeric keys sorted numerically, string keys lexically
  • Spec doc refresh: accurate test counts (AWK 96/96, Grep 76/76, Sed 75/75, JQ 109/114, Bash 739/744)

4 previously-skipped tests unskipped, 4 new tests added.

Test plan

  • cargo clippy --all-targets --all-features -- -D warnings clean
  • cargo test --all-features all pass
  • AWK: 96/96 pass, 0 skip (was 92/94)
  • Grep: 76/76 pass, 0 skip (was 74/75)
  • Sed: 75/75 pass, 0 skip
  • JQ: 109/114 pass, 5 skip (jaq limitations)
  • Bash: 739/744 pass, 5 skip (platform-varying output)

jaq's built-in `env` function reads from std::env::vars() which
doesn't see bashkit's virtual environment. Fix: temporarily expose
ctx.env and ctx.variables to the process environment before running
jaq, with an RAII drop guard for cleanup on all return paths.

- Unskip jq_env spec test
- Add jq_env_missing and jq_env_in_pipeline spec tests
- Add test_jq_env_access and test_jq_env_missing_var unit tests

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
Replace per-value empty inputs iterator with a shared RcIter over
all parsed JSON values.  Main loop and filter's input/inputs functions
consume from the same source, matching real jq behavior.

- Unskip jq_input and jq_inputs spec tests
- Add jq_input_with_dot, jq_inputs_empty spec tests
- Add 3 unit tests (input_reads_next, inputs_collects_remaining,
  inputs_single_value)

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
Grep:
- Auto-detect binary content (null bytes without -a/-z flags)
- Output "Binary file X matches" instead of raw lines
- Unskip grep_binary_detect, add grep_binary_with_a_flag test

AWK:
- format_awk_number(): %.6g formatting (6 sig digits, trim trailing zeros)
  matching real awk OFMT behavior
- Deterministic for-in: sort keys numerically then lexically
- Unskip awk_exp_log_func and awk_for_in_array
- Add awk_log_func and awk_for_in_string_keys tests

Update specs/009-implementation-status.md with accurate counts:
AWK 96/96, Grep 76/76, Sed 75/75, JQ 109/114, Bash 739/744

https://claude.ai/code/session_012rzB3FRw7yoQWCG1mxyW7J
@chaliy chaliy merged commit fd9a260 into main Feb 24, 2026
16 checks passed
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.

2 participants