Skip to content

Commit e07b5cd

Browse files
author
Robert Holt
committed
Add dot source tests for strange paths
1 parent 08c8ae3 commit e07b5cd

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function Hello
2+
{
3+
"Bye"
4+
}

test/PowerShellEditorServices.Test.Shared/scriptassets/NormalScript.ps1

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Windows won't let me put * or ? in the name of this file..."

test/PowerShellEditorServices.Test/Session/PathEscapingTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System;
22
using Xunit;
33
using Microsoft.PowerShell.EditorServices;
4+
using System.IO;
45

56
namespace Microsoft.PowerShell.EditorServices.Test.Session
67
{
78
public class PathEscapingTests
89
{
10+
private const string ScriptAssetPath = @"..\..\..\..\PowerShellEditorServices.Test.Shared\scriptassets";
11+
912
[Theory]
1013
[InlineData("DebugTest.ps1", "DebugTest.ps1")]
1114
[InlineData("../../DebugTest.ps1", "../../DebugTest.ps1")]
@@ -107,5 +110,23 @@ public void CorrectlyUnescapesPaths(string escapedPath, string expectedUnescaped
107110
string extensionUnescapedPath = PowerShellContext.UnescapeGlobEscapedPath(escapedPath);
108111
Assert.Equal(expectedUnescapedPath, extensionUnescapedPath);
109112
}
113+
114+
[Theory]
115+
[InlineData("NormalScript.ps1")]
116+
[InlineData("Bad&name4script.ps1")]
117+
[InlineData("[Truly] b&d Name_4_script.ps1")]
118+
public void CanDotSourcePath(string rawFileName)
119+
{
120+
string fullPath = Path.Combine(ScriptAssetPath, rawFileName);
121+
string quotedPath = PowerShellContext.QuoteEscapeString(fullPath);
122+
123+
var psCommand = new System.Management.Automation.PSCommand().AddScript($". {quotedPath}");
124+
125+
using (var pwsh = System.Management.Automation.PowerShell.Create())
126+
{
127+
pwsh.Commands = psCommand;
128+
pwsh.Invoke();
129+
}
130+
}
110131
}
111132
}

0 commit comments

Comments
 (0)