Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,13 +2431,30 @@ impl Interpreter {
positional: args.clone(),
});

// Set FUNCNAME array from call stack (index 0 = current, 1 = caller, ...)
let funcname_arr: HashMap<usize, String> = self
.call_stack
.iter()
.rev()
.enumerate()
.map(|(i, f)| (i, f.name.clone()))
.collect();
let prev_funcname = self.arrays.insert("FUNCNAME".to_string(), funcname_arr);

// Execute function body
let mut result = self.execute_command(&func_def.body).await?;

// Pop call frame and function counter
self.call_stack.pop();
self.counters.pop_function();

// Restore previous FUNCNAME (or set from remaining stack)
if self.call_stack.is_empty() {
self.arrays.remove("FUNCNAME");
} else if let Some(prev) = prev_funcname {
self.arrays.insert("FUNCNAME".to_string(), prev);
}

// Handle return - convert Return control flow to exit code
if let ControlFlow::Return(code) = result.control_flow {
result.exit_code = code;
Expand Down
44 changes: 44 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/functions.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,47 @@ echo "after outer: $x"
in outer: local_val
after outer: global
### end

### func_funcname_basic
# FUNCNAME[0] is current function name
myfunc() { echo "${FUNCNAME[0]}"; }
myfunc
### expect
myfunc
### end

### func_funcname_call_stack
# FUNCNAME array reflects call stack
inner() { echo "${FUNCNAME[@]}"; }
outer() { inner; }
outer
### expect
inner outer
### end

### func_funcname_depth
# FUNCNAME array length matches nesting depth
a() { echo "${#FUNCNAME[@]}"; }
b() { a; }
c() { b; }
c
### expect
3
### end

### func_funcname_empty_outside
# FUNCNAME is empty outside functions
echo "${#FUNCNAME[@]}"
### expect
0
### end

### func_funcname_restored
# FUNCNAME is cleared after function returns
f() { echo "in: ${FUNCNAME[0]}"; }
f
echo "out: ${#FUNCNAME[@]}"
### expect
in: f
out: 0
### end
8 changes: 4 additions & 4 deletions specs/009-implementation-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ Bashkit implements IEEE 1003.1-2024 Shell Command Language. See

## Spec Test Coverage

**Total spec test cases:** 1199 (1194 pass, 5 skip)
**Total spec test cases:** 1204 (1199 pass, 5 skip)

| Category | Cases | In CI | Pass | Skip | Notes |
|----------|-------|-------|------|------|-------|
| Bash (core) | 838 | Yes | 833 | 5 | `bash_spec_tests` in CI |
| Bash (core) | 843 | Yes | 838 | 5 | `bash_spec_tests` in CI |
| AWK | 96 | Yes | 96 | 0 | loops, arrays, -v, ternary, field assign, getline, %.6g |
| Grep | 76 | Yes | 76 | 0 | -z, -r, -a, -b, -H, -h, -f, -P, --include, --exclude, binary detect |
| Sed | 75 | Yes | 75 | 0 | hold space, change, regex ranges, -E |
| JQ | 114 | Yes | 114 | 0 | reduce, walk, regex funcs, --arg/--argjson, combined flags, input/inputs, env |
| **Total** | **1199** | **Yes** | **1194** | **5** | |
| **Total** | **1204** | **Yes** | **1199** | **5** | |

### Bash Spec Tests Breakdown

Expand All @@ -136,7 +136,7 @@ Bashkit implements IEEE 1003.1-2024 Shell Command Language. See
| errexit.test.sh | 8 | set -e tests |
| fileops.test.sh | 21 | |
| find.test.sh | 10 | file search |
| functions.test.sh | 17 | local dynamic scoping, nested writes |
| functions.test.sh | 22 | local dynamic scoping, nested writes, FUNCNAME call stack |
| getopts.test.sh | 9 | POSIX option parsing, combined flags, silent mode |
| globs.test.sh | 12 | for-loop glob expansion, recursive `**` |
| headtail.test.sh | 14 | |
Expand Down
4 changes: 4 additions & 0 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ criteria = "safe-to-deploy"
version = "0.8.9"
criteria = "safe-to-deploy"

[[exemptions.regex-syntax]]
version = "0.8.10"
criteria = "safe-to-deploy"

[[exemptions.reqwest]]
version = "0.13.2"
criteria = "safe-to-deploy"
Expand Down
Loading