Repository: reubeno/brush
Pull request #435 (2025-04-22 16:59:43)

fix: handle complete builtin run without options
Fix for `complete` built-in being run with no options, and adds a basic compat test for that usage.

Resolves #434 

github-actions[bot]: # Performance Benchmark Report
| Benchmark name                         | Baseline (μs) |  Test/PR (μs) |    Delta (μs) | Delta %         |
| -------------------------------------- | ------------- | ------------- | ------------- | --------------- |
| `clone_shell_object                  ` | `   18.04 μs` | `   17.93 μs` | `   -0.12 μs` | `⚪  Unchanged` |
| `eval_arithmetic                     ` | `    0.17 μs` | `    0.17 μs` | `   -0.00 μs` | `⚪  Unchanged` |
| `expand_one_string                   ` | `    1.91 μs` | `    1.87 μs` | `   -0.04 μs` | `⚪  Unchanged` |
| `for_loop                            ` | `   22.47 μs` | `   22.55 μs` | `    0.08 μs` | `⚪  Unchanged` |
| `function_call                       ` | `    2.86 μs` | `    2.49 μs` | `   -0.38 μs` | `⚪  Unchanged` |
| `instantiate_shell                   ` | `   59.60 μs` | `   57.01 μs` | `   -2.59 μs` | `🟢 -4.34%    ` |
| `instantiate_shell_with_init_scripts ` | `23858.15 μs` | `25050.90 μs` | ` 1192.74 μs` | `🟠 +5.00%    ` |
| `parse_bash_completion               ` | ` 1670.81 μs` | ` 1684.75 μs` | `   13.94 μs` | `⚪  Unchanged` |
| `parse_sample_script                 ` | `    1.78 μs` | `    1.77 μs` | `   -0.01 μs` | `⚪  Unchanged` |
| `run_echo_builtin_command            ` | `   15.37 μs` | `   15.41 μs` | `    0.04 μs` | `⚪  Unchanged` |
| `run_one_external_command            ` | ` 4612.53 μs` | ` 3996.76 μs` | ` -615.77 μs` | `🟢 -13.35%   ` |
| `tokenize_sample_script              ` | `    2.79 μs` | `    2.82 μs` | `    0.03 μs` | `🟠 +1.15%    ` |

# Code Coverage Report: Only Changed Files listed

| Package | Base Coverage | New Coverage | Difference |
| ------- | ------------- | ------------ | ---------- |
| brush-core/src/builtins/complete.rs | 🟠 61.4% | 🟠 65.12% | 🟢 3.72% |
| brush-core/src/completion.rs | 🔴 30.15% | 🔴 30.6% | 🟢 0.45% |
| **Overall Coverage** | **🟢 76.09%** | **🟢 76.21%** | **🟢 0.12%** |

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

# Test Summary: bash-completion test suite
| Outcome            | Count                   | Percentage |
| ------------------ | ----------------------: | ---------: |
| ✅ Pass            | 1311            | <span style='color:green'>62.16</span> |
| ❗️ Error           | 238           | <span style='color:red'>11.28</span> |
| ❌ Fail            | 183            | <span style='color:red'>8.68</span> |
| ⏩ Skip            | 362            | 17.16 |
| ❎ 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/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 6a4b913..b6a992e 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -16,6 +16,7 @@ RUN apt-get update -y && \
         build-essential \
         curl \
         git \
+        iputils-ping \
         language-pack-en \
         neovim \
         sed \
diff --git a/brush-core/src/builtins/complete.rs b/brush-core/src/builtins/complete.rs
index bb8793d..0b01059 100644
--- a/brush-core/src/builtins/complete.rs
+++ b/brush-core/src/builtins/complete.rs
@@ -265,7 +265,8 @@ impl CompleteCommand {
             None
         };
 
-        if self.print {
+        // Treat 'complete' with no options the same as 'complete -p'.
+        if self.print || (!self.remove && target_spec.is_none()) {
             if let Some(target_spec) = target_spec {
                 if let Some(existing_spec) = target_spec {
                     let existing_spec = existing_spec.clone();


Test patch:
diff --git a/brush-shell/tests/cases/builtins/complete.yaml b/brush-shell/tests/cases/builtins/complete.yaml
index ada61c9..73cd5b7 100644
--- a/brush-shell/tests/cases/builtins/complete.yaml
+++ b/brush-shell/tests/cases/builtins/complete.yaml
@@ -1,5 +1,10 @@
 name: "Builtins: complete"
 cases:
+  - name: "complete with no options"
+    stdin: |
+      complete -W foo mycmd
+      complete
+
   - name: "Roundtrip: complete -W"
     stdin: |
       complete -W foo mycmd