1212
1313namespace Microsoft . PowerShell . EditorServices . Test . Session
1414{
15+ [ Trait ( "Category" , "Workspace" ) ]
1516 public class WorkspaceTests
1617 {
1718 private static readonly Lazy < string > s_lazyDriveLetter = new ( ( ) => Path . GetFullPath ( "\\ " ) . Substring ( 0 , 1 ) ) ;
@@ -21,7 +22,6 @@ public class WorkspaceTests
2122 : string . Empty ;
2223
2324 [ Fact ]
24- [ Trait ( "Category" , "Workspace" ) ]
2525 public void CanResolveWorkspaceRelativePath ( )
2626 {
2727 string workspacePath = TestUtilities . NormalizePath ( "c:/Test/Workspace/" ) ;
@@ -64,95 +64,85 @@ internal static List<string> ExecuteEnumeratePSFiles(
6464 string [ ] excludeGlobs ,
6565 string [ ] includeGlobs ,
6666 int maxDepth ,
67- bool ignoreReparsePoints
68- )
67+ bool ignoreReparsePoints )
6968 {
70- IEnumerable < string > result = workspace . EnumeratePSFiles (
69+ List < string > fileList = new ( workspace . EnumeratePSFiles (
7170 excludeGlobs : excludeGlobs ,
7271 includeGlobs : includeGlobs ,
7372 maxDepth : maxDepth ,
7473 ignoreReparsePoints : ignoreReparsePoints
75- ) ;
76- List < string > fileList = new ( ) ;
77- fileList . AddRange ( result ) ;
78- // Assume order is not important from EnumeratePSFiles and sort the array so we can use deterministic asserts
79- fileList . Sort ( ) ;
74+ ) ) ;
8075
76+ // Assume order is not important from EnumeratePSFiles and sort the array so we can use
77+ // deterministic asserts
78+ fileList . Sort ( ) ;
8179 return fileList ;
8280 }
8381
8482 [ Fact ]
85- [ Trait ( "Category" , "Workspace" ) ]
8683 public void CanRecurseDirectoryTree ( )
8784 {
8885 WorkspaceService workspace = FixturesWorkspace ( ) ;
89- List < string > fileList = ExecuteEnumeratePSFiles (
86+ List < string > actual = ExecuteEnumeratePSFiles (
9087 workspace : workspace ,
9188 excludeGlobs : s_defaultExcludeGlobs ,
9289 includeGlobs : s_defaultIncludeGlobs ,
9390 maxDepth : s_defaultMaxDepth ,
9491 ignoreReparsePoints : s_defaultIgnoreReparsePoints
9592 ) ;
9693
97- if ( ! RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
94+ List < string > expected = new ( )
9895 {
99- // .Net Core doesn't appear to use the same three letter pattern matching rule although the docs
100- // suggest it should be find the '.ps1xml' files because we search for the pattern '*.ps1'
101- // 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_
102- Assert . Equal ( 4 , fileList . Count ) ;
103- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "donotfind.ps1" ) , fileList [ 0 ] ) ;
104- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psd1" ) , fileList [ 1 ] ) ;
105- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psm1" ) , fileList [ 2 ] ) ;
106- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "rootfile .ps1" ) , fileList [ 3 ] ) ;
107- }
108- else
96+ Path . Combine ( workspace . WorkspacePath , "nested" , "donotfind.ps1" ) ,
97+ Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psd1" ) ,
98+ Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psm1" ) ,
99+ Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" )
100+ } ;
101+
102+ // .NET Core doesn't appear to use the same three letter pattern matching rule although the docs
103+ // suggest it should be find the '.ps1xml' files because we search for the pattern '* .ps1'
104+ // 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_
105+ if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
109106 {
110- Assert . Equal ( 5 , fileList . Count ) ;
111- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "donotfind.ps1" ) , fileList [ 0 ] ) ;
112- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psd1" ) , fileList [ 1 ] ) ;
113- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psm1" ) , fileList [ 2 ] ) ;
114- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "other" , "other.ps1xml" ) , fileList [ 3 ] ) ;
115- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" ) , fileList [ 4 ] ) ;
107+ expected . Insert ( 3 , Path . Combine ( workspace . WorkspacePath , "other" , "other.ps1xml" ) ) ;
116108 }
109+
110+ Assert . Equal ( expected , actual ) ;
117111 }
118112
119113 [ Fact ]
120- [ Trait ( "Category" , "Workspace" ) ]
121114 public void CanRecurseDirectoryTreeWithLimit ( )
122115 {
123116 WorkspaceService workspace = FixturesWorkspace ( ) ;
124- List < string > fileList = ExecuteEnumeratePSFiles (
117+ List < string > actual = ExecuteEnumeratePSFiles (
125118 workspace : workspace ,
126119 excludeGlobs : s_defaultExcludeGlobs ,
127120 includeGlobs : s_defaultIncludeGlobs ,
128121 maxDepth : 1 ,
129122 ignoreReparsePoints : s_defaultIgnoreReparsePoints
130123 ) ;
131-
132- Assert . Single ( fileList ) ;
133- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" ) , fileList [ 0 ] ) ;
124+ Assert . Equal ( new [ ] { Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" ) } , actual ) ;
134125 }
135126
136127 [ Fact ]
137- [ Trait ( "Category" , "Workspace" ) ]
138128 public void CanRecurseDirectoryTreeWithGlobs ( )
139129 {
140130 WorkspaceService workspace = FixturesWorkspace ( ) ;
141- List < string > fileList = ExecuteEnumeratePSFiles (
131+ List < string > actual = ExecuteEnumeratePSFiles (
142132 workspace : workspace ,
143- excludeGlobs : new [ ] { "**/donotfind*" } , // Exclude any files starting with donotfind
133+ excludeGlobs : new [ ] { "**/donotfind*" } , // Exclude any files starting with donotfind
144134 includeGlobs : new [ ] { "**/*.ps1" , "**/*.psd1" } , // Only include PS1 and PSD1 files
145135 maxDepth : s_defaultMaxDepth ,
146136 ignoreReparsePoints : s_defaultIgnoreReparsePoints
147137 ) ;
148138
149- Assert . Equal ( 2 , fileList . Count ) ;
150- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psd1" ) , fileList [ 0 ] ) ;
151- Assert . Equal ( Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" ) , fileList [ 1 ] ) ;
139+ Assert . Equal ( new [ ] {
140+ Path . Combine ( workspace . WorkspacePath , "nested" , "nestedmodule.psd1" ) ,
141+ Path . Combine ( workspace . WorkspacePath , "rootfile.ps1" )
142+ } , actual ) ;
152143 }
153144
154145 [ Fact ]
155- [ Trait ( "Category" , "Workspace" ) ]
156146 public void CanDetermineIsPathInMemory ( )
157147 {
158148 string tempDir = Path . GetTempPath ( ) ;
@@ -161,32 +151,29 @@ public void CanDetermineIsPathInMemory()
161151 const string shortUriForm = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D" ;
162152 const string longUriForm = "gitlens-git:c%3A%5CUsers%5CKeith%5CGitHub%5Cdahlbyk%5Cposh-git%5Csrc%5CPoshGitTypes%3Ae0022701.ps1?%7B%22fileName%22%3A%22src%2FPoshGitTypes.ps1%22%2C%22repoPath%22%3A%22c%3A%2FUsers%2FKeith%2FGitHub%2Fdahlbyk%2Fposh-git%22%2C%22sha%22%3A%22e0022701fa12e0bc22d0458673d6443c942b974a%22%7D" ;
163153
164- var testCases = new [ ] {
165- // Test short file absolute paths
166- new { IsInMemory = false , Path = shortDirPath } ,
167- new { IsInMemory = false , Path = shortFilePath } ,
168- new { IsInMemory = false , Path = new Uri ( shortDirPath ) . ToString ( ) } ,
169- new { IsInMemory = false , Path = new Uri ( shortFilePath ) . ToString ( ) } ,
170-
171- // Test short file relative paths - not sure we'll ever get these but just in case
172- new { IsInMemory = false , Path = "foo.ps1" } ,
173- new { IsInMemory = false , Path = Path . Combine ( new [ ] { ".." , "foo.ps1" } ) } ,
174-
154+ string [ ] inMemoryPaths = new [ ] {
175155 // Test short non-file paths
176- new { IsInMemory = true , Path = "untitled:untitled-1" } ,
177- new { IsInMemory = true , Path = shortUriForm } ,
178- new { IsInMemory = true , Path = "inmemory://foo.ps1" } ,
156+ "untitled:untitled-1" ,
157+ shortUriForm ,
158+ "inmemory://foo.ps1" ,
159+ // Test long non-file path
160+ longUriForm
161+ } ;
179162
180- // Test long non-file path - known to have crashed PSES
181- new { IsInMemory = true , Path = longUriForm } ,
163+ Assert . All ( inMemoryPaths , ( p ) => Assert . True ( WorkspaceService . IsPathInMemory ( p ) ) ) ;
164+
165+ string [ ] notInMemoryPaths = new [ ] {
166+ // Test short file absolute paths
167+ shortDirPath ,
168+ shortFilePath ,
169+ new Uri ( shortDirPath ) . ToString ( ) ,
170+ new Uri ( shortFilePath ) . ToString ( ) ,
171+ // Test short file relative paths
172+ "foo.ps1" ,
173+ Path . Combine ( new [ ] { ".." , "foo.ps1" } )
182174 } ;
183175
184- foreach ( var testCase in testCases )
185- {
186- Assert . True (
187- WorkspaceService . IsPathInMemory ( testCase . Path ) == testCase . IsInMemory ,
188- $ "Testing path { testCase . Path } ") ;
189- }
176+ Assert . All ( notInMemoryPaths , ( p ) => Assert . False ( WorkspaceService . IsPathInMemory ( p ) ) ) ;
190177 }
191178 }
192179}
0 commit comments