]> granicus.if.org Git - graphviz/commitdiff
shell-quote commands echoed during testing
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 11 Jan 2022 01:23:49 +0000 (17:23 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 15 Jan 2022 21:01:09 +0000 (13:01 -0800)
It is not typical that testing paths will contain things like spaces and other
characters that require quoting. But this change goes the extra mile to make
sure these echoed commands are always copy-pastable to re-execute them.

rtest/gvtest.py

index e91153b11be06ae3de13938ca1b4952d437c9483..390ae6b14e8b7b35382450e1850e2b17b0ee589b 100644 (file)
@@ -3,6 +3,7 @@
 import os
 from pathlib import Path
 import platform
+import shlex
 import subprocess
 import sys
 import sysconfig
@@ -46,7 +47,7 @@ def compile_c(src: Path, cflags: List[str] = None, link: List[str] = None,
       args += [f"-l{l}" for l in link] + ldflags
 
   # dump the command being run for the user to observe if the test fails
-  print(f'+ {" ".join(str(x) for x in args)}')
+  print(f'+ {" ".join(shlex.quote(str(x)) for x in args)}')
 
   # compile the program
   try:
@@ -116,7 +117,7 @@ def run_c(src: Path, args: List[str] = None, input: str = "",
 
     # dump the command being run for the user to observe if the test fails
     argv = [exe] + args
-    print(f'+ {" ".join(str(x) for x in argv)}')
+    print(f'+ {" ".join(shlex.quote(str(x)) for x in argv)}')
 
     # run it
     p = subprocess.run(argv, input=input, stdout=subprocess.PIPE,