changeset 35536:f04d16bef2c7

tests: make #testcase available as env var in test 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. Differential Revision: https://phab.mercurial-scm.org/D1816
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 05 Jan 2018 11:53:33 -0800
parents ffd7b7cd309b
children 58fda95a0202
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Jan 05 19:30:37 2018 +0530
+++ b/tests/run-tests.py	Fri Jan 05 11:53:33 2018 -0800
@@ -1334,6 +1334,9 @@
             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' % shellquote(self._case))
+            script.append(b'export TESTCASE\n')
 
         n = 0
         for n, l in enumerate(lines):
--- a/tests/test-run-tests.t	Fri Jan 05 19:30:37 2018 +0530
+++ b/tests/test-run-tests.t	Fri Jan 05 11:53:33 2018 -0800
@@ -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