Skip to content

Commit 1c6976f

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 2df8043 commit 1c6976f

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
@@ -24,6 +24,7 @@ public class WorkspaceTests
2424
: string.Empty;
2525

2626
[Fact]
27+
[Trait("Category", "Workspace")]
2728
public void CanResolveWorkspaceRelativePath()
2829
{
2930
string workspacePath = TestUtilities.NormalizePath("c:/Test/Workspace/");
@@ -47,6 +48,42 @@ public void CanResolveWorkspaceRelativePath()
4748
}
4849

4950
[Fact]
51+
[Trait("Category", "Workspace")]
52+
public void CanRecurseDirectoryTree()
53+
{
54+
Workspace workspace = new Workspace(PowerShellVersion, Logging.NullLogger);
55+
workspace.WorkspacePath = TestUtilities.NormalizePath("Fixtures/Workspace");
56+
57+
IEnumerable<string> result = workspace.EnumeratePSFiles();
58+
List<string> fileList = new List<string>();
59+
foreach (string file in result) { fileList.Add(file); }
60+
// Assume order is not important from EnumeratePSFiles and sort the array so we can use deterministic asserts
61+
fileList.Sort();
62+
63+
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"))
64+
{
65+
// .Net Core doesn't appear to use the same three letter pattern matching rule although the docs
66+
// suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
67+
// 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_
68+
Assert.Equal(4, fileList.Count);
69+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "donotfind.ps1"), fileList[0]);
70+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psd1"), fileList[1]);
71+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psm1"), fileList[2]);
72+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[3]);
73+
}
74+
else
75+
{
76+
Assert.Equal(5, fileList.Count);
77+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "donotfind.ps1"), fileList[0]);
78+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psd1"), fileList[1]);
79+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"nested", "nestedmodule.psm1"), fileList[2]);
80+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"other", "other.ps1xml"), fileList[3]);
81+
Assert.Equal(Path.Combine(workspace.WorkspacePath,"rootfile.ps1"), fileList[4]);
82+
}
83+
}
84+
85+
[Fact]
86+
[Trait("Category", "Workspace")]
5087
public void CanDetermineIsPathInMemory()
5188
{
5289
string tempDir = Path.GetTempPath();
@@ -84,6 +121,7 @@ public void CanDetermineIsPathInMemory()
84121
}
85122

86123
[Theory()]
124+
[Trait("Category", "Workspace")]
87125
[MemberData(nameof(PathsToResolve), parameters: 2)]
88126
public void CorrectlyResolvesPaths(string givenPath, string expectedPath)
89127
{

0 commit comments

Comments
 (0)