mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Remove / and /tmp references
This commit is contained in:
committed by
Andrew Schwartzmeyer
parent
cb6d7011d9
commit
bdffd103d9
@@ -2,7 +2,7 @@
|
||||
|
||||
Describe "ConvertFrom-Csv" {
|
||||
$testObject = "a", "1"
|
||||
$testcsv = "$here/assets/TestCsv2.csv"
|
||||
$testcsv = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath TestCsv2.csv
|
||||
$testName = "Zaphod BeebleBrox"
|
||||
$testColumns = @"
|
||||
a,b,c
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
. $here/Test-Common.ps1
|
||||
. (Join-Path -Path $here -ChildPath Test-Common.ps1)
|
||||
|
||||
Describe "Export-Alias" {
|
||||
$testAliasDirectory = "$(GetTempDir)/ExportAliasTestDirectory"
|
||||
$testAliasDirectory = Join-Path -Path $(GetTempDir) -ChildPath ExportAliasTestDirectory
|
||||
$testAliases = "TestAliases"
|
||||
$fulltestpath = "$($testAliasDirectory)/$($testAliases)"
|
||||
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||
|
||||
BeforeEach {
|
||||
New-Item -Path $testAliasDirectory -ItemType Directory -Force
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
$testString2 = $firstline + $nl + $secondline + $nl + $thirdline + $nl + $fourthline + $nl + $fifthline
|
||||
|
||||
$testPath = "/tmp/testfile1"
|
||||
$testPath2 = "/tmp/testfile2"
|
||||
$testPath = Join-Path -Path $TestDrive -ChildPath testfile1
|
||||
$testPath2 = Join-Path -Path $TestDrive -ChildPath testfile2
|
||||
|
||||
BeforeEach {
|
||||
New-Item -Path $testPath -ItemType file -Force -Value $testString
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Describe "Get-FileHash" {
|
||||
New-Variable testDocument -Value $PSScriptRoot/assets/testablescript.ps1 -Scope Global -Force
|
||||
New-Variable testDocument -Value (Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath testablescript.ps1) -Scope Global -Force
|
||||
# The MACTripleDES and RIPEMD160 algorithms are unsupported at the moment
|
||||
$algorithms = @{"SHA1" ="01B865D143E07ECC875AB0EFC0A4429387FD0CF7";
|
||||
"SHA256" = "4A6DA9F1C0827143BB19FC4B0F2A8057BC1DF55F6D1F62FA3B917BA458E8F570";
|
||||
@@ -28,8 +28,7 @@
|
||||
It "Should list the path of the file under test" {
|
||||
$result = Get-FileHash $testDocument
|
||||
|
||||
# regular expression for the forward/backslashes for linux/windows compatability
|
||||
$result.Path | Should Match "assets[/|\\]testablescript.ps1"
|
||||
$result.Path | Should Match (Join-Path assets -ChildPath testablescript.ps1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
Describe "Get-Item" {
|
||||
It "Should list all the items in the current working directory when asterisk is used" {
|
||||
(Get-Item $here/*).GetType().BaseType | Should Be 'array'
|
||||
(Get-Item $here/*).GetType().Name | Should Be 'Object[]'
|
||||
(Get-Item (Join-Path -Path $here -ChildPath "*")).GetType().BaseType | Should Be 'array'
|
||||
(Get-Item (Join-Path -Path $here -ChildPath "*")).GetType().Name | Should Be 'Object[]'
|
||||
}
|
||||
|
||||
It "Should return the name of the current working directory when a dot is used" {
|
||||
@@ -13,7 +13,7 @@ Describe "Get-Item" {
|
||||
|
||||
It "Should return the proper Name and BaseType for directory objects vs file system objects" {
|
||||
(Get-Item $here).GetType().Name | Should Be 'DirectoryInfo'
|
||||
(Get-Item $here/Get-Item.Tests.ps1).GetType().Name | Should Be 'FileInfo'
|
||||
(Get-Item (Join-Path -Path $here -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo'
|
||||
}
|
||||
|
||||
It "Should have mode flags set" {
|
||||
|
||||
@@ -2,22 +2,11 @@
|
||||
|
||||
Describe "Get-ItemProperty" {
|
||||
$currentDirectory = Split-Path $here -Leaf
|
||||
$parentDirectory = Split-Path $here/.. -Leaf
|
||||
$isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
|
||||
$parentDirectory = Split-Path (Join-Path -Path $here -ChildPath "..") -Leaf
|
||||
$tempDirectory = $TestDrive
|
||||
$testprovider = (Get-Item $tempDirectory).PSDrive.Name
|
||||
|
||||
if ($isWindows)
|
||||
{
|
||||
$tempDirectory = "~/testfolder"
|
||||
$testProvider = "C"
|
||||
}
|
||||
else
|
||||
{
|
||||
$tempDirectory = "/tmp/testfolder"
|
||||
$testProvider = "/"
|
||||
}
|
||||
|
||||
New-Item $tempDirectory -ItemType Directory -Force
|
||||
$testfile = $tempDirectory + [System.IO.Path]::DirectorySeparatorChar + "testfile1"
|
||||
$testfile = Join-Path -Path $tempDirectory -ChildPath testfile1
|
||||
|
||||
New-Item $testfile -ItemType file -Force
|
||||
|
||||
@@ -62,6 +51,4 @@ Describe "Get-ItemProperty" {
|
||||
$alias.PSDrive | Should Be $cmdlet.PSDrive
|
||||
$alias.PSProvider.Name | Should Be $cmdlet.PSProvider.Name
|
||||
}
|
||||
|
||||
Remove-Item $tempDirectory -Recurse -Force
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
Describe "Import-Alias" {
|
||||
$pesteraliasfile = "$here/assets/pesteralias.txt"
|
||||
$pesteraliasfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath pesteralias.txt
|
||||
|
||||
Context "Validate ability to import alias file" {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
|
||||
Describe "Import-Csv" {
|
||||
$testCsv = "$here/assets/TestCsv.csv"
|
||||
$testCsv = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath TestCsv.csv
|
||||
|
||||
It "Should be able to call without error" {
|
||||
{ Import-Csv $testCsv } | Should Not Throw
|
||||
|
||||
@@ -13,7 +13,7 @@ Describe "Invoke-Expression" {
|
||||
}
|
||||
|
||||
It "Should return the echoed text from a script" {
|
||||
$testfile = "$here/assets/echoscript.ps1"
|
||||
$testfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
||||
$testcommand = "echo pestertestscript"
|
||||
$testcommand | Add-Content -Path $testfile
|
||||
(Invoke-Expression $testfile) | Should Be "pestertestscript"
|
||||
@@ -21,7 +21,7 @@ Describe "Invoke-Expression" {
|
||||
}
|
||||
|
||||
It "Should return the echoed text from a script from the alias" {
|
||||
$testfile = "$here/assets/echoscript.ps1"
|
||||
$testfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
||||
$testcommand = "echo pestertestscript"
|
||||
$testcommand | Add-Content -Path $testfile
|
||||
(iex $testfile) | Should Be "pestertestscript"
|
||||
|
||||
@@ -18,7 +18,7 @@ Describe "Json.NET LINQ Parsing" {
|
||||
[Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($path)
|
||||
|
||||
BeforeEach {
|
||||
$jsonFile = "$here/assets/TestJson.json"
|
||||
$jsonFile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath TestJson.json
|
||||
$jsonData = (Get-Content $jsonFile | Out-String)
|
||||
$json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData)
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ Describe "Measure-Command" {
|
||||
}
|
||||
|
||||
It "Should return TimeSpan after executing a cmdlet" {
|
||||
$pesterscript = "$here/assets/echoscript.ps1"
|
||||
$testfile = "$here/assets/echoscript.ps1"
|
||||
$pesterscript = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
||||
$testfile = $pesterscript
|
||||
$testcommand = "echo pestertestscript"
|
||||
$testcommand | Add-Content -Path $testfile
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
}
|
||||
|
||||
Describe "New-Item" {
|
||||
$tmpDirectory = "/tmp"
|
||||
$tmpDirectory = $TestDrive
|
||||
$testfile = "testfile.txt"
|
||||
$testfolder = "newDirectory"
|
||||
$FullyQualifiedFile = $tmpDirectory + "/" + $testfile
|
||||
$FullyQualifiedFolder = $tmpDirectory + "/" + $testfolder
|
||||
$FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile
|
||||
$FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder
|
||||
|
||||
BeforeEach {
|
||||
Clean-State
|
||||
@@ -74,7 +74,7 @@ Describe "New-Item" {
|
||||
}
|
||||
|
||||
It "Should be able to create a multiple items in different directories" {
|
||||
$FullyQualifiedFile2 = $tmpDirectory + "/" + "test2.txt"
|
||||
$FullyQualifiedFile2 = Join-Path -Path $tmpDirectory -ChildPath test2.txt
|
||||
New-Item -ItemType file -Path $FullyQualifiedFile, $FullyQualifiedFile2
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
@@ -84,7 +84,7 @@ Describe "New-Item" {
|
||||
}
|
||||
|
||||
It "Should be able to call the whatif switch without error" {
|
||||
{ New-Item -Name testfile.txt -Path /tmp -ItemType file -WhatIf } | Should Not Throw
|
||||
{ New-Item -Name testfile.txt -Path $tmpDirectory -ItemType file -WhatIf } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not create a new file when the whatif switch is used" {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Describe "Out-File" {
|
||||
$expectedContent = "some test text"
|
||||
$inObject = New-Object psobject -Property @{text=$expectedContent}
|
||||
$testfile = "/tmp/outfileTest.txt"
|
||||
$testfile = Join-Path -Path $TestDrive -ChildPath outfileTest.txt
|
||||
|
||||
AfterEach {
|
||||
Remove-Item -Path $testfile -Force
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Describe "Remove-Item" {
|
||||
$testpath = "/tmp/"
|
||||
$testpath = $TestDrive
|
||||
$testfile = "testfile.txt"
|
||||
$testfilepath = $testpath + $testfile
|
||||
$testfilepath = Join-Path -Path $testpath -ChildPath $testfile
|
||||
Context "File removal Tests" {
|
||||
BeforeEach {
|
||||
New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force
|
||||
@@ -71,11 +71,11 @@
|
||||
# Create a single file that does not match that string - already done in BeforeEach
|
||||
|
||||
# Delete the specific string
|
||||
Remove-Item /tmp/* -Include file*.txt
|
||||
Remove-Item (Join-Path -Path $testpath -ChildPath "*") -Include file*.txt
|
||||
# validate that the string under test was deleted, and the nonmatching strings still exist
|
||||
Test-path /tmp/file1.txt | Should Be $false
|
||||
Test-path /tmp/file2.txt | Should Be $false
|
||||
Test-path /tmp/file3.txt | Should Be $false
|
||||
Test-path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
|
||||
Test-path (Join-Path -Path $testpath -ChildPath file2.txt) | Should Be $false
|
||||
Test-path (Join-Path -Path $testpath -ChildPath file3.txt) | Should Be $false
|
||||
Test-Path $testfilepath | Should Be $true
|
||||
|
||||
# Delete the non-matching strings
|
||||
@@ -93,27 +93,27 @@
|
||||
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
|
||||
# Delete the specific string
|
||||
Remove-Item /tmp/file* -Exclude *.wav -Include *.txt
|
||||
Remove-Item (Join-Path -Path $testpath -ChildPath "file*") -Exclude *.wav -Include *.txt
|
||||
|
||||
# validate that the string under test was deleted, and the nonmatching strings still exist
|
||||
Test-Path /tmp/file1.wav | Should Be $true
|
||||
Test-Path /tmp/file2.wav | Should Be $true
|
||||
Test-Path /tmp/file1.txt | Should Be $false
|
||||
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $true
|
||||
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $true
|
||||
Test-Path (Join-Path -Path $testpath -ChildPath file1.txt) | Should Be $false
|
||||
|
||||
# Delete the non-matching strings
|
||||
Remove-Item /tmp/file1.wav
|
||||
Remove-Item /tmp/file2.wav
|
||||
Remove-Item (Join-Path -Path $testpath -ChildPath file1.wav)
|
||||
Remove-Item (Join-Path -Path $testpath -ChildPath file2.wav)
|
||||
|
||||
Test-Path /tmp/file1.wav | Should Be $false
|
||||
Test-Path /tmp/file2.wav | Should Be $false
|
||||
Test-Path (Join-Path -Path $testpath -ChildPath file1.wav) | Should Be $false
|
||||
Test-Path (Join-Path -Path $testpath -ChildPath file2.wav) | Should Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Directory Removal Tests" {
|
||||
$testdirectory = "/tmp/testdir"
|
||||
$testsubdirectory = $testdirectory + "/subd"
|
||||
$testdirectory = Join-Path -Path $testpath -ChildPath testdir
|
||||
$testsubdirectory = Join-Path -Path $testdirectory -ChildPath subd
|
||||
BeforeEach {
|
||||
New-Item -Name "testdir" -Path "/tmp/" -ItemType "directory" -Force
|
||||
New-Item -Name "testdir" -Path $testpath -ItemType "directory" -Force
|
||||
|
||||
Test-Path $testdirectory | Should Be $true
|
||||
}
|
||||
@@ -128,7 +128,7 @@
|
||||
New-Item -Name "subd" -Path $testdirectory -ItemType "directory"
|
||||
New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum"
|
||||
|
||||
$complexDirectory = $testsubdirectory + "/" + $testfile
|
||||
$complexDirectory = Join-Path -Path $testsubdirectory -ChildPath $testfile
|
||||
test-path $complexDirectory | Should Be $true
|
||||
|
||||
{ Remove-Item $testdirectory -Recurse} | Should Not Throw
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Describe "Remove-PSBreakpoint" {
|
||||
# Set up test script
|
||||
$testScript = "$here/assets/psbreakpointtestscript.ps1"
|
||||
$testScript = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
|
||||
|
||||
$script = "`$var = 1
|
||||
`$var2 = Get-Process
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
. "$here/Test-Mocks.ps1"
|
||||
. (Join-Path -Path $here -ChildPath Test-Mocks.ps1)
|
||||
|
||||
Describe "Select-Object" {
|
||||
BeforeEach {
|
||||
|
||||
@@ -89,16 +89,8 @@
|
||||
Context "Filesytem actions" {
|
||||
$isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)
|
||||
|
||||
if ($isWindows)
|
||||
{
|
||||
$testDirectory = "C:\tmp\"
|
||||
$testInputFile = "C:\tmp\testfile1.txt"
|
||||
}
|
||||
else
|
||||
{
|
||||
$testDirectory = "/tmp/"
|
||||
$testInputFile = "/tmp/testfile1.txt"
|
||||
}
|
||||
$testDirectory = $TestDrive
|
||||
$testInputFile = Join-Path -Path $testDirectory -ChildPath testfile1.txt
|
||||
|
||||
BeforeEach {
|
||||
New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string${nl}This is the second line${nl}This is the third line${nl}This is the fourth line${nl}No matches"
|
||||
@@ -163,7 +155,11 @@
|
||||
It "Should return the third line in testfile1 when a relative path is used" {
|
||||
$expected = "testfile1.txt:3:This is the third line"
|
||||
|
||||
Select-String third $testDirectory/"../tmp/testfile1.txt" | Should Match $expected
|
||||
$relativePath = Join-Path -Path $testDirectory -ChildPath ".."
|
||||
$relativePath = Join-Path -Path $relativePath -ChildPath ".."
|
||||
$relativePath = Join-Path -Path $relativePath -ChildPath $testDirectory
|
||||
$relativePath = Join-Path -Path $relativePath -ChildPath testfile1.txt
|
||||
Select-String third $relativePath | Should Match $expected
|
||||
}
|
||||
|
||||
It "Should return the fourth line in testfile1 when a relative path is used" {
|
||||
@@ -171,7 +167,7 @@
|
||||
|
||||
pushd $testDirectory
|
||||
|
||||
Select-String matches $testDirectory/testfile1.txt | Should Match $expected
|
||||
Select-String matches (Join-Path -Path $testDirectory -ChildPath testfile1.txt) | Should Match $expected
|
||||
popd
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Describe "Set-PSBreakpoint" {
|
||||
# Set up test script
|
||||
$testScript = "$here/psbreakpointtestscript.ps1"
|
||||
$testScript = Join-Path -Path $here -ChildPath psbreakpointtestscript.ps1
|
||||
|
||||
"`$var = 1 " > $testScript
|
||||
|
||||
|
||||
@@ -61,24 +61,21 @@
|
||||
}
|
||||
|
||||
It "Should be able to accept regular expression input and output an array for multiple objects" {
|
||||
$testDir = "./testDir"
|
||||
$testDir = $TestDrive
|
||||
$testFile1 = "testfile1.ps1"
|
||||
$testFile2 = "testfile2.ps1"
|
||||
$testFilePath1 = $testDir + "/" + $testFile1
|
||||
$testFilePath2 = $testDir + "/" + $testFile2
|
||||
$testFilePath1 = Join-Path -Path $testDir -ChildPath $testFile1
|
||||
$testFilePath2 = Join-Path -Path $testDir -ChildPath $testFile2
|
||||
|
||||
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
|
||||
|
||||
Test-Path $testFilePath1 | Should Be $true
|
||||
Test-Path $testFilePath2 | Should Be $true
|
||||
|
||||
$actual = ( Split-Path $testDir/*file*.ps1 -Leaf -Resolve ) | Sort-Object
|
||||
$actual = ( Split-Path (Join-Path -Path $testDir -ChildPath "*file*.ps1") -Leaf -Resolve ) | Sort-Object
|
||||
$actual.GetType().BaseType.Name | Should Be "Array"
|
||||
$actual[0] | Should Be $testFile1
|
||||
$actual[1] | Should Be $testFile2
|
||||
|
||||
Remove-Item $testDir -Recurse -ErrorAction Ignore
|
||||
Test-Path $testDir | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to tell if a given path is an absolute path" {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
. $here/Test-Common.ps1
|
||||
. (Join-Path -Path $here -ChildPath Test-Common.ps1)
|
||||
|
||||
Describe "Start-Process" {
|
||||
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
||||
$pingDirectory = Split-Path $pingCommand -Parent
|
||||
$tempFile = "$(GetTempDir)/PSTest"
|
||||
$assetsFile = $here + "/assets/SortTest.txt"
|
||||
$tempFile = Join-Path -Path $(GetTempDir) -ChildPath PSTest
|
||||
$assetsFile = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath SortTest.txt
|
||||
$windows = IsWindows
|
||||
if ($windows)
|
||||
{
|
||||
|
||||
@@ -4,29 +4,31 @@ Describe "Tee-Object" {
|
||||
|
||||
Context "Validate Tee-Object is correctly forking output" {
|
||||
|
||||
$testfile = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath testfile.txt
|
||||
|
||||
It "Should return the output to the screen and to the variable" {
|
||||
$teefile = "$here/assets/testfile.txt"
|
||||
$teefile = $testfile
|
||||
echo teeobjecttest1 | Tee-Object -variable teeresults
|
||||
$teeresults | Should Be "teeobjecttest1"
|
||||
Remove-Item $teefile -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "Should return the output to the screen and to the variable from the alias" {
|
||||
$teefile = "$here/assets/testfile.txt"
|
||||
$teefile = $testfile
|
||||
echo teeobjecttest2 | tee -variable teeresults
|
||||
$teeresults | Should Be "teeobjecttest2"
|
||||
Remove-Item $teefile -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "Should tee the output to a file" {
|
||||
$teefile = "$here/assets/testfile.txt"
|
||||
$teefile = $testfile
|
||||
echo teeobjecttest3 | Tee-Object $teefile
|
||||
Get-Content $teefile | Should Be "teeobjecttest3"
|
||||
Remove-Item $teefile -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "Should tee the output to a file using the alias" {
|
||||
$teefile = "$here/assets/testfile.txt"
|
||||
$teefile = $testfile
|
||||
echo teeobjecttest4 | tee $teefile
|
||||
Get-Content $teefile | Should Be "teeobjecttest4"
|
||||
Remove-item $teefile -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
Describe "Test-Path" {
|
||||
BeforeAll {
|
||||
$guid = [Guid]::NewGuid().Guid
|
||||
$testdirectory = New-Item -Path $guid -ItemType Directory -Force
|
||||
$testdirectory = $TestDrive
|
||||
$testfilename = New-Item -path $testdirectory -Name testfile.txt -ItemType file -Value 1 -force
|
||||
$testfile = $tmp + "/" + $testfilename
|
||||
|
||||
# populate with additional files
|
||||
New-Item -Path $testdirectory -Name datestfile -value 1 -ItemType file | Out-Null
|
||||
New-Item -Path $testdirectory -Name gatestfile -value 1 -ItemType file | Out-Null
|
||||
}
|
||||
New-Item -Path $testdirectory -Name usr -value 1 -ItemType directory | Out-Null
|
||||
|
||||
AfterAll {
|
||||
Remove-Item -Path $testdirectory -Recurse
|
||||
$nonExistantDir = Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin
|
||||
$nonExistantPath = Join-Path -Path (Join-Path -Path (Join-Path -Path $testdirectory -ChildPath usr) -ChildPath bin) -ChildPath error
|
||||
}
|
||||
|
||||
It "Should be called on an existing path without error" {
|
||||
@@ -24,15 +22,15 @@
|
||||
{ $testdirectory | Test-Path } | Should Not Throw
|
||||
|
||||
$testdirectory | Test-Path | Should Be $true
|
||||
"/usr/bin/totallyFakeDirectory" | Test-Path | Should Be $false
|
||||
$nonExistantDir | Test-Path | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be called on a nonexistant path without error" {
|
||||
{ Test-Path -Path "aNonexistant/path/that/should/error" } | Should Not Throw
|
||||
{ Test-Path -Path $nonExistantPath } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should return false for a nonexistant path" {
|
||||
Test-Path -Path "aNonexistant/path/that/should/error" | Should Be $false
|
||||
Test-Path -Path $nonExistantPath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true for an existing path" {
|
||||
@@ -40,16 +38,16 @@
|
||||
}
|
||||
|
||||
It "Should be able to accept a regular expression" {
|
||||
{ Test-Path -Path "/u*" } | Should Not Throw
|
||||
{ Test-Path -Path "/u[a-z]r" } | Should Not Throw
|
||||
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") } | Should Not Throw
|
||||
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to return the correct result when a regular expression is used" {
|
||||
Test-Path -Path "/u*" | Should Be $true
|
||||
Test-Path -Path "/u[a-z]*" | Should Be $true
|
||||
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $true
|
||||
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[a-z]*") | Should Be $true
|
||||
|
||||
Test-Path -Path "/aoeu*" | Should Be $false
|
||||
Test-Path -Path "/u[A-Z]" | Should Be $false
|
||||
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "aoeu*") | Should Be $false
|
||||
Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "u[A-Z]") | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return false when the Leaf pathtype is used on a directory" {
|
||||
@@ -69,20 +67,20 @@
|
||||
}
|
||||
|
||||
It "Should be able to search multiple regular expressions using the include switch" {
|
||||
{ Test-Path -Path "$testdirectory/*" -Include t* } | Should Be $true
|
||||
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Include t* } | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to exclude a regular expression using the exclude switch" {
|
||||
{ Test-Path -Path "$testdirectory/*" -Exclude v* } | Should Be $true
|
||||
{ Test-Path -Path (Join-Path -Path $testdirectory -ChildPath "*") -Exclude v* } | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to exclude multiple regular expressions using the exclude switch" {
|
||||
# tests whether there's any files in the /usr directory that don't start with 'd' or 'g'
|
||||
# tests whether there's any files in the usr directory that don't start with 'd' or 'g'
|
||||
{ Test-Path -Path $testfilename -Exclude d*, g* } | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return true if the syntax of the path is correct when using the IsValid switch" {
|
||||
{ Test-Path -Path /this/is/a/valid/path -IsValid } | Should Be $true
|
||||
{ Test-Path -Path $nonExistantPath -IsValid } | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return false if the syntax of the path is incorrect when using the IsValid switch" {
|
||||
@@ -107,13 +105,13 @@
|
||||
}
|
||||
|
||||
It "Should return false if regular expressions are used with the LiteralPath switch" {
|
||||
Test-Path -LiteralPath /*sr/bin | Should Be $false
|
||||
Test-Path -LiteralPath /[usth]sr/bin | Should Be $false
|
||||
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
|
||||
Test-Path -LiteralPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" {
|
||||
Test-Path -PSPath /*sr/bin | Should Be $false
|
||||
Test-Path -PSPath /[aoeu]sr/bin | Should Be $false
|
||||
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u*") | Should Be $false
|
||||
Test-Path -PSPath (Join-Path -Path $testdirectory -ChildPath "u[a-z]r") | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true if used on components other than filesystem objects" {
|
||||
|
||||
Reference in New Issue
Block a user