Patchwork tests: do not use system hg if it does not have "files" command

login
register
mail settings
Submitter Jun Wu
Date June 28, 2017, 2:24 p.m.
Message ID <547cf826d26340ba8076.1498659890@x1c>
Download mbox | patch
Permalink /patch/21800/
State Superseded
Headers show

Comments

Jun Wu - June 28, 2017, 2:24 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1498659616 25200
#      Wed Jun 28 07:20:16 2017 -0700
# Node ID 547cf826d26340ba80762226b49533c5b0c25046
# Parent  8c45747460e8b02cc88146cccc54404fe4df4cb4
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 547cf826d263
tests: do not use system hg if it does not have "files" command

Ancient hg does not have "hg files" so test-check-*.t will fail with
"unknown command 'files'":

  $ hg files
  hg: unknown command 'files'
  $ hg --version
  Mercurial Distributed SCM (version 2.6.2)

Test "hg files" and give up using syshg if it's ancient.
Adam Simpkins - June 28, 2017, 7:54 p.m.
On Jun 28, Jun Wu wrote:
> +
> +# Most test-check-* requiring testrepo use "hg files", which is not available
> +# in ancient versions of hg. So we double check if the syshg works and fallback
> +# to hg shipped in the repo.
> +syshg files -h >/dev/null 2>/dev/null
> +if [ $? -ne 0 ]; then
> +    function syshg {
> +        hg "$@"
> +    }
> +    function syshgenv {
> +        true
> +    }
> +fi

Looks good to me, but this will need to be updated to the
non-bash-specific function syntax (e.g., 'syshg () {'),
as Yuya pointed out on my earlier diff.

If you wanted to be pedantic you could also replace "true" with ":"
here; ":" is guaranteed to be a shell builtin; "true" may require
executing a separate process on some systems.  This probably doesn't
really matter though.
Jun Wu - June 28, 2017, 8:43 p.m.
Excerpts from Adam Simpkins's message of 2017-06-28 12:54:18 -0700:
> Looks good to me, but this will need to be updated to the
> non-bash-specific function syntax (e.g., 'syshg () {'),
> as Yuya pointed out on my earlier diff.
> 
> If you wanted to be pedantic you could also replace "true" with ":"
> here; ":" is guaranteed to be a shell builtin; "true" may require
> executing a separate process on some systems.  This probably doesn't
> really matter though.
 
Good advice. I have been wondering the usage of ":" except for fork bomb for
a while. I'll also fix English grammar in the comment.

Patch

diff --git a/tests/helpers-testrepo.sh b/tests/helpers-testrepo.sh
--- a/tests/helpers-testrepo.sh
+++ b/tests/helpers-testrepo.sh
@@ -26,2 +26,15 @@  function syshgenv {
     export HGPLAIN
 }
+
+# Most test-check-* requiring testrepo use "hg files", which is not available
+# in ancient versions of hg. So we double check if the syshg works and fallback
+# to hg shipped in the repo.
+syshg files -h >/dev/null 2>/dev/null
+if [ $? -ne 0 ]; then
+    function syshg {
+        hg "$@"
+    }
+    function syshgenv {
+        true
+    }
+fi