Skip to contentSkip to conversation

rust: rust_is_available: support testing with `bash` as `/bin/sh`

PATCH Applied Miguel Ojeda 3 participants 3 messages Jul 19 – Aug 3

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: rust_is_available: support testing with `bash` as `/bin/sh`

command -v behaves differently on dash vs. bash when faced with a file without the execute bit.

Thus, for the non-executable rustc and bindgen tests, support both possible outputs that the script currently gives.

This makes the test script clean on distributions like Fedora.

---
Independently, we could add a custom check for the non-exec case in the actual shell script, but back then it was decided with Kbuild to avoid overcomplicating it for rare cases (which anyway give an error).

 scripts/rust_is_available_test.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/rust_is_available_test.py +12 -2
index d6d54b7ea42a..752c59d5f55f 100755
@@ -177,7 +177,12 @@ else:
 
     def test_rustc_nonexecutable(self):
         result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.nonexecutable })
-        self.assertIn(f"Running '{self.nonexecutable}' to check the Rust compiler version failed with", result.stderr)
+        self.assertTrue(
+            # `dash`.
+            f"Running '{self.nonexecutable}' to check the Rust compiler version failed with" in result.stderr or
+            # `bash`.
+            f"Rust compiler '{self.nonexecutable}' could not be found." in result.stderr
+        )
 
     def test_rustc_unexpected_binary(self):
         result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.unexpected_binary })
@@ -205,7 +210,12 @@ else:
 
     def test_bindgen_nonexecutable(self):
         result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable })
-        self.assertIn(f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with", result.stderr)
+        self.assertTrue(
+            # `dash`.
+            f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with" in result.stderr or
+            # `bash`.
+            f"Rust bindings generator '{self.nonexecutable}' could not be found." in result.stderr
+        )
 
     def test_bindgen_unexpected_binary(self):
         result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.unexpected_binary })

base-commit: 880c43b185ca52239e75bc546cc4f4d9154d0fed --
2.55.0

reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 50 lines · On Sun, 19 Jul 2026 15:07:23 +0200 Miguel Ojeda <[email protected]> wrote:

command -v behaves differently on dash vs. bash when faced with a file without the execute bit.

Thus, for the non-executable rustc and bindgen tests, support both possible outputs that the script currently gives.

This makes the test script clean on distributions like Fedora.

---
Independently, we could add a custom check for the non-exec case in the actual shell script, but back then it was decided with Kbuild to avoid overcomplicating it for rare cases (which anyway give an error).

 scripts/rust_is_available_test.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
scripts/rust_is_available_test.py +12 -2
index d6d54b7ea42a..752c59d5f55f 100755
@@ -177,7 +177,12 @@ else:
 
     def test_rustc_nonexecutable(self):
         result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.nonexecutable })
-        self.assertIn(f"Running '{self.nonexecutable}' to check the Rust compiler version failed with", result.stderr)
+        self.assertTrue(
+            # `dash`.
+            f"Running '{self.nonexecutable}' to check the Rust compiler version failed with" in result.stderr or
+            # `bash`.
+            f"Rust compiler '{self.nonexecutable}' could not be found." in result.stderr
+        )
 
     def test_rustc_unexpected_binary(self):
         result = self.run_script(self.Expected.FAILURE, { "RUSTC": self.unexpected_binary })
@@ -205,7 +210,12 @@ else:
 
     def test_bindgen_nonexecutable(self):
         result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.nonexecutable })
-        self.assertIn(f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with", result.stderr)
+        self.assertTrue(
+            # `dash`.
+            f"Running '{self.nonexecutable}' to check the Rust bindings generator version failed with" in result.stderr or
+            # `bash`.
+            f"Rust bindings generator '{self.nonexecutable}' could not be found." in result.stderr
+        )
 
     def test_bindgen_unexpected_binary(self):
         result = self.run_script(self.Expected.FAILURE, { "BINDGEN": self.unexpected_binary })
Quoted 3 lines

base-commit: 880c43b185ca52239e75bc546cc4f4d9154d0fed --
2.55.0

Nit: You can add some useful failure message, something like "$binary could not found in the system". The default failure message for assertTrue is something like "False is not True", which is not helpful. But the failed lines will also be printed so it's not entirely unclear as well.

With/without that:

Applied
#2 lore raw
In reply to Miguel Ojeda
Quoted 10 lines · Miguel Ojeda

command -v behaves differently on dash vs. bash when faced with a file without the execute bit.

Thus, for the non-executable rustc and bindgen tests, support both possible outputs that the script currently gives.

This makes the test script clean on distributions like Fedora.

Applied to rust-next -- thanks everyone!

[ Added custom assertion message as suggested. - Miguel ]

Cheers,
Miguel