[PATCH 2 of 6] run-tests: handle output that starts with "$ "

timeless timeless at mozdev.org
Tue Jan 12 18:38:05 UTC 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1452619172 0
#      Tue Jan 12 17:19:32 2016 +0000
# Node ID a4f6489df893272a532f9d9cf88b12fd0619efc6
# Parent  13f44adf400886e8d65fcb2bcf5dc5763b250214
run-tests: handle output that starts with "$ "

This is necessary because some help content happens to start with that pattern,
and it is legitimate, so, we add an escape sequence for "$ " as "\$ ".

If you need to use this escape sequence in a dynamic (echo > test-test.t << EOF)
test, remember that you have to escape your backslash because the first one
will be parsed by the shell, and thus will not be in your file.

For normal users, a single backslash is enough, and running your test with -i
will generate the proper escaping.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1045,6 +1045,9 @@
             elif l.startswith(b'  > '): # continuations
                 after.setdefault(prepos, []).append(l)
                 script.append(l[4:])
+            elif l.startswith(b'  \\$'): # results
+                # Queue up a list of expected results.
+                expected.setdefault(pos, []).append(l[2:])
             elif l.startswith(b'  '): # results
                 # Queue up a list of expected results.
                 expected.setdefault(pos, []).append(l[2:])
@@ -1077,6 +1080,11 @@
                 lout, lcmd = l.split(salt, 1)
 
             while lout:
+                # We generally expect lines that start with "$ "
+                # To be commands, but they can also be the result of
+                # output, when that happens, we escape them with a \.
+                if lout.startswith('$ '):
+                    lout = '\\' + lout
                 if not lout.endswith(b'\n'):
                     lout += b' (no-eol)\n'
 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -2260,24 +2260,24 @@
   <ul>
    <li> New (unknown) files are added   automatically by "hg add":
   <pre>
-  \$ ls (re)
+  \$ ls
   foo.c
-  \$ hg status (re)
+  \$ hg status
   ? foo.c
-  \$ hg add (re)
+  \$ hg add
   adding foo.c
-  \$ hg status (re)
+  \$ hg status
   A foo.c
   </pre>
    <li> Specific files to be added can be specified:
   <pre>
-  \$ ls (re)
+  \$ ls
   bar.c  foo.c
-  \$ hg status (re)
+  \$ hg status
   ? bar.c
   ? foo.c
-  \$ hg add bar.c (re)
-  \$ hg status (re)
+  \$ hg add bar.c
+  \$ hg status
   A bar.c
   ? foo.c
   </pre>
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
@@ -620,6 +620,16 @@
 
   $ rm -f test-glob-backslash.t
 
+dollar at beginning of line needs to be escaped
+
+  $ cat > test-dollar-escape.t << EOF
+  >   $ echo $ echo this
+  >   \\$ echo this
+  > EOF
+  $ rt test-dollar-escape.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
 Test reusability for third party tools
 ======================================
 



More information about the Mercurial-devel mailing list