testutil/dott: make translate use posix shell quote

Summary:
`util.shellquote` is platform-dependent. In case of the translator, it always
uses `shlex.split`. Therefore the posix shell quote should be used.

This makes the the test stable across multiple platforms. Namely, `"` is not
used on Windows.

Reviewed By: xavierd

Differential Revision: D16606904

fbshipit-source-id: 879e06b54fc427a6ad1aa959927a0df52f33269a
This commit is contained in:
Jun Wu 2019-08-01 17:55:27 -07:00 committed by Facebook Github Bot
parent 5e701ebdaf
commit 6253e8a50e

View File

@ -17,6 +17,7 @@ from __future__ import absolute_import
import ast
import hashlib
import os
import re
import shlex
import subprocess
import sys
@ -29,6 +30,12 @@ from .. import autofix
_repr = autofix._repr
def shellquote(s, _needsshellquote=re.compile(br"[^a-zA-Z0-9._/+-]").search):
if _needsshellquote(s):
s = "'%s'" % s.replace("'", "'\\''")
return s
def parsecmd(line):
argiter = iter(shlex.split(line))
nextarg = lambda: next(argiter, None)
@ -41,7 +48,7 @@ def parsecmd(line):
cmd[:] = []
def result():
return " ".join(map(util.shellquote, cmd)), opts.copy()
return " ".join(map(shellquote, cmd)), opts.copy()
reset()