mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge pull request #1534 from PowerShell/vors/cd
Make 'cd' go to the HOME directory
This commit is contained in:
commit
fa78a55c37
3 files changed
+41
-20
No files matched your search
@@ -996,6 +996,12 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Change the current working directory
|
// Change the current working directory
|
||||||
|
if (string.IsNullOrEmpty(Path))
|
||||||
|
{
|
||||||
|
// If user just typed 'cd', go to FileSystem provider home directory
|
||||||
|
Path = SessionState.Internal.GetSingleProvider(Commands.FileSystemProvider.ProviderName).Home;
|
||||||
|
}
|
||||||
|
|
||||||
result = SessionState.Path.SetLocation(Path, CmdletProviderContext);
|
result = SessionState.Path.SetLocation(Path, CmdletProviderContext);
|
||||||
}
|
}
|
||||||
catch (PSNotSupportedException notSupported)
|
catch (PSNotSupportedException notSupported)
|
||||||
|
|||||||
@@ -3,64 +3,79 @@ Describe "Set-Location" -Tags "CI" {
|
|||||||
|
|
||||||
if ($IsWindows)
|
if ($IsWindows)
|
||||||
{
|
{
|
||||||
$target = "C:\"
|
$target = "C:\"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$target = "/"
|
$target = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to be called without error" {
|
It "Should be able to be called without error" {
|
||||||
{ Set-Location $target } | Should Not Throw
|
{ Set-Location $target } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to be called on different providers" {
|
It "Should be able to be called on different providers" {
|
||||||
{ Set-Location alias: } | Should Not Throw
|
{ Set-Location alias: } | Should Not Throw
|
||||||
{ Set-Location env: } | Should Not Throw
|
{ Set-Location env: } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able use the cd alias without error" {
|
It "Should be able use the cd alias without error" {
|
||||||
{ cd $target } | Should Not Throw
|
{ cd $target } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to use the chdir alias without error" {
|
It "Should be able to use the chdir alias without error" {
|
||||||
{ chdir $target } | Should Not Throw
|
{ chdir $target } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to use the sl alias without error" {
|
It "Should be able to use the sl alias without error" {
|
||||||
{ sl $target } | Should Not Throw
|
{ sl $target } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have the correct current location when using the set-location cmdlet" {
|
It "Should have the correct current location when using the set-location cmdlet" {
|
||||||
Set-Location $startDirectory
|
Set-Location $startDirectory
|
||||||
|
|
||||||
$(Get-Location).Path | Should Be $startDirectory.Path
|
$(Get-Location).Path | Should Be $startDirectory.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have the correct current location when using the cd alias" {
|
It "Should have the correct current location when using the cd alias" {
|
||||||
cd $target
|
cd $target
|
||||||
|
|
||||||
$(Get-Location).Path | Should Be $target
|
$(Get-Location).Path | Should Be $target
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have the correct current location when using the chdir alias" {
|
It "Should have the correct current location when using the chdir alias" {
|
||||||
chdir $target
|
chdir $target
|
||||||
|
|
||||||
$(Get-Location).Path | Should Be $target
|
$(Get-Location).Path | Should Be $target
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have the correct current location when using the chdir alias" {
|
It "Should have the correct current location when using the chdir alias" {
|
||||||
sl $target
|
sl $target
|
||||||
|
|
||||||
$(Get-Location).Path | Should Be $target
|
$(Get-Location).Path | Should Be $target
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to use the Path switch" {
|
It "Should be able to use the Path switch" {
|
||||||
{ Set-Location -Path $target } | Should Not Throw
|
{ Set-Location -Path $target } | Should Not Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should generate a pathinfo object when using the Passthru switch" {
|
It "Should generate a pathinfo object when using the Passthru switch" {
|
||||||
$(Set-Location $target -PassThru).GetType().Name | Should Be PathInfo
|
$(Set-Location $target -PassThru).GetType().Name | Should Be PathInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
Context 'cd with no arguments' {
|
||||||
|
|
||||||
|
It 'Should go to $env:HOME when cd run with no arguments from FileSystem provider' {
|
||||||
|
Set-Location 'TestDrive:\'
|
||||||
|
cd
|
||||||
|
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Should go to $env:HOME when cd run with no arguments from Env: provider' {
|
||||||
|
Set-Location 'Env:'
|
||||||
|
cd
|
||||||
|
(Get-Location).Path | Should Be (Get-PSProvider FileSystem).Home
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location $startDirectory
|
Set-Location $startDirectory
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using namespace System.Management.Automation
|
using namespace System.Management.Automation
|
||||||
using namespace System.Management.Automation.Language
|
using namespace System.Management.Automation.Language
|
||||||
|
|
||||||
Describe "SemanticVersion api tests" {
|
Describe "SemanticVersion api tests" -Tags 'CI' {
|
||||||
Context "constructing valid versions" {
|
Context "constructing valid versions" {
|
||||||
It "string argument constructor" {
|
It "string argument constructor" {
|
||||||
$v = [SemanticVersion]::new("1.2.3-alpha")
|
$v = [SemanticVersion]::new("1.2.3-alpha")
|
||||||
@@ -184,4 +184,4 @@ Describe "SemanticVersion api tests" {
|
|||||||
{ [SemanticVersion]::new([Version]::new("1.2")) } | Should Throw # PSArgumentException
|
{ [SemanticVersion]::new([Version]::new("1.2")) } | Should Throw # PSArgumentException
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user