Skip to content

Commit cc2fda0

Browse files
committed
(PowerShellGH-879) Add characterisation tests for Workspace.EnumeratePSFiles
Previosly there were no tests for the Workspace.EnumeratePSFiles method. This commit adds tests for EnumeratePSFiles method using a set of static fixture test files. Note that the behaviour of EnumeratePSFiles changes depending on the .Net Framework edition
1 parent 13d8f8a commit cc2fda0

File tree

11 files changed

+52
-0
lines changed

11 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# donotfind.ps1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
donotfind.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# nestedmodule.psd1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# nestedmodule.psm1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- other.cdxml -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- other.ps1xml -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# other.psrc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# other.pssc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# rootfile.ps1

test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<ItemGroup>
2828
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
2929
</ItemGroup>
30+
<ItemGroup>
31+
<None Include="Fixtures\**">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</None>
34+
</ItemGroup>
3035
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
3136
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
3237
</PropertyGroup>

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

+38
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class WorkspaceTests
1818
private static readonly Version PowerShellVersion = new Version("5.0");
1919

2020
[Fact]
21+
[Trait("Category", "Workspace")]
2122
public void CanResolveWorkspaceRelativePath()
2223
{
2324
string workspacePath = TestUtilities.NormalizePath("c:/Test/Workspace/");
@@ -41,6 +42,42 @@ public void CanResolveWorkspaceRelativePath()
4142
}
4243

4344
[Fact]
45+
[Trait("Category", "Workspace")]
46+
public void CanRecurseDirectoryTree()
47+
{
48+
Workspace workspace = new Workspace(PowerShellVersion, Logging.NullLogger);
49+
workspace.WorkspacePath = TestUtilities.NormalizePath("Fixtures/Workspace");
50+
51+
IEnumerable<string> result = workspace.EnumeratePSFiles();
52+
List<string> fileList = new List<string>();
53+
foreach (string file in result) { fileList.Add(file); }
54+
// Assume order is not important from EnumeratePSFiles and sort the array so we can use deterministic asserts
55+
fileList.Sort();
56+
57+
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"))
58+
{
59+
// .Net Core doesn't appear to use the same three letter pattern matching rule although the docs
60+
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
61+
// ref https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netcore-2.1#System_IO_Directory_GetFiles_System_String_System_String_System_IO_EnumerationOptions_
62+
Assert.Equal(4, fileList.Count);
63+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "donotfind.ps1"), fileList[0]);
64+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psd1"), fileList[1]);
65+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psm1"), fileList[2]);
66+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[3]);
67+
}
68+
else
69+
{
70+
Assert.Equal(5, fileList.Count);
71+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "donotfind.ps1"), fileList[0]);
72+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psd1"), fileList[1]);
73+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psm1"), fileList[2]);
74+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"other", "other.ps1xml"), fileList[3]);
75+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[4]);
76+
}
77+
}
78+
79+
[Fact]
80+
[Trait("Category", "Workspace")]
4481
public void CanDetermineIsPathInMemory()
4582
{
4683
string tempDir = Path.GetTempPath();
@@ -78,6 +115,7 @@ public void CanDetermineIsPathInMemory()
78115
}
79116

80117
[Theory()]
118+
[Trait("Category", "Workspace")]
81119
[MemberData(nameof(PathsToResolve), parameters: 2)]
82120
public void CorrectlyResolvesPaths(string givenPath, string expectedPath)
83121
{

0 commit comments

Comments
 (0)