From 1f79c1ee9652322acc350e448bcb08bd4c40583a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 13 Oct 2017 22:42:16 -0700 Subject: [PATCH 1/2] put command discovery before scripts for Unix --- .../engine/CommandPathSearch.cs | 2 +- .../NativeLinuxCommands.Tests.ps1 | 40 ++++++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandPathSearch.cs b/src/System.Management.Automation/engine/CommandPathSearch.cs index 4eb175d2a7b..75a27f03b20 100644 --- a/src/System.Management.Automation/engine/CommandPathSearch.cs +++ b/src/System.Management.Automation/engine/CommandPathSearch.cs @@ -65,7 +65,7 @@ internal CommandPathSearch( // Porting note: on non-Windows platforms, we want to always allow just 'commandName' // as an acceptable command name. However, we also want to allow commands to be // called with the .ps1 extension, so that 'script.ps1' can be called by 'script'. - commandPatterns = new[] { commandName + ".ps1", commandName }; + commandPatterns = new[] { commandName, commandName + ".ps1" }; } _postProcessEnumeratedFiles = CheckAgainstAcceptableCommandNames; _acceptableCommandNames = acceptableCommandNames; diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 index 88d2a78ea6d..233ae051b04 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 @@ -1,39 +1,57 @@ -if ( $IsWindows ) { - $PesterSkipOrPending = @{ Skip = $true } -} -else { - $PesterSkipOrPending = @{} -} Describe "NativeLinuxCommands" -tags "CI" { + BeforeAll { + $originalDefaultParams = $PSDefaultParameterValues.Clone() + $PSDefaultParameterValues["It:Skip"] = $IsWindows + $originalPath = $env:PATH + $env:PATH += [IO.Path]::PathSeparator + $TestDrive + } + + AfterAll { + $global:PSDefaultParameterValues = $originalDefaultParams + $env:PATH = $originalPath + } + It "Should return a type of 'string' for hostname cmdlet" { $result = hostname $result | Should Not BeNullOrEmpty $result | Should BeOfType string } - It "Should find Application grep" @PesterSkipOrPending { + It "Should find Application grep" { (get-command grep).CommandType | Should Be Application } - It "Should pipe to grep and get result" @PesterSkipOrPending { + It "Should pipe to grep and get result" { "hello world" | grep hello | Should Be "hello world" } - It "Should find Application touch" @PesterSkipOrPending { + It "Should find Application touch" { (get-command touch).CommandType | Should Be Application } - It "Should not redirect standard input if native command is the first command in pipeline (1)" @PesterSkipOrPending { + It "Should not redirect standard input if native command is the first command in pipeline (1)" { df | ForEach-Object -Begin { $out = @() } -Process { $out += $_ } $out.Length -gt 0 | Should Be $true $out[0] -like "Filesystem*Available*" | Should Be $true } - It "Should not redirect standard input if native command is the first command in pipeline (2)" @PesterSkipOrPending { + It "Should not redirect standard input if native command is the first command in pipeline (2)" { $out = df $out.Length -gt 0 | Should Be $true $out[0] -like "Filesystem*Available*" | Should Be $true } + + It "Should find command before script with same name" { + Set-Content "$TestDrive\foo" -Value @" +#!/usr/bin/env bash +echo 'command' +"@ -Encoding Ascii + chmod +x "$TestDrive/foo" + Set-Content "$TestDrive\foo.ps1" -Value @" +'script' +"@ -Encoding Ascii + foo | Should BeExactly 'command' + } } Describe "Scripts with extensions" -tags "CI" { From c2f30137ebbb3f21eab3f9c715a0e172a6c24d5f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 14 Oct 2017 08:25:46 -0700 Subject: [PATCH 2/2] remove unnecessary test --- .../Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 index 233ae051b04..a333adb4091 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 @@ -11,12 +11,6 @@ Describe "NativeLinuxCommands" -tags "CI" { $env:PATH = $originalPath } - It "Should return a type of 'string' for hostname cmdlet" { - $result = hostname - $result | Should Not BeNullOrEmpty - $result | Should BeOfType string - } - It "Should find Application grep" { (get-command grep).CommandType | Should Be Application }