Patchwork [1,of,2] windows: add doctest for shellquote()

login
register
mail settings
Submitter Matt Harbison
Date May 2, 2015, 2:57 a.m.
Message ID <95f85481cf53e0855e94.1430535439@Envy>
Download mbox | patch
Permalink /patch/8841/
State Accepted
Commit 30b910fea244374e5a0418fa1bc95f3b47c1fa7d
Headers show

Comments

Matt Harbison - May 2, 2015, 2:57 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1430525820 14400
#      Fri May 01 20:17:00 2015 -0400
# Node ID 95f85481cf53e0855e9481fbd85196efcaa72455
# Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
windows: add doctest for shellquote()

This is actual test coverage for issue4629.  The test changes in eea3977e6fca
were simply the addition of quotes to the output, not ensuring that strings with
backslashes are quoted.
Matt Mackall - May 4, 2015, 5:30 p.m.
On Fri, 2015-05-01 at 22:57 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1430525820 14400
> #      Fri May 01 20:17:00 2015 -0400
> # Node ID 95f85481cf53e0855e9481fbd85196efcaa72455
> # Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
> windows: add doctest for shellquote()

Queued for default, thanks. Did you check that test-doctest.py runs the
test?
Matt Harbison - May 4, 2015, 11:32 p.m.
On Mon, 04 May 2015 13:30:31 -0400, Matt Mackall <mpm@selenic.com> wrote:

> On Fri, 2015-05-01 at 22:57 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1430525820 14400
>> #      Fri May 01 20:17:00 2015 -0400
>> # Node ID 95f85481cf53e0855e9481fbd85196efcaa72455
>> # Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
>> windows: add doctest for shellquote()
>
> Queued for default, thanks. Did you check that test-doctest.py runs the
> test?
>

   $ ./run-tests.py --local test-doctest.py

on Windows and Linux.  I wouldn't have guessed the double backslash was  
needed, and it was quadruple backslash without the raw string.  I got the  
idea on SO [1], otherwise it was pretty incomprehensible.

--Matt

[1]  
https://stackoverflow.com/questions/11765401/doctest-involving-escape-characters

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -162,6 +162,18 @@ 
 _quotere = None
 _needsshellquote = None
 def shellquote(s):
+    r"""
+    >>> shellquote(r'C:\Users\xyz')
+    '"C:\\Users\\xyz"'
+    >>> shellquote(r'C:\Users\xyz/mixed')
+    '"C:\\Users\\xyz/mixed"'
+    >>> # Would be safe not to quote too, since it is all double backslashes
+    >>> shellquote(r'C:\\Users\\xyz')
+    '"C:\\\\Users\\\\xyz"'
+    >>> # But this must be quoted
+    >>> shellquote(r'C:\\Users\\xyz/abc')
+    '"C:\\\\Users\\\\xyz/abc"'
+    """
     global _quotere
     if _quotere is None:
         _quotere = re.compile(r'(\\*)("|\\$)')