Use a variable instead of a file for testing args

* Use a variable (which can be indexed by line) instead of a file to
  test the output of arguments passed to echoargs
* Add comments explaining the tests
This commit is contained in:
Douglas Thrift committed 2016-09-13 13:37:42 -07:00
1 parent 4d5d0a0034
commit ddf30c4008
1 file changed
+27 -8
@@ -1,22 +1,41 @@
Describe "Native Command Arguments" -tags "CI" { Describe "Native Command Arguments" -tags "CI" {
$testPath = 'TestDrive:\test.txt' # Find where test/powershell is so we can find the echoargs command relative to it
$powershellTestDir = $PSScriptRoot $powershellTestDir = $PSScriptRoot
while ($powershellTestDir -notmatch 'test[\\/]powershell$') { while ($powershellTestDir -notmatch 'test[\\/]powershell$') {
$powershellTestDir = Split-Path $powershellTestDir $powershellTestDir = Split-Path $powershellTestDir
} }
$echoArgs = Join-Path (Split-Path $powershellTestDir) tools/EchoArgs/bin/echoargs $echoArgs = Join-Path (Split-Path $powershellTestDir) tools/EchoArgs/bin/echoargs
# When passing arguments to native commands, quoted segments that contain
# spaces need to be quoted with '"' characters when they are passed to the
# native command (or to bash or sh on Linux).
#
# This test checks that the proper quoting is occuring by passing arguments
# to the echoargs native command and looking at how it got the arguments.
It "Should handle quoted spaces correctly" { It "Should handle quoted spaces correctly" {
$a = 'a"b c"d' $a = 'a"b c"d'
& $echoArgs $a 'a"b c"d' a"b c"d >$testPath $lines = & $echoArgs $a 'a"b c"d' a"b c"d
$testPath | Should Contain 'Arg 0 is <ab cd>' ($lines | measure).Count | Should Be 3
$testPath | Should Contain 'Arg 1 is <ab cd>' $lines[0] | Should Be 'Arg 0 is <ab cd>'
$testPath | Should Contain 'Arg 2 is <ab cd>' $lines[1] | Should Be 'Arg 1 is <ab cd>'
$lines[2] | Should Be 'Arg 2 is <ab cd>'
} }
# In order to pass '"' characters so they are actually part of command line
# arguments for native commands, they need to be escaped with a '\' (this
# is in addition to the '`' escaping needed inside '"' quoted strings in
# PowerShell).
#
# This functionality was broken in PowerShell 5.0 and 5.1, so this test
# will fail on those versions unless the fix is backported to them.
#
# This test checks that the proper quoting and escaping is occurring by
# passing arguments with escaped quotes to the echoargs native command and
# looking at how it got the arguments.
It "Should handle spaces between escaped quotes" { It "Should handle spaces between escaped quotes" {
& $echoArgs 'a\"b c\"d' "a\`"b c\`"d" >$testPath $lines = & $echoArgs 'a\"b c\"d' "a\`"b c\`"d"
$testPath | Should Contain 'Arg 0 is <a"b c"d>' ($lines | measure).Count | Should Be 2
$testPath | Should Contain 'Arg 1 is <a"b c"d>' $lines[0] | Should Be 'Arg 0 is <a"b c"d>'
$lines[1] | Should Be 'Arg 1 is <a"b c"d>'
} }
} }