diff --git a/test/powershell/Export-Alias.Tests.ps1 b/test/powershell/Export-Alias.Tests.ps1 index 8de44f20d..88a228b56 100644 --- a/test/powershell/Export-Alias.Tests.ps1 +++ b/test/powershell/Export-Alias.Tests.ps1 @@ -1,8 +1,5 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path -. (Join-Path -Path $here -ChildPath Test-Common.ps1) - Describe "Export-Alias" { - $testAliasDirectory = Join-Path -Path $(GetTempDir) -ChildPath ExportAliasTestDirectory + $testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory $testAliases = "TestAliases" $fulltestpath = Join-Path -Path $($testAliasDirectory) -ChildPath $($testAliases) diff --git a/test/powershell/Get-Item.Tests.ps1 b/test/powershell/Get-Item.Tests.ps1 index afd2d6bc5..3dd6acafc 100644 --- a/test/powershell/Get-Item.Tests.ps1 +++ b/test/powershell/Get-Item.Tests.ps1 @@ -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" { - (Get-Item (Join-Path -Path $here -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().BaseType | Should Be 'array' + (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" { - (Get-Item $here).GetType().BaseType | Should Be 'System.IO.FileSystemInfo' - (Get-Item $here).Name | Should Be (Split-Path $here -Leaf) + (Get-Item $PSScriptRoot).GetType().BaseType | Should Be 'System.IO.FileSystemInfo' + (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" { - (Get-Item $here).GetType().Name | Should Be 'DirectoryInfo' - (Get-Item (Join-Path -Path $here -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo' + (Get-Item $PSScriptRoot).GetType().Name | Should Be 'DirectoryInfo' + (Get-Item (Join-Path -Path $PSScriptRoot -ChildPath Get-Item.Tests.ps1)).GetType().Name | Should Be 'FileInfo' } It "Should have mode flags set" { - ls $here | foreach-object { $_.Mode | Should Not BeNullOrEmpty } + ls $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty } } } diff --git a/test/powershell/Get-ItemProperty.Tests.ps1 b/test/powershell/Get-ItemProperty.Tests.ps1 index f0c9bf009..33dfe8c61 100644 --- a/test/powershell/Get-ItemProperty.Tests.ps1 +++ b/test/powershell/Get-ItemProperty.Tests.ps1 @@ -1,8 +1,6 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - -Describe "Get-ItemProperty" { - $currentDirectory = Split-Path $here -Leaf - $parentDirectory = Split-Path (Join-Path -Path $here -ChildPath "..") -Leaf +Describe "Get-ItemProperty" { + $currentDirectory = Split-Path $PSScriptRoot -Leaf + $parentDirectory = Split-Path (Join-Path -Path $PSScriptRoot -ChildPath "..") -Leaf $tempDirectory = $TestDrive $testprovider = (Get-Item $tempDirectory).PSDrive.Name @@ -11,11 +9,11 @@ Describe "Get-ItemProperty" { New-Item $testfile -ItemType file -Force 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" { - (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" { diff --git a/test/powershell/Import-Alias.Tests.ps1 b/test/powershell/Import-Alias.Tests.ps1 index e6f1b98a4..78665e125 100644 --- a/test/powershell/Import-Alias.Tests.ps1 +++ b/test/powershell/Import-Alias.Tests.ps1 @@ -1,7 +1,5 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - 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" { diff --git a/test/powershell/Import-Csv.Tests.ps1 b/test/powershell/Import-Csv.Tests.ps1 index 7f9143297..fc15ddea1 100644 --- a/test/powershell/Import-Csv.Tests.ps1 +++ b/test/powershell/Import-Csv.Tests.ps1 @@ -1,7 +1,5 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - -Describe "Import-Csv" { - $testCsv = Join-Path -Path (Join-Path $here -ChildPath assets) -ChildPath TestCsv.csv +Describe "Import-Csv" { + $testCsv = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath TestCsv.csv It "Should be able to call without error" { { Import-Csv $testCsv } | Should Not Throw diff --git a/test/powershell/Import-LocalizedData.Tests.ps1 b/test/powershell/Import-LocalizedData.Tests.ps1 index 640c88e46..5ec0e1c85 100644 --- a/test/powershell/Import-LocalizedData.Tests.ps1 +++ b/test/powershell/Import-LocalizedData.Tests.ps1 @@ -1,5 +1,4 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path -$assetsDir = Join-Path -Path $here -ChildPath assets +$assetsDir = Join-Path -Path $PSScriptRoot -ChildPath assets Describe "Import-LocalizedData" { diff --git a/test/powershell/Invoke-Expression.Tests.ps1 b/test/powershell/Invoke-Expression.Tests.ps1 index ce14bd657..da3cbd739 100644 --- a/test/powershell/Invoke-Expression.Tests.ps1 +++ b/test/powershell/Invoke-Expression.Tests.ps1 @@ -1,5 +1,3 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - Describe "Invoke-Expression" { Context "Should execute the invoked command validly" { @@ -13,7 +11,7 @@ Describe "Invoke-Expression" { } 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 | Add-Content -Path $testfile (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" { - $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 | Add-Content -Path $testfile (iex $testfile) | Should Be "pestertestscript" diff --git a/test/powershell/Json.Tests.ps1 b/test/powershell/Json.Tests.ps1 index 2d58cc52e..eda930c01 100644 --- a/test/powershell/Json.Tests.ps1 +++ b/test/powershell/Json.Tests.ps1 @@ -1,5 +1,3 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - # While Core PowerShell does not support the JSON cmdlets, a third # party C# library, [Json.NET](http://www.newtonsoft.com/json), can be # loaded into PowerShell and used directly. @@ -18,7 +16,7 @@ Describe "Json.NET LINQ Parsing" { [Microsoft.PowerShell.CoreCLR.AssemblyExtensions]::LoadFrom($path) 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) $json = [Newtonsoft.Json.Linq.JObject]::Parse($jsonData) } diff --git a/test/powershell/Measure-Command.Tests.ps1 b/test/powershell/Measure-Command.Tests.ps1 index 018916066..0f3fc7bc9 100644 --- a/test/powershell/Measure-Command.Tests.ps1 +++ b/test/powershell/Measure-Command.Tests.ps1 @@ -1,5 +1,3 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - Describe "Measure-Command" { Context "Validate return types for Measure-Command" { @@ -16,7 +14,7 @@ Describe "Measure-Command" { } 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 $testcommand = "echo pestertestscript" $testcommand | Add-Content -Path $testfile diff --git a/test/powershell/Remove-PSBreakpoint.Tests.ps1 b/test/powershell/Remove-PSBreakpoint.Tests.ps1 index 294576fc6..e97a582d8 100644 --- a/test/powershell/Remove-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Remove-PSBreakpoint.Tests.ps1 @@ -1,8 +1,6 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - -Describe "Remove-PSBreakpoint" { +Describe "Remove-PSBreakpoint" { # 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 `$var2 = Get-Process diff --git a/test/powershell/Select-Object.Tests.ps1 b/test/powershell/Select-Object.Tests.ps1 index bdeab7d73..639b230aa 100644 --- a/test/powershell/Select-Object.Tests.ps1 +++ b/test/powershell/Select-Object.Tests.ps1 @@ -1,5 +1,4 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path -. (Join-Path -Path $here -ChildPath Test-Mocks.ps1) +. (Join-Path -Path $PSScriptRoot -ChildPath Test-Mocks.ps1) Describe "Select-Object" { BeforeEach { diff --git a/test/powershell/Set-PSBreakpoint.Tests.ps1 b/test/powershell/Set-PSBreakpoint.Tests.ps1 index a4a957e35..ebf11952e 100644 --- a/test/powershell/Set-PSBreakpoint.Tests.ps1 +++ b/test/powershell/Set-PSBreakpoint.Tests.ps1 @@ -1,8 +1,6 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - -Describe "Set-PSBreakpoint" { +Describe "Set-PSBreakpoint" { # Set up test script - $testScript = Join-Path -Path $here -ChildPath psbreakpointtestscript.ps1 + $testScript = Join-Path -Path $PSScriptRoot -ChildPath psbreakpointtestscript.ps1 "`$var = 1 " > $testScript diff --git a/test/powershell/Start-Process.Tests.ps1 b/test/powershell/Start-Process.Tests.ps1 index c31f6ade7..6880f79ee 100644 --- a/test/powershell/Start-Process.Tests.ps1 +++ b/test/powershell/Start-Process.Tests.ps1 @@ -1,13 +1,9 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path -. (Join-Path -Path $here -ChildPath Test-Common.ps1) - -Describe "Start-Process" { +Describe "Start-Process" { $pingCommand = (Get-Command -CommandType Application ping)[0].Definition $pingDirectory = Split-Path $pingCommand -Parent - $tempFile = Join-Path -Path $(GetTempDir) -ChildPath PSTest - $assetsFile = Join-Path -Path (Join-Path -Path $here -ChildPath assets) -ChildPath SortTest.txt - $windows = IsWindows - if ($windows) + $tempFile = Join-Path -Path $TestDrive -ChildPath PSTest + $assetsFile = Join-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath assets) -ChildPath SortTest.txt + if ($IsWindows) { $pingParam = "localhost -n 4" } diff --git a/test/powershell/Tee-Object.Tests.ps1 b/test/powershell/Tee-Object.Tests.ps1 index 9cd6a13d2..321353f56 100644 --- a/test/powershell/Tee-Object.Tests.ps1 +++ b/test/powershell/Tee-Object.Tests.ps1 @@ -1,10 +1,8 @@ -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - Describe "Tee-Object" { 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" { $teefile = $testfile