Skip to content

Commit 296f592

Browse files
committed
determine rust default language version independent of rust-toolchain.toml
1 parent 1602328 commit 296f592

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pre_commit/languages/rust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_default_version() -> str:
3434
# Just detecting the executable does not suffice, because if rustup is
3535
# installed but no toolchain is available, then `cargo` exists but
3636
# cannot be used without installing a toolchain first.
37-
if cmd_output_b('cargo', '--version', check=False)[0] == 0:
37+
if cmd_output_b('cargo', '--version', check=False, cwd='/')[0] == 0:
3838
return 'system'
3939
else:
4040
return C.DEFAULT

tests/languages/rust_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pre_commit.languages import rust
1010
from pre_commit.store import _make_local_repo
1111
from testing.language_helpers import run_language
12+
from testing.util import cwd
1213

1314
ACTUAL_GET_DEFAULT_VERSION = rust.get_default_version.__wrapped__
1415

@@ -29,6 +30,14 @@ def test_uses_default_when_rust_is_not_available(cmd_output_b_mck):
2930
assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT
3031

3132

33+
def test_selects_system_even_if_rust_toolchain_toml(tmp_path):
34+
toolchain_toml = '[toolchain]\nchannel = "wtf"\n'
35+
tmp_path.joinpath('rust-toolchain.toml').write_text(toolchain_toml)
36+
37+
with cwd(tmp_path):
38+
assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
39+
40+
3241
def _make_hello_world(tmp_path):
3342
src_dir = tmp_path.joinpath('src')
3443
src_dir.mkdir()

0 commit comments

Comments
 (0)