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

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Jan 5 20:03:18 UTC 2018


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

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):



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


More information about the Mercurial-devel mailing list