Skip to content

Commit

Permalink
Merge pull request #1583 from AndrejMitrovic/Fix9310
Browse files Browse the repository at this point in the history
Reintroduce missing test-cases for escapeShellCommand.
  • Loading branch information
dnadlinger committed Sep 18, 2013
2 parents 8e926a6 + 41ca4e8 commit 7222047
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions std/process.d
Expand Up @@ -2193,6 +2193,48 @@ string escapeShellCommand(in char[][] args...)
return escapeShellCommandString(escapeShellArguments(args));
}

unittest
{
// This is a simple unit test without any special requirements,
// in addition to the unittest_burnin one below which requires
// special preparation.

struct TestVector { string[] args; string windows, posix; }
TestVector[] tests =
[
{
args : ["foo"],
windows : `^"foo^"`,
posix : `'foo'`
},
{
args : ["foo", "hello"],
windows : `^"foo^" ^"hello^"`,
posix : `'foo' 'hello'`
},
{
args : ["foo", "hello world"],
windows : `^"foo^" ^"hello world^"`,
posix : `'foo' 'hello world'`
},
{
args : ["foo", "hello", "world"],
windows : `^"foo^" ^"hello^" ^"world^"`,
posix : `'foo' 'hello' 'world'`
},
{
args : ["foo", `'"^\`],
windows : `^"foo^" ^"'\^"^^\\^"`,
posix : `'foo' ''\''"^\'`
},
];

foreach (test; tests)
version (Windows)
assert(escapeShellCommand(test.args) == test.windows);
else
assert(escapeShellCommand(test.args) == test.posix );
}

private string escapeShellCommandString(string command)
//TODO: @safe pure nothrow
Expand Down

0 comments on commit 7222047

Please sign in to comment.