Repository: reubeno/brush
Pull request #467 (2025-05-06 04:38:09)

fix(declare): turn down volume on non-existent functions
In testing with `fzf`, we found that `brush` complains more noisily when `declare -F` (or `-f`) is asked to find a non-existent function. Apparently this is counted on by some scripts (without suppressing `stderr`) to check for function existence.

github-actions[bot]: ## Test Results
    3 files     14 suites   3m 41s ⏱️
  730 tests   730 ✅ 0 💤 0 ❌
2 176 runs  2 176 ✅ 0 💤 0 ❌

Results for commit d8045da3.

[test-results]:data:application/gzip;base64,H4sIAPmUGWgC/13MSw6DIBSF4a0Yxh3wEGi7mQa5kNxUpeExMt17kWjUDr//JGchHkeXyLMTt46kgrmB9VVQoskY5mrOWQ11y+uqBd31SsXa//TGT01H8AbHS3AxhriVWOb1kzOtNu2fl3R8Np8um8+PNkwT5goCd9pLMIIqDmzQhlJhwYLmSrjBSpCeg35oRr4/spoZPwgBAAA=

github-actions[bot]: # Performance Benchmark Report
| Benchmark name                         | Baseline (μs) |  Test/PR (μs) |    Delta (μs) | Delta %         |
| -------------------------------------- | ------------- | ------------- | ------------- | --------------- |
| `clone_shell_object                  ` | `   18.42 μs` | `   17.70 μs` | `   -0.72 μs` | `🟢 -3.93%    ` |
| `eval_arithmetic                     ` | `    0.17 μs` | `    0.18 μs` | `    0.00 μs` | `⚪  Unchanged` |
| `expand_one_string                   ` | `    1.86 μs` | `    1.85 μs` | `   -0.01 μs` | `⚪  Unchanged` |
| `for_loop                            ` | `   22.59 μs` | `   22.57 μs` | `   -0.02 μs` | `⚪  Unchanged` |
| `function_call                       ` | `    2.48 μs` | `    2.37 μs` | `   -0.11 μs` | `⚪  Unchanged` |
| `instantiate_shell                   ` | `   57.35 μs` | `   57.18 μs` | `   -0.17 μs` | `⚪  Unchanged` |
| `instantiate_shell_with_init_scripts ` | `23650.65 μs` | `23579.86 μs` | `  -70.79 μs` | `⚪  Unchanged` |
| `parse_bash_completion               ` | ` 1664.73 μs` | ` 1658.86 μs` | `   -5.88 μs` | `⚪  Unchanged` |
| `parse_sample_script                 ` | `    1.75 μs` | `    1.74 μs` | `   -0.01 μs` | `🟢 -0.51%    ` |
| `run_echo_builtin_command            ` | `   15.58 μs` | `   15.35 μs` | `   -0.24 μs` | `⚪  Unchanged` |
| `run_one_external_command            ` | ` 8224.34 μs` | ` 2358.90 μs` | `-5865.44 μs` | `🟢 -71.32%   ` |
| `tokenize_sample_script              ` | `    2.98 μs` | `    2.87 μs` | `   -0.11 μs` | `🟢 -3.56%    ` |

# Code Coverage Report: Only Changed Files listed

| Package | Base Coverage | New Coverage | Difference |
| ------- | ------------- | ------------ | ---------- |
| brush-core/src/builtins/declare.rs | 🟢 83.93% | 🟢 84.72% | 🟢 0.79% |
| **Overall Coverage** | **🟢 78.48%** | **🟢 78.5%** | **🟢 0.02%** |

_Minimum allowed coverage is_ `70%`_, this run produced_ `78.5%`

# Test Summary: bash-completion test suite
| Outcome            | Count                   | Percentage |
| ------------------ | ----------------------: | ---------: |
| ✅ Pass            | 1302            | <span style='color:green'>61.74</span> |
| ❗️ Error           | 238           | <span style='color:red'>11.28</span> |
| ❌ Fail            | 181            | <span style='color:red'>8.58</span> |
| ⏩ Skip            | 373            | 17.69 |
| ❎ Expected Fail   | 14   | 0.66 |
| ✔️ Unexpected Pass | 1 | <span style='color:red'>0.05</span> |
| 📊 Total           | 2109           | 100.00 |

<!-- Sticky Pull Request Comment -->

Patch:
diff --git a/brush-core/src/builtins/declare.rs b/brush-core/src/builtins/declare.rs
index 1767f27..4c43778 100644
--- a/brush-core/src/builtins/declare.rs
+++ b/brush-core/src/builtins/declare.rs
@@ -199,7 +199,7 @@ impl DeclareCommand {
                 }
                 Ok(true)
             } else {
-                writeln!(context.stderr(), "declare: {name}: not found")?;
+                // For some reason, bash does not print an error message in this case.
                 Ok(false)
             }
         } else if let Some(variable) = context.shell.env.get_using_policy(name, lookup) {


Test patch:
diff --git a/brush-shell/tests/cases/builtins/declare.yaml b/brush-shell/tests/cases/builtins/declare.yaml
index 9dfe11f..3f50f20 100644
--- a/brush-shell/tests/cases/builtins/declare.yaml
+++ b/brush-shell/tests/cases/builtins/declare.yaml
@@ -198,6 +198,14 @@ cases:
       declare -f test
       declare -p -f test
 
+  - name: "Displaying non-existent functions"
+    stdin: |
+      declare -f not_a_function
+      echo "Result (-f): $?"
+
+      declare -F not_a_function
+      echo "Result (-F): $?"
+
   - name: "Valid conversions"
     stdin: |
       declare -a arr1=(a b c)