12
12
13
13
namespace Microsoft . PowerShell . EditorServices . Test . Session
14
14
{
15
+ [ Trait ( "Category" , "Workspace" ) ]
15
16
public class WorkspaceTests
16
17
{
17
18
private static readonly Lazy < string > s_lazyDriveLetter = new ( ( ) => Path . GetFullPath ( "\\ " ) . Substring ( 0 , 1 ) ) ;
@@ -21,7 +22,6 @@ public class WorkspaceTests
21
22
: string . Empty ;
22
23
23
24
[ Fact ]
24
- [ Trait ( "Category" , "Workspace" ) ]
25
25
public void CanResolveWorkspaceRelativePath ( )
26
26
{
27
27
string workspacePath = TestUtilities . NormalizePath ( "c:/Test/Workspace/" ) ;
@@ -64,95 +64,85 @@ internal static List<string> ExecuteEnumeratePSFiles(
64
64
string [ ] excludeGlobs ,
65
65
string [ ] includeGlobs ,
66
66
int maxDepth ,
67
- bool ignoreReparsePoints
68
- )
67
+ bool ignoreReparsePoints )
69
68
{
70
- IEnumerable < string > result = workspace . EnumeratePSFiles (
69
+ List < string > fileList = new ( workspace . EnumeratePSFiles (
71
70
excludeGlobs : excludeGlobs ,
72
71
includeGlobs : includeGlobs ,
73
72
maxDepth : maxDepth ,
74
73
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
+ ) ) ;
80
75
76
+ // Assume order is not important from EnumeratePSFiles and sort the array so we can use
77
+ // deterministic asserts
78
+ fileList . Sort ( ) ;
81
79
return fileList ;
82
80
}
83
81
84
82
[ Fact ]
85
- [ Trait ( "Category" , "Workspace" ) ]
86
83
public void CanRecurseDirectoryTree ( )
87
84
{
88
85
WorkspaceService workspace = FixturesWorkspace ( ) ;
89
- List < string > fileList = ExecuteEnumeratePSFiles (
86
+ List < string > actual = ExecuteEnumeratePSFiles (
90
87
workspace : workspace ,
91
88
excludeGlobs : s_defaultExcludeGlobs ,
92
89
includeGlobs : s_defaultIncludeGlobs ,
93
90
maxDepth : s_defaultMaxDepth ,
94
91
ignoreReparsePoints : s_defaultIgnoreReparsePoints
95
92
) ;
96
93
97
- if ( ! RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" ) )
94
+ List < string > expected = new ( )
98
95
{
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" ) )
109
106
{
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" ) ) ;
116
108
}
109
+
110
+ Assert . Equal ( expected , actual ) ;
117
111
}
118
112
119
113
[ Fact ]
120
- [ Trait ( "Category" , "Workspace" ) ]
121
114
public void CanRecurseDirectoryTreeWithLimit ( )
122
115
{
123
116
WorkspaceService workspace = FixturesWorkspace ( ) ;
124
- List < string > fileList = ExecuteEnumeratePSFiles (
117
+ List < string > actual = ExecuteEnumeratePSFiles (
125
118
workspace : workspace ,
126
119
excludeGlobs : s_defaultExcludeGlobs ,
127
120
includeGlobs : s_defaultIncludeGlobs ,
128
121
maxDepth : 1 ,
129
122
ignoreReparsePoints : s_defaultIgnoreReparsePoints
130
123
) ;
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 ) ;
134
125
}
135
126
136
127
[ Fact ]
137
- [ Trait ( "Category" , "Workspace" ) ]
138
128
public void CanRecurseDirectoryTreeWithGlobs ( )
139
129
{
140
130
WorkspaceService workspace = FixturesWorkspace ( ) ;
141
- List < string > fileList = ExecuteEnumeratePSFiles (
131
+ List < string > actual = ExecuteEnumeratePSFiles (
142
132
workspace : workspace ,
143
- excludeGlobs : new [ ] { "**/donotfind*" } , // Exclude any files starting with donotfind
133
+ excludeGlobs : new [ ] { "**/donotfind*" } , // Exclude any files starting with donotfind
144
134
includeGlobs : new [ ] { "**/*.ps1" , "**/*.psd1" } , // Only include PS1 and PSD1 files
145
135
maxDepth : s_defaultMaxDepth ,
146
136
ignoreReparsePoints : s_defaultIgnoreReparsePoints
147
137
) ;
148
138
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 ) ;
152
143
}
153
144
154
145
[ Fact ]
155
- [ Trait ( "Category" , "Workspace" ) ]
156
146
public void CanDetermineIsPathInMemory ( )
157
147
{
158
148
string tempDir = Path . GetTempPath ( ) ;
@@ -161,32 +151,29 @@ public void CanDetermineIsPathInMemory()
161
151
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" ;
162
152
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" ;
163
153
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 [ ] {
175
155
// 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
+ } ;
179
162
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" } )
182
174
} ;
183
175
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 ) ) ) ;
190
177
}
191
178
}
192
179
}
0 commit comments