Skip to content

Commit e926822

Browse files
chaliyclaude
andauthored
fix(bash): glob pattern matching in [[ == ]] and [[ != ]] (#244)
## Summary - `[[ ]]` conditional now uses glob matching (*, ?, [...]) for `==` and `!=` operators - Previously did exact string comparison, causing `[[ "hello.txt" == *.txt ]]` to fail - Leverages existing `pattern_matches()` method ## Test plan - [x] 7 new tests: star, question, prefix, suffix, negation, no-match, exact - [x] `cargo test --all-features` passes - [x] `cargo clippy` and `cargo fmt` clean Co-authored-by: Claude <noreply@anthropic.com>
1 parent 97c5434 commit e926822

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

crates/bashkit/src/interpreter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,8 @@ impl Interpreter {
959959
3 => {
960960
// Binary operators
961961
match args[1].as_str() {
962-
"=" | "==" => args[0] == args[2],
963-
"!=" => args[0] != args[2],
962+
"=" | "==" => self.pattern_matches(&args[0], &args[2]),
963+
"!=" => !self.pattern_matches(&args[0], &args[2]),
964964
"<" => args[0] < args[2],
965965
">" => args[0] > args[2],
966966
"-eq" => {

crates/bashkit/tests/spec_cases/bash/conditional.test.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,52 @@ echo $?
118118
### expect
119119
1
120120
### end
121+
122+
### cond_glob_star
123+
# [[ == ]] with * glob pattern
124+
[[ "hello.txt" == *.txt ]] && echo match || echo no
125+
### expect
126+
match
127+
### end
128+
129+
### cond_glob_star_no_match
130+
# [[ == ]] glob * doesn't match wrong extension
131+
[[ "hello.txt" == *.log ]] && echo match || echo no
132+
### expect
133+
no
134+
### end
135+
136+
### cond_glob_question
137+
# [[ == ]] with ? single-char glob
138+
[[ "abc" == ?b? ]] && echo match || echo no
139+
### expect
140+
match
141+
### end
142+
143+
### cond_glob_prefix
144+
# [[ == ]] with prefix glob
145+
[[ "hello_world" == hello* ]] && echo match || echo no
146+
### expect
147+
match
148+
### end
149+
150+
### cond_glob_suffix
151+
# [[ == ]] with suffix glob
152+
[[ "test_file" == *_file ]] && echo match || echo no
153+
### expect
154+
match
155+
### end
156+
157+
### cond_glob_not_equal
158+
# [[ != ]] with glob pattern
159+
[[ "hello.txt" != *.log ]] && echo diff || echo same
160+
### expect
161+
diff
162+
### end
163+
164+
### cond_exact_match_no_glob
165+
# [[ == ]] exact match with no glob chars
166+
[[ "hello" == "hello" ]] && echo yes || echo no
167+
### expect
168+
yes
169+
### end

specs/009-implementation-status.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ Bashkit implements IEEE 1003.1-2024 Shell Command Language. See
103103

104104
## Spec Test Coverage
105105

106-
**Total spec test cases:** 1174 (1169 pass, 5 skip)
106+
**Total spec test cases:** 1181 (1176 pass, 5 skip)
107107

108108
| Category | Cases | In CI | Pass | Skip | Notes |
109109
|----------|-------|-------|------|------|-------|
110-
| Bash (core) | 813 | Yes | 808 | 5 | `bash_spec_tests` in CI |
110+
| Bash (core) | 820 | Yes | 815 | 5 | `bash_spec_tests` in CI |
111111
| AWK | 96 | Yes | 96 | 0 | loops, arrays, -v, ternary, field assign, getline, %.6g |
112112
| Grep | 76 | Yes | 76 | 0 | -z, -r, -a, -b, -H, -h, -f, -P, --include, --exclude, binary detect |
113113
| Sed | 75 | Yes | 75 | 0 | hold space, change, regex ranges, -E |
114114
| JQ | 114 | Yes | 114 | 0 | reduce, walk, regex funcs, --arg/--argjson, combined flags, input/inputs, env |
115-
| **Total** | **1174** | **Yes** | **1169** | **5** | |
115+
| **Total** | **1181** | **Yes** | **1176** | **5** | |
116116

117117
### Bash Spec Tests Breakdown
118118

@@ -126,7 +126,7 @@ Bashkit implements IEEE 1003.1-2024 Shell Command Language. See
126126
| column.test.sh | 10 | column alignment |
127127
| command.test.sh | 9 | `command -v`, `-V`, function bypass |
128128
| command-not-found.test.sh | 17 | unknown command handling |
129-
| conditional.test.sh | 17 | `[[ ]]` conditionals, `=~` regex, BASH_REMATCH |
129+
| conditional.test.sh | 24 | `[[ ]]` conditionals, `=~` regex, BASH_REMATCH, glob `==`/`!=` |
130130
| command-subst.test.sh | 14 | includes backtick substitution (1 skipped) |
131131
| control-flow.test.sh | 43 | if/elif/else, for, while, case, trap ERR, `[[ =~ ]]` BASH_REMATCH |
132132
| cuttr.test.sh | 32 | cut and tr commands, `-z` zero-terminated |

0 commit comments

Comments
 (0)