mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Use $PSScriptRoot instead of assigning $here
This commit is contained in:
1 parent
c37a0c4a64
commit
15f8433d98
14 files changed
+32
-61
No files matched your search
@@ -1,8 +1,5 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
. (Join-Path -Path $here -ChildPath Test-Common.ps1)
|
|
||||||
|
|
||||||
Describe "Export-Alias" {
|
Describe "Export-Alias" {
|
||||||
$testAliasDirectory = Join-Path -Path $(GetTempDir) -ChildPath ExportAliasTestDirectory
|
$testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory
|
||||||
$testAliases = "TestAliases"
|
$testAliases = "TestAliases"
|
||||||
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
$fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases)
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Get-Item" {
|
||||||
|
|
||||||
Describe "Get-Item" {
|
|
||||||
It "Should list all the items in the current working directory when asterisk is used" {
|
It "Should list all the items in the current working directory when asterisk is used" {
|
||||||
(Get-Item (Join-Path -Path $here -ChildPath "*")).GetType().BaseType | Should Be 'array'
|
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().BaseType | Should Be 'array'
|
||||||
(Get-Item (Join-Path -Path $here -ChildPath "*")).GetType().Name | Should Be 'Object[]'
|
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath "*")).GetType().Name | Should Be 'Object[]'
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should return the name of the current working directory when a dot is used" {
|
It "Should return the name of the current working directory when a dot is used" {
|
||||||
(Get-Item $here).GetType().BaseType | Should Be 'System.IO.FileSystemInfo'
|
(Get-Item $PSScriptRoot).GetType().BaseType | Should Be 'System.IO.FileSystemInfo'
|
||||||
(Get-Item $here).Name | Should Be (Split-Path $here -Leaf)
|
(Get-Item $PSScriptRoot).Name | Should Be (Split-Path $PSScriptRoot -Leaf)
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should return the proper Name and BaseType for directory objects vs file system objects" {
|
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 $PSScriptRoot).GetType().Name | Should Be 'DirectoryInfo'
|
||||||
(Get-Item (Join-Path -Path $here -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo'
|
(Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo'
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have mode flags set" {
|
It "Should have mode flags set" {
|
||||||
ls $here | foreach-object { $_.Mode | Should Not BeNullOrEmpty }
|
ls $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Get-ItemProperty" {
|
||||||
|
$currentDirectory = Split-Path $PSScriptRoot -Leaf
|
||||||
Describe "Get-ItemProperty" {
|
$parentDirectory = Split-Path (Join-Path -Path $PSScriptRoot -ChildPath "..") -Leaf
|
||||||
$currentDirectory = Split-Path $here -Leaf
|
|
||||||
$parentDirectory = Split-Path (Join-Path -Path $here -ChildPath "..") -Leaf
|
|
||||||
$tempDirectory = $TestDrive
|
$tempDirectory = $TestDrive
|
||||||
$testprovider = (Get-Item $tempDirectory).PSDrive.Name
|
$testprovider = (Get-Item $tempDirectory).PSDrive.Name
|
||||||
|
|
||||||
@@ -11,11 +9,11 @@ Describe "Get-ItemProperty" {
|
|||||||
New-Item $testfile -ItemType file -Force
|
New-Item $testfile -ItemType file -Force
|
||||||
|
|
||||||
It "Should be able to be called on in the current directory" {
|
It "Should be able to be called on in the current directory" {
|
||||||
$(Get-ItemProperty $here).Name | Should Be $currentDirectory
|
$(Get-ItemProperty $PSScriptRoot).Name | Should Be $currentDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to be called on a parent directory" {
|
It "Should be able to be called on a parent directory" {
|
||||||
(Get-ItemProperty $here/..).Name | Should Be $parentDirectory
|
(Get-ItemProperty $PSScriptRoot/..).Name | Should Be $parentDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to be called on a directory using the path switch" {
|
It "Should be able to be called on a directory using the path switch" {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
|
|
||||||
Describe "Import-Alias" {
|
Describe "Import-Alias" {
|
||||||
$pesteraliasfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath pesteralias.txt
|
$pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt
|
||||||
|
|
||||||
Context "Validate ability to import alias file" {
|
Context "Validate ability to import alias file" {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Import-Csv" {
|
||||||
|
$testCsv = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestCsv.csv
|
||||||
Describe "Import-Csv" {
|
|
||||||
$testCsv = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath TestCsv.csv
|
|
||||||
|
|
||||||
It "Should be able to call without error" {
|
It "Should be able to call without error" {
|
||||||
{ Import-Csv $testCsv } | Should Not Throw
|
{ Import-Csv $testCsv } | Should Not Throw
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$assetsDir = Join-Path -Path $PSScriptRoot -ChildPath assets
|
||||||
$assetsDir = Join-Path -Path $here -ChildPath assets
|
|
||||||
|
|
||||||
Describe "Import-LocalizedData" {
|
Describe "Import-LocalizedData" {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
|
|
||||||
Describe "Invoke-Expression" {
|
Describe "Invoke-Expression" {
|
||||||
|
|
||||||
Context "Should execute the invoked command validly" {
|
Context "Should execute the invoked command validly" {
|
||||||
@@ -13,7 +11,7 @@ Describe "Invoke-Expression" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It "Should return the echoed text from a script" {
|
It "Should return the echoed text from a script" {
|
||||||
$testfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
|
||||||
$testcommand = "echo pestertestscript"
|
$testcommand = "echo pestertestscript"
|
||||||
$testcommand | Add-Content -Path $testfile
|
$testcommand | Add-Content -Path $testfile
|
||||||
(Invoke-Expression $testfile) | Should Be "pestertestscript"
|
(Invoke-Expression $testfile) | Should Be "pestertestscript"
|
||||||
@@ -21,7 +19,7 @@ Describe "Invoke-Expression" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It "Should return the echoed text from a script from the alias" {
|
It "Should return the echoed text from a script from the alias" {
|
||||||
$testfile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
$testfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
|
||||||
$testcommand = "echo pestertestscript"
|
$testcommand = "echo pestertestscript"
|
||||||
$testcommand | Add-Content -Path $testfile
|
$testcommand | Add-Content -Path $testfile
|
||||||
(iex $testfile) | Should Be "pestertestscript"
|
(iex $testfile) | Should Be "pestertestscript"
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
|
|
||||||
# While Core PowerShell does not support the JSON cmdlets, a third
|
# While Core PowerShell does not support the JSON cmdlets, a third
|
||||||
# party C# library, [Json.NET](http://www.newtonsoft.com/json), can be
|
# party C# library, [Json.NET](http://www.newtonsoft.com/json), can be
|
||||||
# loaded into PowerShell and used directly.
|
# loaded into PowerShell and used directly.
|
||||||
@@ -18,7 +16,7 @@ Describe "Json.NET LINQ Parsing" {
|
|||||||
[Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($path)
|
[Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($path)
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
$jsonFile = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath TestJson.json
|
$jsonFile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestJson.json
|
||||||
$jsonData = (Get-Content $jsonFile | Out-String)
|
$jsonData = (Get-Content $jsonFile | Out-String)
|
||||||
$json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData)
|
$json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
|
|
||||||
Describe "Measure-Command" {
|
Describe "Measure-Command" {
|
||||||
|
|
||||||
Context "Validate return types for Measure-Command" {
|
Context "Validate return types for Measure-Command" {
|
||||||
@@ -16,7 +14,7 @@ Describe "Measure-Command" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
It "Should return TimeSpan after executing a cmdlet" {
|
It "Should return TimeSpan after executing a cmdlet" {
|
||||||
$pesterscript = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath echoscript.ps1
|
$pesterscript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath echoscript.ps1
|
||||||
$testfile = $pesterscript
|
$testfile = $pesterscript
|
||||||
$testcommand = "echo pestertestscript"
|
$testcommand = "echo pestertestscript"
|
||||||
$testcommand | Add-Content -Path $testfile
|
$testcommand | Add-Content -Path $testfile
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Remove-PSBreakpoint" {
|
||||||
|
|
||||||
Describe "Remove-PSBreakpoint" {
|
|
||||||
# Set up test script
|
# Set up test script
|
||||||
$testScript = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
|
$testScript = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath psbreakpointtestscript.ps1
|
||||||
|
|
||||||
$script = "`$var = 1
|
$script = "`$var = 1
|
||||||
`$var2 = Get-Process
|
`$var2 = Get-Process
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1)
|
||||||
. (Join-Path -Path $here -ChildPath Test-Mocks.ps1)
|
|
||||||
|
|
||||||
Describe "Select-Object" {
|
Describe "Select-Object" {
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Set-PSBreakpoint" {
|
||||||
|
|
||||||
Describe "Set-PSBreakpoint" {
|
|
||||||
# Set up test script
|
# Set up test script
|
||||||
$testScript = Join-Path -Path $here -ChildPath psbreakpointtestscript.ps1
|
$testScript = Join-Path -Path $PSScriptRoot -ChildPath psbreakpointtestscript.ps1
|
||||||
|
|
||||||
"`$var = 1 " > $testScript
|
"`$var = 1 " > $testScript
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
Describe "Start-Process" {
|
||||||
. (Join-Path -Path $here -ChildPath Test-Common.ps1)
|
|
||||||
|
|
||||||
Describe "Start-Process" {
|
|
||||||
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
||||||
$pingDirectory = Split-Path $pingCommand -Parent
|
$pingDirectory = Split-Path $pingCommand -Parent
|
||||||
$tempFile = Join-Path -Path $(GetTempDir) -ChildPath PSTest
|
$tempFile = Join-Path -Path $TestDrive -ChildPath PSTest
|
||||||
$assetsFile = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath SortTest.txt
|
$assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt
|
||||||
$windows = IsWindows
|
if ($IsWindows)
|
||||||
if ($windows)
|
|
||||||
{
|
{
|
||||||
$pingParam = "localhost -n 4"
|
$pingParam = "localhost -n 4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
|
|
||||||
Describe "Tee-Object" {
|
Describe "Tee-Object" {
|
||||||
|
|
||||||
Context "Validate Tee-Object is correctly forking output" {
|
Context "Validate Tee-Object is correctly forking output" {
|
||||||
|
|
||||||
$testfile = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath testfile.txt
|
$testfile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath testfile.txt
|
||||||
|
|
||||||
It "Should return the output to the screen and to the variable" {
|
It "Should return the output to the screen and to the variable" {
|
||||||
$teefile = $testfile
|
$teefile = $testfile
|
||||||
|
|||||||
Reference in new issue
Block a user