From 6060fd0804234b4a5ead26327953a6cd60c6cf3f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 15:24:25 -0700 Subject: [PATCH 01/44] Add ability for searcher to search for commands using either wildcards in path or not using wildcards in the path. --- .../engine/CommandSearcher.cs | 102 +++++++++++------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index f3f29a514c0..13d4d593c3f 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -459,49 +459,61 @@ private CommandInfo GetNextFromPath() Collection resolvedPaths = new Collection(); - try - { - Provider.CmdletProvider providerInstance; - ProviderInfo provider; - resolvedPaths = - _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(_commandName, false, out provider, out providerInstance); - } - catch (ItemNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The path could not be found: {0}", - _commandName); - } - catch (DriveNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "A drive could not be found for the path: {0}", - _commandName); - } - catch (ProviderNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "A provider could not be found for the path: {0}", - _commandName); - } - catch (InvalidOperationException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The path specified a home directory, but the provider home directory was not set. {0}", - _commandName); - } - catch (ProviderInvocationException providerException) + ProviderInfo provider; + if ((_commandResolutionOptions & SearchResolutionOptions.ResolvePathPatterns) != 0 && + WildcardPattern.ContainsWildcardCharacters(_commandName)) { - CommandDiscovery.discoveryTracer.TraceError( - "The provider associated with the path '{0}' encountered an error: {1}", - _commandName, - providerException.Message); + try + { + Provider.CmdletProvider providerInstance; + resolvedPaths = + _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(_commandName, false, out provider, out providerInstance); + } + catch (ItemNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The path could not be found: {0}", + _commandName); + } + catch (DriveNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "A drive could not be found for the path: {0}", + _commandName); + } + catch (ProviderNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "A provider could not be found for the path: {0}", + _commandName); + } + catch (InvalidOperationException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The path specified a home directory, but the provider home directory was not set. {0}", + _commandName); + } + catch (ProviderInvocationException providerException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The provider associated with the path '{0}' encountered an error: {1}", + _commandName, + providerException.Message); + } + catch (PSNotSupportedException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The provider associated with the path '{0}' does not implement ContainerCmdletProvider", + _commandName); + } } - catch (PSNotSupportedException) + + if ((resolvedPaths == null)) { - CommandDiscovery.discoveryTracer.TraceError( - "The provider associated with the path '{0}' does not implement ContainerCmdletProvider", - _commandName); + string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); + var temp = new System.Collections.ObjectModel.Collection(); + temp.Add(path); + resolvedPaths = temp; } if (resolvedPaths.Count > 1) @@ -1092,7 +1104,8 @@ private string ResolvePSPath(string path) { ProviderInfo provider = null; string resolvedPath = null; - if (WildcardPattern.ContainsWildcardCharacters(path)) + if ((_commandResolutionOptions & SearchResolutionOptions.ResolvePathPatterns) != 0 && + WildcardPattern.ContainsWildcardCharacters(path)) { // Let PowerShell resolve relative path with wildcards. Provider.CmdletProvider providerInstance; @@ -1456,6 +1469,7 @@ private void setupPathSearcher() // path lookup for relative paths. string directory = Path.GetDirectoryName(_commandName); + // Not using directory = ResolvePSPath(directory); CommandDiscovery.discoveryTracer.WriteLine( @@ -1609,5 +1623,11 @@ internal enum SearchResolutionOptions /// Enable searching for cmdlets/functions by abbreviation expansion. /// UseAbbreviationExpansion = 0x20, + + /// + /// Enable resolving wildcard in paths. + /// + ResolvePathPatterns = 0x40, + } } From 234335732bd3670a2c1063f2ad4257b39094fb70 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 15:24:53 -0700 Subject: [PATCH 02/44] make get-command tell command searcher to use wildcards when searching path --- src/System.Management.Automation/engine/GetCommandCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index 832134039e1..dcd977d3015 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -704,7 +704,7 @@ private void AccumulateMatchingCommands(IEnumerable commandNames) { // First set the search options - SearchResolutionOptions options = SearchResolutionOptions.None; + SearchResolutionOptions options = SearchResolutionOptions.ResolvePathPatterns; if (All) { options = SearchResolutionOptions.SearchAllScopes; From 5e0523feeb9bd44258130b0a04db392ea203ff0c Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 15:27:03 -0700 Subject: [PATCH 03/44] Add tests for the various cases --- .../engine/Basic/CommandDiscovery.Tests.ps1 | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 4b9be7a736b..9a3b4151ff7 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -85,6 +85,41 @@ Describe "Command Discovery tests" -Tags "CI" { (& 'location').Path | Should -Be (get-location).Path } + Context "Use literal path when executing scripts" { + BeforeAll { + $firstResult = 'first script' + $secondResult = 'alt script' + setup -f '[test1].ps1' -content "'$firstResult'" + setup -f '1.ps1' -content "'$secondResult'" + + $executionWithWildcardCases = @( + @{command = '.\[test1].ps1' ; expectedResult = $firstResult} + @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult} + ) + + $shouldNotExecuteCases = @( + @{command = '.\[12].ps1'; testName = 'relative path with bracket wildcard matctching one file'} + @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching one file'} + ) + + Push-Location ${TestDrive}\ + } + + AfterAll { + Pop-Location + } + + It "Invoking should return ''" -TestCases $executionWithWildcardCases { + param($command, $expectedResult) + & $command | Should -BeExactly $expectedResult + } + + It "'' should not execute" -TestCases $shouldNotExecuteCases { + param($command) + { & $command } | Should -Throw -ErrorId 'CommandNotFoundException' + } + } + Context "Get-Command should use globbing for scripts" { BeforeAll { $firstResult = '[first script]' From 9b8f2f874fe2a0a402ecb4cc8676a194c94d0d6e Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 16:03:34 -0700 Subject: [PATCH 04/44] Address Paul's comments --- .../engine/CommandSearcher.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 13d4d593c3f..78899c62967 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -508,12 +508,12 @@ private CommandInfo GetNextFromPath() } } + // Try literal path resolution if wildcards are disable or wildcard search failed if ((resolvedPaths == null)) { string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); - var temp = new System.Collections.ObjectModel.Collection(); - temp.Add(path); - resolvedPaths = temp; + result = GetInfoFromPath(path); + return result; } if (resolvedPaths.Count > 1) @@ -1137,7 +1137,7 @@ private string ResolvePSPath(string path) } } - // Revert to previous path resolver if wildcards produces no results. + // Try literal path resolution if wildcards are disable or wildcard search failed if ((resolvedPath == null) || (provider == null)) { resolvedPath = _context.LocationGlobber.GetProviderPath(path, out provider); @@ -1469,7 +1469,6 @@ private void setupPathSearcher() // path lookup for relative paths. string directory = Path.GetDirectoryName(_commandName); - // Not using directory = ResolvePSPath(directory); CommandDiscovery.discoveryTracer.WriteLine( From 38f0111a032b7c841831f407d54194e30416079f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 16:03:47 -0700 Subject: [PATCH 05/44] make test names static --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 9a3b4151ff7..5b35e1755a6 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -93,8 +93,8 @@ Describe "Command Discovery tests" -Tags "CI" { setup -f '1.ps1' -content "'$secondResult'" $executionWithWildcardCases = @( - @{command = '.\[test1].ps1' ; expectedResult = $firstResult} - @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult} + @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} + @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} ) $shouldNotExecuteCases = @( @@ -109,7 +109,7 @@ Describe "Command Discovery tests" -Tags "CI" { Pop-Location } - It "Invoking should return ''" -TestCases $executionWithWildcardCases { + It "Invoking should return ''" -TestCases $executionWithWildcardCases { param($command, $expectedResult) & $command | Should -BeExactly $expectedResult } From f143e17bccbc35d6182b7d9c39700c1948048816 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 18 Mar 2019 16:18:15 -0700 Subject: [PATCH 06/44] Address Paul's comments (some offline) --- src/System.Management.Automation/engine/CommandSearcher.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 78899c62967..7587c5fcf52 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -512,8 +512,8 @@ private CommandInfo GetNextFromPath() if ((resolvedPaths == null)) { string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); - result = GetInfoFromPath(path); - return result; + resolvedPaths = new System.Collections.ObjectModel.Collection(); + resolvedPaths.Add(path); } if (resolvedPaths.Count > 1) From ffc4ce192ade8e171f654a48123bc674fa3378ea Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 22 Mar 2019 11:16:01 -0700 Subject: [PATCH 07/44] start using `HasFlag` --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 7587c5fcf52..8212c857731 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1104,7 +1104,7 @@ private string ResolvePSPath(string path) { ProviderInfo provider = null; string resolvedPath = null; - if ((_commandResolutionOptions & SearchResolutionOptions.ResolvePathPatterns) != 0 && + if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolvePathPatterns) && WildcardPattern.ContainsWildcardCharacters(path)) { // Let PowerShell resolve relative path with wildcards. From 539a0d0b4c1c8af8f62f17380c114f43e7672e5f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 22 Mar 2019 11:22:42 -0700 Subject: [PATCH 08/44] start using `HasFlag` in second location --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 8212c857731..f534efbbd54 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -460,7 +460,7 @@ private CommandInfo GetNextFromPath() Collection resolvedPaths = new Collection(); ProviderInfo provider; - if ((_commandResolutionOptions & SearchResolutionOptions.ResolvePathPatterns) != 0 && + if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolvePathPatterns) && WildcardPattern.ContainsWildcardCharacters(_commandName)) { try From f79768b3a8845f12d59e4d9eba235c9fbf119a21 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 22 Mar 2019 11:32:11 -0700 Subject: [PATCH 09/44] Fix CodeFactor issues --- src/System.Management.Automation/engine/CommandSearcher.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index f534efbbd54..60b1171fdc8 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -509,7 +509,7 @@ private CommandInfo GetNextFromPath() } // Try literal path resolution if wildcards are disable or wildcard search failed - if ((resolvedPaths == null)) + if (resolvedPaths == null) { string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); resolvedPaths = new System.Collections.ObjectModel.Collection(); @@ -1627,6 +1627,5 @@ internal enum SearchResolutionOptions /// Enable resolving wildcard in paths. /// ResolvePathPatterns = 0x40, - } } From cdbf1e92a667b124c3d834dcd33581cb2bdc48cc Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 22 Mar 2019 13:40:44 -0700 Subject: [PATCH 10/44] Fix check in fullPath codePath --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 60b1171fdc8..09ea960fd8f 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -509,7 +509,7 @@ private CommandInfo GetNextFromPath() } // Try literal path resolution if wildcards are disable or wildcard search failed - if (resolvedPaths == null) + if (resolvedPaths.Count == 0) { string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); resolvedPaths = new System.Collections.ObjectModel.Collection(); From 4688ae870c3e1859ccac5166487735afb9bde65b Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 22 Mar 2019 14:14:05 -0700 Subject: [PATCH 11/44] Don't recreate resolvedPaths --- src/System.Management.Automation/engine/CommandSearcher.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 09ea960fd8f..63a1a1b9d9c 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -512,7 +512,6 @@ private CommandInfo GetNextFromPath() if (resolvedPaths.Count == 0) { string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); - resolvedPaths = new System.Collections.ObjectModel.Collection(); resolvedPaths.Add(path); } From bc8330804ddea58b07b890f218b5a42bb5bdbd40 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 19:05:38 -0700 Subject: [PATCH 12/44] Add -wait to start-pspester --- build.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index c61750c9ec6..4649ab42058 100644 --- a/build.psm1 +++ b/build.psm1 @@ -907,7 +907,8 @@ function Start-PSPester { [switch]$IncludeCommonTests, [string]$ExperimentalFeatureName, [Parameter(HelpMessage='Title to publish the results as.')] - [string]$Title = 'PowerShell Core Tests' + [string]$Title = 'PowerShell Core Tests', + [switch]$Wait ) if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge "4.2" } )) @@ -1100,6 +1101,9 @@ function Start-PSPester { Set-Content -Path $configFile -Value $content -Encoding Ascii -Force $PSFlags = @("-settings", $configFile, "-noprofile") } + if($Wait.IsPresent){ + $PSFlags += '-wait' + } # To ensure proper testing, the module path must not be inherited by the spawned process try { From 74ee28b7de9bee9bd3ef6dab2e32e0f349e31cee Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 19:05:55 -0700 Subject: [PATCH 13/44] make changes that committee asked for --- .../engine/CommandDiscovery.cs | 2 +- .../engine/CommandSearcher.cs | 159 +++++++++++------- .../engine/GetCommandCommand.cs | 2 +- .../engine/Basic/CommandDiscovery.Tests.ps1 | 6 +- 4 files changed, 103 insertions(+), 66 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 5ad7717f084..2d557c46901 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -735,7 +735,7 @@ internal CommandInfo LookupCommandInfo(string commandName, CommandOrigin command internal static CommandInfo LookupCommandInfo(string commandName, CommandOrigin commandOrigin, ExecutionContext context) { - return LookupCommandInfo(commandName, CommandTypes.All, SearchResolutionOptions.None, commandOrigin, context); + return LookupCommandInfo(commandName, CommandTypes.All, SearchResolutionOptions.ResolveLiteralThenPathPatterns, commandOrigin, context); } internal static CommandInfo LookupCommandInfo( diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 63a1a1b9d9c..c49bdd58a99 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -457,62 +457,28 @@ private CommandInfo GetNextFromPath() // Find the match if it is. - Collection resolvedPaths = new Collection(); - ProviderInfo provider; - if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolvePathPatterns) && + + // Try literal path resolution if it is set to run first + if(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) + { + string path = GetNextLiteralPathThatExists(_commandName, out provider); + return GetInfoFromPath(path); + } + + Collection resolvedPaths = new Collection(); + if (resolvedPaths.Count == 0 && WildcardPattern.ContainsWildcardCharacters(_commandName)) { - try - { - Provider.CmdletProvider providerInstance; - resolvedPaths = - _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(_commandName, false, out provider, out providerInstance); - } - catch (ItemNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The path could not be found: {0}", - _commandName); - } - catch (DriveNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "A drive could not be found for the path: {0}", - _commandName); - } - catch (ProviderNotFoundException) - { - CommandDiscovery.discoveryTracer.TraceError( - "A provider could not be found for the path: {0}", - _commandName); - } - catch (InvalidOperationException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The path specified a home directory, but the provider home directory was not set. {0}", - _commandName); - } - catch (ProviderInvocationException providerException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The provider associated with the path '{0}' encountered an error: {1}", - _commandName, - providerException.Message); - } - catch (PSNotSupportedException) - { - CommandDiscovery.discoveryTracer.TraceError( - "The provider associated with the path '{0}' does not implement ContainerCmdletProvider", - _commandName); - } + resolvedPaths = GetNextFromPathUsingWildcards(_commandName, out provider); } - // Try literal path resolution if wildcards are disable or wildcard search failed - if (resolvedPaths.Count == 0) + // Try literal path resolution if wildcards are enable first and wildcard search failed + if (!(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) && + resolvedPaths.Count == 0) { - string path = _context.LocationGlobber.GetProviderPath(_commandName, out provider); - resolvedPaths.Add(path); + string path = GetNextLiteralPathThatExists(_commandName, out provider); + return GetInfoFromPath(path); } if (resolvedPaths.Count > 1) @@ -539,6 +505,54 @@ private CommandInfo GetNextFromPath() return result; } + private Collection GetNextFromPathUsingWildcards(string command, out ProviderInfo provider) + { + try + { + Provider.CmdletProvider providerInstance; + return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(command, false, out provider, out providerInstance); + } + catch (ItemNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The path could not be found: {0}", + command); + } + catch (DriveNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "A drive could not be found for the path: {0}", + command); + } + catch (ProviderNotFoundException) + { + CommandDiscovery.discoveryTracer.TraceError( + "A provider could not be found for the path: {0}", + command); + } + catch (InvalidOperationException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The path specified a home directory, but the provider home directory was not set. {0}", + command); + } + catch (ProviderInvocationException providerException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The provider associated with the path '{0}' encountered an error: {1}", + command, + providerException.Message); + } + catch (PSNotSupportedException) + { + CommandDiscovery.discoveryTracer.TraceError( + "The provider associated with the path '{0}' does not implement ContainerCmdletProvider", + command); + } + provider = null; + return null; + } + private static bool checkPath(string path, string commandName) { return path.StartsWith(commandName, StringComparison.OrdinalIgnoreCase); @@ -1103,16 +1117,24 @@ private string ResolvePSPath(string path) { ProviderInfo provider = null; string resolvedPath = null; - if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolvePathPatterns) && - WildcardPattern.ContainsWildcardCharacters(path)) + + // Try literal path resolution if it is set to run first + if(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) + { + resolvedPath = _context.LocationGlobber.GetProviderPath(path, out provider); + if(provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase) + && !File.Exists(resolvedPath)) + { + resolvedPath = null; + provider = null; + } + } + + if (WildcardPattern.ContainsWildcardCharacters(path) && + ((resolvedPath == null) || (provider == null))) { // Let PowerShell resolve relative path with wildcards. - Provider.CmdletProvider providerInstance; - Collection resolvedPaths = _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath( - path, - false, - out provider, - out providerInstance); + Collection resolvedPaths = GetNextFromPathUsingWildcards(path, out provider); if (resolvedPaths.Count == 0) { @@ -1136,8 +1158,9 @@ private string ResolvePSPath(string path) } } - // Try literal path resolution if wildcards are disable or wildcard search failed - if ((resolvedPath == null) || (provider == null)) + // Try literal path resolution if wildcards are enabled first and wildcard search failed + if (!(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) && + (resolvedPath == null) || (provider == null)) { resolvedPath = _context.LocationGlobber.GetProviderPath(path, out provider); } @@ -1188,6 +1211,19 @@ private string ResolvePSPath(string path) return result; } + string GetNextLiteralPathThatExists(string command, out ProviderInfo provider) + { + string resolvedPath = _context.LocationGlobber.GetProviderPath(command, out provider); + + if(System.IO.File.Exists(resolvedPath)) + { + return resolvedPath; + } + + provider = null; + return null; + } + /// /// Creates a collection of patterns used to find the command. /// @@ -1625,6 +1661,7 @@ internal enum SearchResolutionOptions /// /// Enable resolving wildcard in paths. /// - ResolvePathPatterns = 0x40, + //ResolvePathPatterns = 0x40, + ResolveLiteralThenPathPatterns = 0x40 } } diff --git a/src/System.Management.Automation/engine/GetCommandCommand.cs b/src/System.Management.Automation/engine/GetCommandCommand.cs index dcd977d3015..832134039e1 100644 --- a/src/System.Management.Automation/engine/GetCommandCommand.cs +++ b/src/System.Management.Automation/engine/GetCommandCommand.cs @@ -704,7 +704,7 @@ private void AccumulateMatchingCommands(IEnumerable commandNames) { // First set the search options - SearchResolutionOptions options = SearchResolutionOptions.ResolvePathPatterns; + SearchResolutionOptions options = SearchResolutionOptions.None; if (All) { options = SearchResolutionOptions.SearchAllScopes; diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 5b35e1755a6..41e3cac7789 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -85,7 +85,7 @@ Describe "Command Discovery tests" -Tags "CI" { (& 'location').Path | Should -Be (get-location).Path } - Context "Use literal path when executing scripts" { + Context "Use literal path first when executing scripts" { BeforeAll { $firstResult = 'first script' $secondResult = 'alt script' @@ -94,11 +94,11 @@ Describe "Command Discovery tests" -Tags "CI" { $executionWithWildcardCases = @( @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} + @{command = '.\[t1].ps1' ; expectedResult = $secondResult; name = '.\[t1].ps1'} @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} ) $shouldNotExecuteCases = @( - @{command = '.\[12].ps1'; testName = 'relative path with bracket wildcard matctching one file'} @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching one file'} ) @@ -120,7 +120,7 @@ Describe "Command Discovery tests" -Tags "CI" { } } - Context "Get-Command should use globbing for scripts" { + Context "Get-Command should use globbing first for scripts" { BeforeAll { $firstResult = '[first script]' $secondResult = 'alt script' From e1531827d4b6880c302f188407b37a51ba15ccfe Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 22:16:24 -0700 Subject: [PATCH 14/44] fix CodeFactor issues --- .../engine/CommandSearcher.cs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index c49bdd58a99..5783dfa29ae 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -460,7 +460,7 @@ private CommandInfo GetNextFromPath() ProviderInfo provider; // Try literal path resolution if it is set to run first - if(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) + if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { string path = GetNextLiteralPathThatExists(_commandName, out provider); return GetInfoFromPath(path); @@ -474,7 +474,7 @@ private CommandInfo GetNextFromPath() } // Try literal path resolution if wildcards are enable first and wildcard search failed - if (!(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) && + if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) && resolvedPaths.Count == 0) { string path = GetNextLiteralPathThatExists(_commandName, out provider); @@ -549,6 +549,7 @@ private Collection GetNextFromPathUsingWildcards(string command, out Pro "The provider associated with the path '{0}' does not implement ContainerCmdletProvider", command); } + provider = null; return null; } @@ -1119,15 +1120,9 @@ private string ResolvePSPath(string path) string resolvedPath = null; // Try literal path resolution if it is set to run first - if(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) + if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { - resolvedPath = _context.LocationGlobber.GetProviderPath(path, out provider); - if(provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase) - && !File.Exists(resolvedPath)) - { - resolvedPath = null; - provider = null; - } + resolvedPath = GetNextLiteralPathThatExists(path, out provider); } if (WildcardPattern.ContainsWildcardCharacters(path) && @@ -1159,10 +1154,10 @@ private string ResolvePSPath(string path) } // Try literal path resolution if wildcards are enabled first and wildcard search failed - if (!(_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) && + if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) && (resolvedPath == null) || (provider == null)) { - resolvedPath = _context.LocationGlobber.GetProviderPath(path, out provider); + resolvedPath = GetNextLiteralPathThatExists(path, out provider); } // Verify the path was resolved to a file system path @@ -1211,17 +1206,18 @@ private string ResolvePSPath(string path) return result; } - string GetNextLiteralPathThatExists(string command, out ProviderInfo provider) + private string GetNextLiteralPathThatExists(string command, out ProviderInfo provider) { string resolvedPath = _context.LocationGlobber.GetProviderPath(command, out provider); - if(System.IO.File.Exists(resolvedPath)) + if (provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase) + && !File.Exists(resolvedPath)) { - return resolvedPath; + provider = null; + return null; } - provider = null; - return null; + return resolvedPath; } /// @@ -1661,7 +1657,6 @@ internal enum SearchResolutionOptions /// /// Enable resolving wildcard in paths. /// - //ResolvePathPatterns = 0x40, ResolveLiteralThenPathPatterns = 0x40 } } From 3b004d1166d8ba7a400ba04302d1bb25c5c95ecd Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 22:27:34 -0700 Subject: [PATCH 15/44] Add comments to new functions --- .../engine/CommandSearcher.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 5783dfa29ae..a66c777304c 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -505,6 +505,16 @@ private CommandInfo GetNextFromPath() return result; } + /// + /// Gets the next path using WildCards. + /// + /// + /// The command to search for + /// + /// The provider that the command was found in + /// + /// A collection of full paths to the commands which were found + /// private Collection GetNextFromPathUsingWildcards(string command, out ProviderInfo provider) { try @@ -1206,6 +1216,17 @@ private string ResolvePSPath(string path) return result; } + /// + /// Gets the next literal path. + /// filtering to ones that exist for the filesystem + /// + /// + /// The command to search for + /// + /// The provider that the command was found in + /// + /// Full path to the command + /// private string GetNextLiteralPathThatExists(string command, out ProviderInfo provider) { string resolvedPath = _context.LocationGlobber.GetProviderPath(command, out provider); From 8ac7068c027e4a0571890f93a1e391a2ac1a01af Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 22:33:14 -0700 Subject: [PATCH 16/44] fix function summaries --- .../engine/CommandSearcher.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index a66c777304c..44e90a12569 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -509,11 +509,11 @@ private CommandInfo GetNextFromPath() /// Gets the next path using WildCards. /// /// - /// The command to search for + /// The command to search for. /// - /// The provider that the command was found in + /// The provider that the command was found in. /// - /// A collection of full paths to the commands which were found + /// A collection of full paths to the commands which were found. /// private Collection GetNextFromPathUsingWildcards(string command, out ProviderInfo provider) { @@ -1165,7 +1165,7 @@ private string ResolvePSPath(string path) // Try literal path resolution if wildcards are enabled first and wildcard search failed if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) && - (resolvedPath == null) || (provider == null)) + ((resolvedPath == null) || (provider == null)) { resolvedPath = GetNextLiteralPathThatExists(path, out provider); } @@ -1218,14 +1218,14 @@ private string ResolvePSPath(string path) /// /// Gets the next literal path. - /// filtering to ones that exist for the filesystem + /// Filtering to ones that exist for the filesystem. /// /// - /// The command to search for + /// The command to search for. /// - /// The provider that the command was found in + /// The provider that the command was found in. /// - /// Full path to the command + /// Full path to the command. /// private string GetNextLiteralPathThatExists(string command, out ProviderInfo provider) { From eebc092c6c893fda5b5885d94d949d9b7a4534b4 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Thu, 28 Mar 2019 22:38:29 -0700 Subject: [PATCH 17/44] fix syntax issue --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 44e90a12569..823a4abf596 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1165,7 +1165,7 @@ private string ResolvePSPath(string path) // Try literal path resolution if wildcards are enabled first and wildcard search failed if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) && - ((resolvedPath == null) || (provider == null)) + ((resolvedPath == null) || (provider == null))) { resolvedPath = GetNextLiteralPathThatExists(path, out provider); } From 7f14662318fc9f7c3360490d028b108d65f2f9a8 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 11:25:00 -0700 Subject: [PATCH 18/44] Address PR feedback --- src/System.Management.Automation/engine/CommandSearcher.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 823a4abf596..8c87c5bc26d 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -519,8 +519,7 @@ private Collection GetNextFromPathUsingWildcards(string command, out Pro { try { - Provider.CmdletProvider providerInstance; - return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(command, false, out provider, out providerInstance); + return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(command, false, out provider, out _); } catch (ItemNotFoundException) { From 4569916741b06616dc075fbbbaeac6815a10ff18 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 11:26:46 -0700 Subject: [PATCH 19/44] Address PR feedback --- .../engine/CommandSearcher.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 8c87c5bc26d..bb537b08b9a 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -456,13 +456,10 @@ private CommandInfo GetNextFromPath() "Trying to resolve the path as an PSPath"); // Find the match if it is. - - ProviderInfo provider; - // Try literal path resolution if it is set to run first if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { - string path = GetNextLiteralPathThatExists(_commandName, out provider); + string path = GetNextLiteralPathThatExists(_commandName, out _); return GetInfoFromPath(path); } @@ -470,14 +467,14 @@ private CommandInfo GetNextFromPath() if (resolvedPaths.Count == 0 && WildcardPattern.ContainsWildcardCharacters(_commandName)) { - resolvedPaths = GetNextFromPathUsingWildcards(_commandName, out provider); + resolvedPaths = GetNextFromPathUsingWildcards(_commandName, out _); } // Try literal path resolution if wildcards are enable first and wildcard search failed if (!_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns) && resolvedPaths.Count == 0) { - string path = GetNextLiteralPathThatExists(_commandName, out provider); + string path = GetNextLiteralPathThatExists(_commandName, out _); return GetInfoFromPath(path); } From 9e7edcf0da5c8283c57dffba423c60206ec8e49b Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 13:37:35 -0700 Subject: [PATCH 20/44] prevent null ref exception --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index bb537b08b9a..5b221828195 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1167,7 +1167,7 @@ private string ResolvePSPath(string path) } // Verify the path was resolved to a file system path - if (provider.NameEquals(_context.ProviderNames.FileSystem)) + if (provider !=null && provider.NameEquals(_context.ProviderNames.FileSystem)) { result = resolvedPath; From eaa81a66ac634fe0c86bd0d8f263b0cc75dd98a1 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 14:34:11 -0700 Subject: [PATCH 21/44] must return directories too --- src/System.Management.Automation/engine/CommandSearcher.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 5b221828195..a1fc5363a91 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1228,7 +1228,8 @@ private string GetNextLiteralPathThatExists(string command, out ProviderInfo pro string resolvedPath = _context.LocationGlobber.GetProviderPath(command, out provider); if (provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase) - && !File.Exists(resolvedPath)) + && !File.Exists(resolvedPath) + && !Directory.Exists(resolvedPath)) { provider = null; return null; From 5071a5421e79a728b5a9a15381fb33aab102dd02 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 14:34:47 -0700 Subject: [PATCH 22/44] Update src/System.Management.Automation/engine/CommandSearcher.cs --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index a1fc5363a91..98e324c6d83 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1167,7 +1167,7 @@ private string ResolvePSPath(string path) } // Verify the path was resolved to a file system path - if (provider !=null && provider.NameEquals(_context.ProviderNames.FileSystem)) + if (provider != null && provider.NameEquals(_context.ProviderNames.FileSystem)) { result = resolvedPath; From 6618eb355c50ba6c4baffff35e8777fa68682116 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:24:51 -0700 Subject: [PATCH 23/44] Apply suggestions from code review --- src/System.Management.Automation/engine/CommandSearcher.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 98e324c6d83..0aa3214d264 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -459,7 +459,9 @@ private CommandInfo GetNextFromPath() // Try literal path resolution if it is set to run first if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { - string path = GetNextLiteralPathThatExists(_commandName, out _); + var path = GetNextLiteralPathThatExists(_commandName, out _); + // This can return null, but that is expected. + // The searcher will continue, if it can. return GetInfoFromPath(path); } @@ -1128,6 +1130,9 @@ private string ResolvePSPath(string path) // Try literal path resolution if it is set to run first if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { + // Cannot return early as this code path only expects + // The file system provider and the final check for that + // must verify this before we return. resolvedPath = GetNextLiteralPathThatExists(path, out provider); } From d9615c51f378577ad4d20f79e1a3a831dc7ca62f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:29:34 -0700 Subject: [PATCH 24/44] remove unneeded condition --- src/System.Management.Automation/engine/CommandSearcher.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 0aa3214d264..8e01f7f8957 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -466,8 +466,7 @@ private CommandInfo GetNextFromPath() } Collection resolvedPaths = new Collection(); - if (resolvedPaths.Count == 0 && - WildcardPattern.ContainsWildcardCharacters(_commandName)) + if (WildcardPattern.ContainsWildcardCharacters(_commandName)) { resolvedPaths = GetNextFromPathUsingWildcards(_commandName, out _); } @@ -1131,7 +1130,7 @@ private string ResolvePSPath(string path) if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { // Cannot return early as this code path only expects - // The file system provider and the final check for that + // The file system provider and the final check for that // must verify this before we return. resolvedPath = GetNextLiteralPathThatExists(path, out provider); } From 2e43c54cb66c3cb3014edbf3e5ec9671b7b009f0 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:31:01 -0700 Subject: [PATCH 25/44] Fix CodeFactor issue --- src/System.Management.Automation/engine/CommandSearcher.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 8e01f7f8957..eabab2485d1 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -460,6 +460,7 @@ private CommandInfo GetNextFromPath() if (_commandResolutionOptions.HasFlag(SearchResolutionOptions.ResolveLiteralThenPathPatterns)) { var path = GetNextLiteralPathThatExists(_commandName, out _); + // This can return null, but that is expected. // The searcher will continue, if it can. return GetInfoFromPath(path); From 3a4e6f3c0c60bc1d0b4468f9d94fe60d6a646e78 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:34:18 -0700 Subject: [PATCH 26/44] Apply suggestions from code review --- build.psm1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.psm1 b/build.psm1 index 4649ab42058..613803e48be 100644 --- a/build.psm1 +++ b/build.psm1 @@ -908,6 +908,7 @@ function Start-PSPester { [string]$ExperimentalFeatureName, [Parameter(HelpMessage='Title to publish the results as.')] [string]$Title = 'PowerShell Core Tests', + [Parameter(ParameterSetName='Wait',Mandatory=$true,HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')] [switch]$Wait ) @@ -1101,6 +1102,10 @@ function Start-PSPester { Set-Content -Path $configFile -Value $content -Encoding Ascii -Force $PSFlags = @("-settings", $configFile, "-noprofile") } + + # -Wait is only available on Debug builds + # It is used to allow the debugger to attach before PowerShell + # runs pester in this case if($Wait.IsPresent){ $PSFlags += '-wait' } From 925bc41be5450ef7c59b6d7b81f74928e0423afe Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:54:51 -0700 Subject: [PATCH 27/44] used named parameters --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index eabab2485d1..847d32425d4 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -518,7 +518,7 @@ private Collection GetNextFromPathUsingWildcards(string command, out Pro { try { - return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(command, false, out provider, out _); + return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(path: command, allowNonexistingPaths: false, provider: out provider, providerInstance: out _); } catch (ItemNotFoundException) { From 30134f4e9aafe9ea4a469f0162d19dff7e7556c5 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 16:56:22 -0700 Subject: [PATCH 28/44] Update instance where filesystem provider name is not compared using constant --- src/System.Management.Automation/engine/CommandSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 847d32425d4..a78894e0f2e 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -1232,7 +1232,7 @@ private string GetNextLiteralPathThatExists(string command, out ProviderInfo pro { string resolvedPath = _context.LocationGlobber.GetProviderPath(command, out provider); - if (provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase) + if (provider.NameEquals(_context.ProviderNames.FileSystem) && !File.Exists(resolvedPath) && !Directory.Exists(resolvedPath)) { From 93a4ee929c44b0f9392ba19f11f91ebf441f49b6 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 29 Mar 2019 17:06:57 -0700 Subject: [PATCH 29/44] update parameter spacing --- build.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index 613803e48be..59ce64872e9 100644 --- a/build.psm1 +++ b/build.psm1 @@ -908,7 +908,8 @@ function Start-PSPester { [string]$ExperimentalFeatureName, [Parameter(HelpMessage='Title to publish the results as.')] [string]$Title = 'PowerShell Core Tests', - [Parameter(ParameterSetName='Wait',Mandatory=$true,HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')] + [Parameter(ParameterSetName='Wait', Mandatory=$true, + HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')] [switch]$Wait ) @@ -1104,7 +1105,7 @@ function Start-PSPester { } # -Wait is only available on Debug builds - # It is used to allow the debugger to attach before PowerShell + # It is used to allow the debugger to attach before PowerShell # runs pester in this case if($Wait.IsPresent){ $PSFlags += '-wait' From ddf6c6f76ef1127a1d29cd6a413d15f52c05ddf5 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 12:23:24 -0700 Subject: [PATCH 30/44] don't get commandinfo if path is null --- src/System.Management.Automation/engine/CommandSearcher.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index a78894e0f2e..2968e22c8be 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -461,9 +461,10 @@ private CommandInfo GetNextFromPath() { var path = GetNextLiteralPathThatExists(_commandName, out _); - // This can return null, but that is expected. - // The searcher will continue, if it can. - return GetInfoFromPath(path); + if(path !=null) + { + return GetInfoFromPath(path); + } } Collection resolvedPaths = new Collection(); From 5ddcb4f6039a239c599ce59a72b3cc1e996c07ff Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 12:50:46 -0700 Subject: [PATCH 31/44] fix tests to cover additional cases --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 41e3cac7789..6eb20e5432d 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -89,17 +89,20 @@ Describe "Command Discovery tests" -Tags "CI" { BeforeAll { $firstResult = 'first script' $secondResult = 'alt script' + $thirdResult = 'bad script' setup -f '[test1].ps1' -content "'$firstResult'" setup -f '1.ps1' -content "'$secondResult'" + setup -f '2.ps1' -content "'$thirdResult'" $executionWithWildcardCases = @( @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} @{command = '.\[t1].ps1' ; expectedResult = $secondResult; name = '.\[t1].ps1'} @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} + @{command = (Join-Path ${TestDrive} -ChildPath '[t1].ps1') ; expectedResult = $firstResult; name = '.\1.ps1 by fully qualified path with wildcard'} ) $shouldNotExecuteCases = @( - @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching one file'} + @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} ) Push-Location ${TestDrive}\ From 2d0a2f170260d04405a33e21a9f91086001ecee8 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 12:52:01 -0700 Subject: [PATCH 32/44] fix codefactor issues --- src/System.Management.Automation/engine/CommandSearcher.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index 2968e22c8be..a376582f3ae 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -461,7 +461,7 @@ private CommandInfo GetNextFromPath() { var path = GetNextLiteralPathThatExists(_commandName, out _); - if(path !=null) + if (path != null) { return GetInfoFromPath(path); } @@ -519,7 +519,7 @@ private Collection GetNextFromPathUsingWildcards(string command, out Pro { try { - return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(path: command, allowNonexistingPaths: false, provider: out provider, providerInstance: out _); + return _context.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(path: command, allowNonexistingPaths: false, provider: out provider, providerInstance: out _); } catch (ItemNotFoundException) { From 866aaf6bb2d8886ad5e5940dea552f44265d6a16 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 13:19:18 -0700 Subject: [PATCH 33/44] fix expected result --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 6eb20e5432d..fa8fe91dd6f 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -98,7 +98,7 @@ Describe "Command Discovery tests" -Tags "CI" { @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} @{command = '.\[t1].ps1' ; expectedResult = $secondResult; name = '.\[t1].ps1'} @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} - @{command = (Join-Path ${TestDrive} -ChildPath '[t1].ps1') ; expectedResult = $firstResult; name = '.\1.ps1 by fully qualified path with wildcard'} + @{command = (Join-Path ${TestDrive} -ChildPath '[t1].ps1') ; expectedResult = $secondResult; name = '.\1.ps1 by fully qualified path with wildcard'} ) $shouldNotExecuteCases = @( From 9670f88f9a7a40938b7428aa92fbe31f3bacfb6b Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 13:59:14 -0700 Subject: [PATCH 34/44] Add additional negative cases --- .../engine/Basic/CommandDiscovery.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index fa8fe91dd6f..35e8ecd5aef 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -102,6 +102,7 @@ Describe "Command Discovery tests" -Tags "CI" { ) $shouldNotExecuteCases = @( + @{command = '.\[12].ps1' ; testName = 'relative path with bracket wildcard matctching multiple files'} @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} ) @@ -127,8 +128,10 @@ Describe "Command Discovery tests" -Tags "CI" { BeforeAll { $firstResult = '[first script]' $secondResult = 'alt script' + $thirdResult = 'bad script' setup -f '[test1].ps1' -content "'$firstResult'" setup -f '1.ps1' -content "'$secondResult'" + setup -f '2.ps1' -content "'$thirdResult'" $gcmWithWildcardCases = @( @{command = '.\?[tb]est1?.ps1'; expectedCommand = '[test1].ps1'; expectedCommandCount =1; name = '''.\?[tb]est1?.ps1'''} @@ -137,6 +140,11 @@ Describe "Command Discovery tests" -Tags "CI" { @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1'); expectedCommand = '1.ps1'; expectedCommandCount =1 ; name = '''.\[test1].ps1'' by fully qualified path'} ) + $shouldNotFindCases = @( + @{command = '.\[12].ps1' ; testName = 'relative path with bracket wildcard matctching multiple files'} + @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} + ) + Push-Location ${TestDrive}\ } @@ -150,5 +158,9 @@ Describe "Command Discovery tests" -Tags "CI" { $commands.Count | Should -Be $expectedCommandCount $commands.Name | Should -BeExactly $expectedCommand } + + It "Get-Command should throw CommandNotFoundException when running ''" -TestCases $shouldNotFindCases { + {Get-Command -Name $command} | Should -Throw -ErrorId 'CommandNotFoundException' + } } } From 32ee8082535fb9a89e09349f71e6d0acb299a16f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 14:21:38 -0700 Subject: [PATCH 35/44] add missing param block --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 35e8ecd5aef..8c515f8dc9c 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -160,6 +160,7 @@ Describe "Command Discovery tests" -Tags "CI" { } It "Get-Command should throw CommandNotFoundException when running ''" -TestCases $shouldNotFindCases { + param($command) {Get-Command -Name $command} | Should -Throw -ErrorId 'CommandNotFoundException' } } From c086e74b12821590ce0607c1caba91c26f52eac8 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 14:30:23 -0700 Subject: [PATCH 36/44] expected results aren't as negative as I thought --- .../engine/Basic/CommandDiscovery.Tests.ps1 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 8c515f8dc9c..4ee5692d360 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -138,11 +138,8 @@ Describe "Command Discovery tests" -Tags "CI" { @{command = (Join-Path ${TestDrive} -ChildPath '?[tb]est1?.ps1'); expectedCommand = '[test1].ps1'; expectedCommandCount =1 ; name = '''.\?[tb]est1?.ps1'' by fully qualified path'} @{command = '.\[test1].ps1'; expectedCommand = '1.ps1'; expectedCommandCount =1; name = '''.\[test1].ps1'''} @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1'); expectedCommand = '1.ps1'; expectedCommandCount =1 ; name = '''.\[test1].ps1'' by fully qualified path'} - ) - - $shouldNotFindCases = @( - @{command = '.\[12].ps1' ; testName = 'relative path with bracket wildcard matctching multiple files'} - @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} + @{command = '.\[12].ps1'; expectedCommand = '1.ps1'; expectedCommandCount =0; name = 'relative path with bracket wildcard matctching multiple files'} + @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1'); expectedCommand = '1.ps1'; expectedCommandCount =0 ; name = 'fully qualified path with bracket wildcard matctching multiple files'} ) Push-Location ${TestDrive}\ @@ -154,14 +151,12 @@ Describe "Command Discovery tests" -Tags "CI" { It "Get-Command should return command named ''" -TestCases $gcmWithWildcardCases { param($command, $expectedCommand, $expectedCommandCount) - $commands = Get-Command -Name $command + $commands = @(Get-Command -Name $command) $commands.Count | Should -Be $expectedCommandCount - $commands.Name | Should -BeExactly $expectedCommand - } - - It "Get-Command should throw CommandNotFoundException when running ''" -TestCases $shouldNotFindCases { - param($command) - {Get-Command -Name $command} | Should -Throw -ErrorId 'CommandNotFoundException' + if($expectedCommandCount -gt 0) + { + $commands.Name | Should -BeExactly $expectedCommand + } } } } From a49ad497ab132ed3895923e64b7ccd758cc51711 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Sat, 30 Mar 2019 15:32:20 -0700 Subject: [PATCH 37/44] Add additional subFolder execution cases --- .../engine/Basic/CommandDiscovery.Tests.ps1 | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 4ee5692d360..bafae3c5370 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -87,18 +87,57 @@ Describe "Command Discovery tests" -Tags "CI" { Context "Use literal path first when executing scripts" { BeforeAll { - $firstResult = 'first script' - $secondResult = 'alt script' - $thirdResult = 'bad script' - setup -f '[test1].ps1' -content "'$firstResult'" - setup -f '1.ps1' -content "'$secondResult'" - setup -f '2.ps1' -content "'$thirdResult'" + $firstFileName = '[test1].ps1' + $secondFileName = '1.ps1' + $thirdFileName = '2.ps1' + $firstResult = "executing $firstFileName in root" + $secondResult = "executing $secondFileName in root" + $thirdResult = "executing $thirdFileName in root" + setup -f $firstFileName -content "'$firstResult'" + setup -f $secondFileName -content "'$secondResult'" + setup -f $thirdFileName -content "'$thirdResult'" + + $subFolder = 'subFolder' + $firstFileInSubFolder = Join-Path $subFolder -ChildPath $firstFileName + $secondFileInSubFolder = Join-Path $subFolder -ChildPath $secondFileName + $thirdFileInSubFolder = Join-Path $subFolder -ChildPath $thirdFileName + setup -f $firstFileInSubFolder -content "'$firstResult'" + setup -f $secondFileInSubFolder -content "'$secondResult'" + setup -f $thirdFileInSubFolder -content "'$thirdResult'" + + $secondFileSearchInSubfolder = (Join-Path -Path $subFolder -ChildPath '[t1].ps1') $executionWithWildcardCases = @( - @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} - @{command = '.\[t1].ps1' ; expectedResult = $secondResult; name = '.\[t1].ps1'} - @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} - @{command = (Join-Path ${TestDrive} -ChildPath '[t1].ps1') ; expectedResult = $secondResult; name = '.\1.ps1 by fully qualified path with wildcard'} + #Region relative paths with './' + @{command = '.\[test1].ps1' ; expectedResult = $firstResult; name = '.\[test1].ps1'} + @{command = '.\[t1].ps1' ; expectedResult = $secondResult; name = '.\[t1].ps1'} + #endregion + + #Region relative Subfolder paths without './' + @{command = $secondFileInSubFolder ; expectedResult = $secondResult; name = $secondFileInSubFolder} + + # PowerShell fails if the directory separators are in the wrong direction in this case + # https://github.com/PowerShell/PowerShell/issues/9256 + @{command = 'subFolder\[test1].ps1' ; expectedResult = $firstResult; name = 'subFolder\[test1].ps1'; Pending="See directory separator direction in https://github.com/PowerShell/PowerShell/issues/9256"} + @{command = 'subFolder\[t1].ps1' ; expectedResult = $secondResult; name = $secondFileSearchInSubfolder; Pending="See directory separator direction in https://github.com/PowerShell/PowerShell/issues/9256"} + + # Wildcard search is also not being performed in this scenario before this change. + # I noted this in the above issue and disabling these cases + @{command = $firstFileInSubFolder ; expectedResult = $firstResult; name = $firstFileInSubFolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} + @{command = $secondFileSearchInSubfolder ; expectedResult = $secondResult; name = $secondFileSearchInSubfolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} + #endregion + #Region relative Subfolder paths with '.\' + @{command = '.\' + $secondFileInSubFolder ; expectedResult = $secondResult; name = $secondFileInSubFolder} + @{command = '.\subFolder\[test1].ps1' ; expectedResult = $firstResult; name = '.\subFolder\[test1].ps1'} + @{command = '.\subFolder\[t1].ps1' ; expectedResult = $secondResult; name = '.\' + $secondFileSearchInSubfolder} + @{command = '.\' + $firstFileInSubFolder ; expectedResult = $firstResult; name = '.\' + $firstFileInSubFolder} + @{command = '.\' + $secondFileSearchInSubfolder ; expectedResult = $secondResult; name = '.\' + $secondFileSearchInSubfolder} + #endregion + + #region rooted paths + @{command = (Join-Path ${TestDrive} -ChildPath '[test1].ps1') ; expectedResult = $firstResult; name = '.\[test1].ps1 by fully qualified path'} + @{command = (Join-Path ${TestDrive} -ChildPath '[t1].ps1') ; expectedResult = $secondResult; name = '.\1.ps1 by fully qualified path with wildcard'} + #endregion ) $shouldNotExecuteCases = @( @@ -114,7 +153,13 @@ Describe "Command Discovery tests" -Tags "CI" { } It "Invoking should return ''" -TestCases $executionWithWildcardCases { - param($command, $expectedResult) + param($command, $expectedResult, [String]$Pending) + + if($Pending) + { + Set-TestInconclusive -Message $Pending + } + & $command | Should -BeExactly $expectedResult } From a59bc79a2e5dd7d6fa45f3d88ea88e5131261051 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 Apr 2019 10:38:06 -0700 Subject: [PATCH 38/44] make returns consistent --- src/System.Management.Automation/engine/CommandSearcher.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index a376582f3ae..2a4346a5f4d 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -478,7 +478,11 @@ private CommandInfo GetNextFromPath() resolvedPaths.Count == 0) { string path = GetNextLiteralPathThatExists(_commandName, out _); - return GetInfoFromPath(path); + + if (path != null) + { + return GetInfoFromPath(path); + } } if (resolvedPaths.Count > 1) From b18aaccc36bb100ed51a53b36bf8e3d25c06f20e Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 Apr 2019 11:04:01 -0700 Subject: [PATCH 39/44] make some pending tests negative tests --- .../powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index bafae3c5370..0d29d6224d8 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -141,6 +141,7 @@ Describe "Command Discovery tests" -Tags "CI" { ) $shouldNotExecuteCases = @( + @{command = 'subFolder\[test1].ps1' ; testName = 'Relative path that where module qualified syntax overlaps'; ExpectedErrorId = 'CouldNotAutoLoadModule'} @{command = '.\[12].ps1' ; testName = 'relative path with bracket wildcard matctching multiple files'} @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} ) @@ -164,8 +165,13 @@ Describe "Command Discovery tests" -Tags "CI" { } It "'' should not execute" -TestCases $shouldNotExecuteCases { - param($command) - { & $command } | Should -Throw -ErrorId 'CommandNotFoundException' + param( + [string] + $command, + [string] + $ExpectedErrorId = 'CommandNotFoundException' + ) + { & $command } | Should -Throw -ErrorId $ExpectedErrorId } } From 85a8c85559eed0fefd4cf00356f81c3b98ae586f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 Apr 2019 16:49:16 -0700 Subject: [PATCH 40/44] delete pending tests which were made negative tests --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 0d29d6224d8..8633f186b5b 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -116,11 +116,6 @@ Describe "Command Discovery tests" -Tags "CI" { #Region relative Subfolder paths without './' @{command = $secondFileInSubFolder ; expectedResult = $secondResult; name = $secondFileInSubFolder} - # PowerShell fails if the directory separators are in the wrong direction in this case - # https://github.com/PowerShell/PowerShell/issues/9256 - @{command = 'subFolder\[test1].ps1' ; expectedResult = $firstResult; name = 'subFolder\[test1].ps1'; Pending="See directory separator direction in https://github.com/PowerShell/PowerShell/issues/9256"} - @{command = 'subFolder\[t1].ps1' ; expectedResult = $secondResult; name = $secondFileSearchInSubfolder; Pending="See directory separator direction in https://github.com/PowerShell/PowerShell/issues/9256"} - # Wildcard search is also not being performed in this scenario before this change. # I noted this in the above issue and disabling these cases @{command = $firstFileInSubFolder ; expectedResult = $firstResult; name = $firstFileInSubFolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} From 0e4c566dc26a02dbee5acd1bab5fa09e13a349ed Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 Apr 2019 16:49:27 -0700 Subject: [PATCH 41/44] fix PR feedback --- build.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 59ce64872e9..5aedbfd33f1 100644 --- a/build.psm1 +++ b/build.psm1 @@ -909,7 +909,7 @@ function Start-PSPester { [Parameter(HelpMessage='Title to publish the results as.')] [string]$Title = 'PowerShell Core Tests', [Parameter(ParameterSetName='Wait', Mandatory=$true, - HelpMessage='Wait for the debugger to attach to powershell before pester starts. Debug builds only!')] + HelpMessage='Wait for the debugger to attach to PowerShell before Pester starts. Debug builds only!')] [switch]$Wait ) From 66fc031c4d4a52793cbded5e65d6291334ed98b6 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 1 Apr 2019 16:59:16 -0700 Subject: [PATCH 42/44] Update test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 8633f186b5b..b585de222c9 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -138,7 +138,7 @@ Describe "Command Discovery tests" -Tags "CI" { $shouldNotExecuteCases = @( @{command = 'subFolder\[test1].ps1' ; testName = 'Relative path that where module qualified syntax overlaps'; ExpectedErrorId = 'CouldNotAutoLoadModule'} @{command = '.\[12].ps1' ; testName = 'relative path with bracket wildcard matctching multiple files'} - @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matctching multiple files'} + @{command = (Join-Path ${TestDrive} -ChildPath '[12].ps1') ; testName = 'fully qualified path with bracket wildcard matching multiple files'} ) Push-Location ${TestDrive}\ From 5d7bc154b7a13970eda5f6d372925e6a767ff354 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 2 Apr 2019 10:37:44 -0700 Subject: [PATCH 43/44] Update test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index b585de222c9..154ecfa6c6e 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -117,7 +117,7 @@ Describe "Command Discovery tests" -Tags "CI" { @{command = $secondFileInSubFolder ; expectedResult = $secondResult; name = $secondFileInSubFolder} # Wildcard search is also not being performed in this scenario before this change. - # I noted this in the above issue and disabling these cases + # I noted the issue in the pending message @{command = $firstFileInSubFolder ; expectedResult = $firstResult; name = $firstFileInSubFolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} @{command = $secondFileSearchInSubfolder ; expectedResult = $secondResult; name = $secondFileSearchInSubfolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} #endregion From c96509756e1d65ad2e13572eba484134b362ac79 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 2 Apr 2019 10:38:22 -0700 Subject: [PATCH 44/44] Update test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 --- test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 154ecfa6c6e..030301477c2 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -116,7 +116,7 @@ Describe "Command Discovery tests" -Tags "CI" { #Region relative Subfolder paths without './' @{command = $secondFileInSubFolder ; expectedResult = $secondResult; name = $secondFileInSubFolder} - # Wildcard search is also not being performed in this scenario before this change. + # Wildcard search is not being performed in this scenario before this change. # I noted the issue in the pending message @{command = $firstFileInSubFolder ; expectedResult = $firstResult; name = $firstFileInSubFolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"} @{command = $secondFileSearchInSubfolder ; expectedResult = $secondResult; name = $secondFileSearchInSubfolder; Pending="See note about wildcard in https://github.com/PowerShell/PowerShell/issues/9256"}