parseopt2.cmdLineRest is now correct too (#10304)
This commit is contained in:
parent
beed27b75d
commit
795e5e11ef
2 changed files with 23 additions and 20 deletions
|
|
@ -112,10 +112,10 @@ proc next(p: var OptParser) =
|
||||||
p.key = token
|
p.key = token
|
||||||
p.val = ""
|
p.val = ""
|
||||||
|
|
||||||
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo2$1", deprecated.} =
|
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo2$1".} =
|
||||||
## Returns part of command line string that has not been parsed yet.
|
## Returns the part of command line string that has not been parsed yet,
|
||||||
## Do not use - does not correctly handle whitespace.
|
## properly quoted.
|
||||||
return p.cmd[p.pos..p.cmd.len-1].join(" ")
|
return p.cmd[p.pos..p.cmd.len-1].quoteShellCommand
|
||||||
|
|
||||||
type
|
type
|
||||||
GetoptResult* = tuple[kind: CmdLineKind, key, val: TaintedString]
|
GetoptResult* = tuple[kind: CmdLineKind, key, val: TaintedString]
|
||||||
|
|
|
||||||
|
|
@ -97,24 +97,27 @@ else:
|
||||||
from stdtest/specialpaths import buildDir
|
from stdtest/specialpaths import buildDir
|
||||||
import "../.." / compiler/unittest_light
|
import "../.." / compiler/unittest_light
|
||||||
|
|
||||||
block: # fix #9951
|
block: # fix #9951 (and make it work for parseopt and parseopt2)
|
||||||
var p = parseopt.initOptParser(@["echo \"quoted\""])
|
template runTest(parseoptCustom) =
|
||||||
|
var p = parseoptCustom.initOptParser(@["echo \"quoted\""])
|
||||||
let expected = when defined(windows):
|
let expected = when defined(windows):
|
||||||
""""echo \"quoted\"""""
|
""""echo \"quoted\"""""
|
||||||
else:
|
else:
|
||||||
"""'echo "quoted"'"""
|
"""'echo "quoted"'"""
|
||||||
assertEquals parseopt.cmdLineRest(p), expected
|
assertEquals parseoptCustom.cmdLineRest(p), expected
|
||||||
|
|
||||||
doAssert "a5'b" == "a5\'b"
|
doAssert "a5'b" == "a5\'b"
|
||||||
|
|
||||||
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
||||||
var p2 = parseopt.initOptParser(args)
|
var p2 = parseoptCustom.initOptParser(args)
|
||||||
let expected2 = when defined(windows):
|
let expected2 = when defined(windows):
|
||||||
"""a1b "a2 b" "" a4\"b a5'b a6\b a7'b"""
|
"""a1b "a2 b" "" a4\"b a5'b a6\b a7'b"""
|
||||||
else:
|
else:
|
||||||
"""a1b 'a2 b' '' 'a4"b' 'a5'"'"'b' 'a6\b' 'a7'"'"'b'"""
|
"""a1b 'a2 b' '' 'a4"b' 'a5'"'"'b' 'a6\b' 'a7'"'"'b'"""
|
||||||
doAssert "a5'b" == "a5\'b"
|
doAssert "a5'b" == "a5\'b"
|
||||||
assertEquals parseopt.cmdLineRest(p2), expected2
|
assertEquals parseoptCustom.cmdLineRest(p2), expected2
|
||||||
|
runTest(parseopt)
|
||||||
|
runTest(parseopt2)
|
||||||
|
|
||||||
block: # fix #9842
|
block: # fix #9842
|
||||||
let exe = buildDir / "D20190112T145450".addFileExt(ExeExt)
|
let exe = buildDir / "D20190112T145450".addFileExt(ExeExt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue