From 7816516c244627da2054140dc569e2dce08336cb Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Sun, 11 Sep 2016 21:13:14 -0700 Subject: [PATCH] Add tests for native command arguments --- test/EchoArgs/EchoArgs.cs | 28 +++++++++++++++++ test/EchoArgs/project.json | 28 +++++++++++++++++ .../NativeCommandArguments.Tests.ps1 | 31 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 test/EchoArgs/EchoArgs.cs create mode 100644 test/EchoArgs/project.json create mode 100644 test/powershell/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 diff --git a/test/EchoArgs/EchoArgs.cs b/test/EchoArgs/EchoArgs.cs new file mode 100644 index 000000000..88d0f5e40 --- /dev/null +++ b/test/EchoArgs/EchoArgs.cs @@ -0,0 +1,28 @@ +//--------------------------------------------------------------------- +// Author: Keith Hill +// +// Description: Very simple little console class that you can use to see +// how PowerShell is passing parameters to legacy console +// apps. +// +// Creation Date: March 06, 2006 +//--------------------------------------------------------------------- +using System; + +namespace Pscx.Applications +{ + class EchoArgs + { + static void Main(string[] args) + { + for (int i = 0; i < args.Length; i++) + { + Console.WriteLine("Arg {0} is <{1}>", i, args[i]); + } + + /*Console.WriteLine("\nCommand line:"); + Console.WriteLine(Environment.CommandLine);*/ + Console.WriteLine(); + } + } +} diff --git a/test/EchoArgs/project.json b/test/EchoArgs/project.json new file mode 100644 index 000000000..106dcc46a --- /dev/null +++ b/test/EchoArgs/project.json @@ -0,0 +1,28 @@ +{ + "name": "echoargs", + "version": "1.0.0-*", + "description": "Very simple little console class that you can use to see how PowerShell is passing parameters to legacy console apps.", + + "buildOptions": { + "emitEntryPoint": true + }, + + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": "1.0.0" + } + } + }, + + "runtimes": { + "ubuntu.16.04-x64": { }, + "ubuntu.14.04-x64": { }, + "debian.8-x64": { }, + "centos.7-x64": { }, + "win7-x64": { }, + "win81-x64": { }, + "win10-x64": { }, + "osx.10.11-x64": { } + } +} diff --git a/test/powershell/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 b/test/powershell/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 new file mode 100644 index 000000000..bf26060cd --- /dev/null +++ b/test/powershell/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 @@ -0,0 +1,31 @@ +Describe "Native Command Arguments" -tags "CI" { + $testPath = 'TestDrive:\test.txt' + $powershellTestDir = $PSScriptRoot + while ($powershellTestDir -notmatch 'test[\\/]powershell$') { + $powershellTestDir = Split-Path $powershellTestDir + } + $echoArgsDir = Join-Path (Split-Path $powershellTestDir) EchoArgs + + function Start-EchoArgs { + Push-Location $echoArgsDir + try { + dotnet run $args + } finally { + Pop-Location + } + } + + It "Should handle quoted spaces correctly" { + $a = 'a"b c"d' + Start-EchoArgs $a 'a"b c"d' a"b c"d >$testPath + $testPath | Should Contain 'Arg 0 is ' + $testPath | Should Contain 'Arg 1 is ' + $testPath | Should Contain 'Arg 2 is ' + } + + It "Should handle spaces between escaped quotes" { + Start-EchoArgs 'a\"b c\"d' "a\`"b c\`"d" >$testPath + $testPath | Should Contain 'Arg 0 is ' + $testPath | Should Contain 'Arg 1 is ' + } +}