Patchwork D1816: tests: make #testcase available as env var in test

login
register
mail settings
Submitter phabricator
Date Jan. 5, 2018, 8:03 p.m.
Message ID <differential-rev-PHID-DREV-xtuq5mbahrwk7qqryts3-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26574/
State Superseded
Headers show

Comments

phabricator - Jan. 5, 2018, 8:03 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It can be useful for e.g. helper functions to behave differently
  depending on which test case is being executed. This patch helps with
  that by making the #testcase case available as a TESTCASE environment
  variable.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  tests/run-tests.py
  tests/test-run-tests.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 5, 2018, 8:56 p.m.
quark added inline comments.

INLINE COMMENTS

> run-tests.py:1338
> +        if self._case:
> +            script.append(b'TESTCASE=%s\n' % self._case)
>  

Maybe `util.shellquote` the name.

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, quark
Cc: mercurial-devel
phabricator - Jan. 5, 2018, 9:06 p.m.
martinvonz marked an inline comment as not done.
martinvonz added inline comments.

INLINE COMMENTS

> quark wrote in run-tests.py:1338
> Maybe `util.shellquote` the name.

Done (but it seems to be just `shellquote` in the test runner).

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, quark
Cc: mercurial-devel
phabricator - Jan. 6, 2018, 2:38 a.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> run-tests.py:1338
> +        if self._case:
> +            script.append(b'TESTCASE=%s\n' % shellquote(self._case))
>  

Needs `export TESTCASE` to export shell variables to environment.

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, quark, yuja
Cc: yuja, mercurial-devel
phabricator - Jan. 6, 2018, 6:20 a.m.
martinvonz marked an inline comment as not done.
martinvonz added inline comments.

INLINE COMMENTS

> yuja wrote in run-tests.py:1338
> Needs `export TESTCASE` to export shell variables to environment.

> Needs `export TESTCASE` to export shell variables to environment.

Sure, will do. I wasn't sure if I should or shouldn't. Are you thinking that it may be useful if the function in my test case is instead a stand-alone script/binary?

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, quark, yuja
Cc: yuja, mercurial-devel
phabricator - Jan. 6, 2018, 7:27 a.m.
yuja accepted this revision.
yuja added a comment.
This revision is now accepted and ready to land.


  > Are you thinking that it may be useful if the function in my test case is instead a stand-alone script/binary?
  
  No idea if it'll be useful, but there seemed no reason to narrow the scope
  of `$TESTCASE` variable.
  
  Queued, thanks.

REPOSITORY
  rHG Mercurial

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

To: martinvonz, #hg-reviewers, quark, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -1533,6 +1533,26 @@ 
   python hash seed: * (glob)
   [1]
 
+Test TESTCASE variable
+
+  $ cat > test-cases-ab.t <<'EOF'
+  >   $ dostuff() {
+  >   >   echo "In case $TESTCASE"
+  >   > }
+  > #testcases A B
+  > #if A
+  >   $ dostuff
+  >   In case A
+  > #endif
+  > #if B
+  >   $ dostuff
+  >   In case B
+  > #endif
+  > EOF
+  $ rt test-cases-ab.t
+  ..
+  # Ran 2 tests, 0 skipped, 0 failed.
+
 Test automatic pattern replacement
 
   $ cat << EOF >> common-pattern.py
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1334,6 +1334,8 @@ 
             script.append(b'alias hg="%s"\n' % self._hgcommand)
         if os.getenv('MSYSTEM'):
             script.append(b'alias pwd="pwd -W"\n')
+        if self._case:
+            script.append(b'TESTCASE=%s\n' % self._case)
 
         n = 0
         for n, l in enumerate(lines):