Patchwork D7579: tests: add test for Rust formatting

login
register
mail settings
Submitter phabricator
Date Dec. 10, 2019, 3:45 p.m.
Message ID <e987fb3e50819ab3a8ddc9c966c286a0@localhost.localdomain>
Download mbox | patch
Permalink /patch/43673/
State Not Applicable
Headers show

Comments

phabricator - Dec. 10, 2019, 3:45 p.m.
Closed by commit rHGe8a3bbffdc7d: tests: add test for Rust formatting (authored by indygreg).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7579?vs=18539&id=18570

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7579/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7579

AFFECTED FILES
  tests/hghave.py
  tests/run-tests.py
  tests/test-check-rust-format.t

CHANGE DETAILS




To: indygreg, #hg-reviewers, Alphare, pulkit
Cc: Alphare, mercurial-devel

Patch

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
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/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'
+    )