Use $PSScriptRoot instead of assigning $here

This commit is contained in:
Andrew Schwartzmeyer committed 2016-03-04 14:42:08 -08:00
1 parent c37a0c4a64
commit 15f8433d98
14 files changed
+32 -61

No files matched your search

+1 -4
View File
@@ -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)
+8 -10
View File
@@ -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 }
}
}
+5 -7
View File
@@ -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" {
+1 -3
View File
@@ -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" {
+2 -4
View File
@@ -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
@@ -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" {
+2 -4
View File
@@ -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"
+1 -3
View File
@@ -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)
}
+1 -3
View File
@@ -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
@@ -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
+1 -2
View File
@@ -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 {
+2 -4
View File
@@ -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
+4 -8
View File
@@ -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"
}
+1 -3
View File
@@ -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