Repository: reubeno/brush
Pull request #391 (2025-02-27 04:20:45)

fix: correct path tests on empty strings
Ensure that, for example, `[[ -e '' ]]` does *not* return 0.

The trouble here is that `Shell::get_absolute_path()` had returned a valid, absolute path when given a `Path` constructed from `""`. This fixes that at the root by explicitly checking for a `Path` whose `.as_os_str()` is empty.

github-actions[bot]: # Performance Benchmark Report
| Benchmark name                         | Baseline (μs) |  Test/PR (μs) |    Delta (μs) | Delta %         |
| -------------------------------------- | ------------- | ------------- | ------------- | --------------- |
| `clone_shell_object                  ` | `   18.05 μs` | `   18.20 μs` | `    0.15 μs` | `🟠 +0.85%    ` |
| `eval_arithmetic                     ` | `    0.17 μs` | `    0.17 μs` | `    0.00 μs` | `⚪  Unchanged` |
| `expand_one_string                   ` | `    1.79 μs` | `    1.85 μs` | `    0.05 μs` | `⚪  Unchanged` |
| `for_loop                            ` | `   21.50 μs` | `   21.60 μs` | `    0.09 μs` | `⚪  Unchanged` |
| `function_call                       ` | `    2.36 μs` | `    2.28 μs` | `   -0.08 μs` | `⚪  Unchanged` |
| `instantiate_shell                   ` | `   56.99 μs` | `   56.66 μs` | `   -0.32 μs` | `⚪  Unchanged` |
| `instantiate_shell_with_init_scripts ` | `23409.82 μs` | `23740.32 μs` | `  330.50 μs` | `🟠 +1.41%    ` |
| `parse_bash_completion               ` | ` 1654.74 μs` | ` 1666.35 μs` | `   11.62 μs` | `⚪  Unchanged` |
| `parse_sample_script                 ` | `    1.73 μs` | `    1.75 μs` | `    0.02 μs` | `⚪  Unchanged` |
| `run_echo_builtin_command            ` | `   14.96 μs` | `   15.00 μs` | `    0.04 μs` | `⚪  Unchanged` |
| `run_one_external_command            ` | ` 2294.09 μs` | ` 7501.02 μs` | ` 5206.94 μs` | `🟠 +226.97%  ` |
| `tokenize_sample_script              ` | `    2.83 μs` | `    2.73 μs` | `   -0.10 μs` | `🟢 -3.71%    ` |

# Code Coverage Report: Only Changed Files listed

| Package | Base Coverage | New Coverage | Difference |
| ------- | ------------- | ------------ | ---------- |
| brush-core/src/jobs.rs | 🔴 37.07% | 🔴 43.1% | 🟢 6.03% |
| brush-core/src/shell.rs | 🟢 82.62% | 🟢 82.49% | 🔴 -0.13% |
| **Overall Coverage** | **🟢 76.06%** | **🟢 76.14%** | **🟢 0.08%** |

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

# Test Summary: bash-completion test suite
| Outcome            | Count                   | Percentage |
| ------------------ | ----------------------: | ---------: |
| ✅ Pass            | 1329            | <span style='color:green'>63.29</span> |
| ❗️ Error           | 229           | <span style='color:red'>10.90</span> |
| ❌ Fail            | 169            | <span style='color:red'>8.05</span> |
| ⏩ Skip            | 358            | 17.05 |
| ❎ Expected Fail   | 14   | 0.67 |
| ✔️ Unexpected Pass | 1 | <span style='color:red'>0.05</span> |
| 📊 Total           | 2100           | 100.00 |

<!-- Sticky Pull Request Comment -->
github-actions[bot]: ## Test Results
    2 files      9 suites   1m 39s ⏱️
  691 tests   691 ✅ 0 💤 0 ❌
1 368 runs  1 368 ✅ 0 💤 0 ❌

Results for commit 638f5f15.

[test-results]:data:application/gzip;base64,H4sIAPPqv2cC/13MTQ6DIBhF0a0Yxh3wIx/QzTSAkpCqNAgj070XiLba4bkveRtyfhpXdO/orUNr9qlBFQw56uTDUlldllQ3UOTQY83W/qenf5WEv8FpP13CGGOIe4l5qZ+Egdx1fF7S77P5dNl8frRhnn0qQMCk445wS4Br3NN+0NQAKGYEU9IaS7jABgv0/gC+BcSWBgEAAA==


Patch:
diff --git a/brush-core/src/shell.rs b/brush-core/src/shell.rs
index 2039f89..00624f0 100644
--- a/brush-core/src/shell.rs
+++ b/brush-core/src/shell.rs
@@ -1364,7 +1364,7 @@ impl Shell {
     ///
     /// * `path` - The path to get the absolute form of.
     pub fn get_absolute_path(&self, path: &Path) -> PathBuf {
-        if path.is_absolute() {
+        if path.as_os_str().is_empty() || path.is_absolute() {
             path.to_owned()
         } else {
             self.working_dir.join(path)


Test patch:
diff --git a/brush-shell/tests/cases/extended_tests.yaml b/brush-shell/tests/cases/extended_tests.yaml
index f59ec2d..a233ce8 100644
--- a/brush-shell/tests/cases/extended_tests.yaml
+++ b/brush-shell/tests/cases/extended_tests.yaml
@@ -8,11 +8,36 @@ cases:
       [[ -c /dev/null ]] && echo "-c correctly checked /dev/null"
       [[ -c /tmp ]] || echo "-c correctly checked /tmp"
 
-      [[ -d /tmp ]] && echo "-d correctly checked /tmp"
-      [[ -d /dev/null ]] || echo "-d correctly checked /dev/null"
+  - name: "Existence tests"
+    stdin: |
+      [[ -e '' ]] || echo "-e correctly identified empty string as non-existent"
+
+      [[ -e non-existent ]] || echo "-e correctly identified non-existent path"
+      [[ ! -e non-existent ]] && echo "! -e correctly identified non-existent path"
+
+      touch test-file
+      [[ -e test-file ]] && echo "-e correctly identified existing non-dir"
+
+      mkdir test-dir
+      [[ -e test-dir ]] && echo "-d correctly identified existing dir"
+
+  - name: "Directory tests"
+    stdin: |
+      [[ -d '' ]] || echo "-d correctly identified empty string as non-existent"
+
+      [[ -d non-existent ]] || echo "-d correctly identified non-existent path"
+      [[ ! -d non-existent ]] && echo "! -d correctly identified non-existent path"
+
+      touch test-file
+      [[ -d test-file ]] || echo "-d correctly identified non-dir file"
+
+      mkdir test-dir
+      [[ -d test-dir ]] && echo "-d correctly identified existing dir"
 
   - name: "File regular tests"
     stdin: |
+      [[ -f '' ]] || echo "-f correctly identified empty string as non-existent"
+
       [[ -f non-existent ]] || echo "-f correctly identified non-existent path"
       [[ ! -f non-existent ]] && echo "! -f correctly identified non-existent path"