Allow creation of symlink to non-existent target

This action is completely valid on both Windows and Linux (and OS X)
operating systems; tested with `mklink` and `ln -s` respectively.

Note that targets for hard links must exist, thus we check specifically
for symbolic links.

Both the path globber in session state and the `New-Item` implementation
needed to be fixed to allow the target not to exist.

Resolves #801.

Also enable symbolic link tests on Windows.
This commit is contained in:
Andrew Schwartzmeyer committed 2016-04-09 18:45:23 -07:00
1 parent 76ad94d8a7
commit 3a43126a2e
3 files changed
+23 -4

No files matched your search

+13 -2
View File
@@ -104,7 +104,7 @@ Describe "New-Item" {
Test-Path $FullyQualifiedFile | Should Be $false
}
It "Should create a symbolic link of a file without error" -Skip:$IsWindows {
It "Should create a symbolic link of a file without error" {
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
Test-Path $FullyQualifiedFile | Should Be $true
@@ -116,7 +116,18 @@ Describe "New-Item" {
$fileInfo.LinkType | Should Be "SymbolicLink"
}
It "Should create a symbolic link from directory without error" -Skip:$IsWindows {
It "Should create a symbolic link to a non-existing file without error" {
$target = Join-Path $tmpDirectory "totallyBogusFile"
New-Item -ItemType SymbolicLink -Target $target -Name $testlink -Path $tmpDirectory
Test-Path $FullyQualifiedLink | Should Be $true
$fileInfo = Get-ChildItem $FullyQualifiedLink
$fileInfo.Target | Should Be $target
Test-Path $fileInfo.Target | Should be $false
$fileInfo.LinkType | Should Be "SymbolicLink"
}
It "Should create a symbolic link from directory without error" {
New-Item -Name $testFolder -Path $tmpDirectory -ItemType directory
Test-Path $FullyQualifiedFolder | Should Be $true