diff --git a/tests/hghave.py b/tests/hghave.py --- a/tests/hghave.py +++ b/tests/hghave.py @@ -1015,3 +1015,11 @@ version = matchoutput(pytypecmd, b'[0-9a-b.]+') sv = distutils.version.StrictVersion return version and sv(_strpath(version.group(0))) >= sv('2019.10.17') + + +@check("rustfmt", "rustfmt tool") +def has_rustfmt(): + # We use Nightly's rustfmt due to current unstable config options. + return matchoutput( + '`rustup which --toolchain nightly rustfmt` --version', b'rustfmt' + ) diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1363,6 +1363,20 @@ if PYTHON3 and os.name == 'nt': env['PYTHONLEGACYWINDOWSSTDIO'] = '1' + # Modified HOME in test environment can confuse Rust tools. So set + # CARGO_HOME and RUSTUP_HOME automatically if a Rust toolchain is + # present and these variables aren't already defined. + cargo_home_path = os.path.expanduser('~/.cargo') + rustup_home_path = os.path.expanduser('~/.rustup') + + if os.path.exists(cargo_home_path) and b'CARGO_HOME' not in osenvironb: + env['CARGO_HOME'] = cargo_home_path + if ( + os.path.exists(rustup_home_path) + and b'RUSTUP_HOME' not in osenvironb + ): + env['RUSTUP_HOME'] = rustup_home_path + # Reset some environment variables to well-known values so that # the tests produce repeatable output. env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C' diff --git a/tests/test-check-rust-format.t b/tests/test-check-rust-format.t new file mode 100644 --- /dev/null +++ b/tests/test-check-rust-format.t @@ -0,0 +1,9 @@ +#require rustfmt test-repo + + $ . "$TESTDIR/helpers-testrepo.sh" + + $ cd "$TESTDIR"/.. + $ RUSTFMT=$(rustup which --toolchain nightly rustfmt) + $ for f in `testrepohg files 'glob:**/*.rs'` ; do + > $RUSTFMT --check --unstable-features --color=never $f + > done