Files
PowerShell/test/powershell/Language/Scripting/MyInvocation.Tests.ps1
T

45 lines
1.4 KiB
PowerShell
Raw Normal View History

2016-09-15 11:27:44 -07:00
Describe 'Testing of MyInvocation' -Tags "CI" {
It 'MyInvocation works in Function' {
function myfunc
{
$MyInvocation.Line.IndexOf("myfunc") | Should BeGreaterThan -1
}
{ . myfunc } | Should Not Throw
{& myfunc } | Should Not Throw
}
It 'MyInvocation works in Filter' {
filter myfilter
{
$MyInvocation.Line.IndexOf("myfilter") | Should BeGreaterThan -1
}
{. myfilter } | Should Not Throw
{ & myfilter } | Should Not Throw
}
2017-01-16 13:31:14 -08:00
Context 'MyInvocation works in Script block' {
2016-09-15 11:27:44 -07:00
It 'MyInvocation works in dot sourced Script block' {
2017-01-16 13:31:14 -08:00
$a = . {$MyInvocation.Line}
2016-09-15 11:27:44 -07:00
$a.IndexOf('$a = . {$MyInvocation.Line}') | Should BeGreaterThan -1
}
2017-01-16 13:31:14 -08:00
It 'MyInvocation works in & Script block2' {
2016-09-15 11:27:44 -07:00
$a = & {$MyInvocation.Line}
$a.IndexOf('$a = & {$MyInvocation.Line}') | Should BeGreaterThan -1
}
2017-01-16 13:31:14 -08:00
It 'MyInvocation works when run Script file' {
2016-09-15 11:27:44 -07:00
$a = & {$MyInvocation.ScriptName}
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should BeGreaterThan -1
}
2017-01-16 13:31:14 -08:00
2016-09-15 11:27:44 -07:00
It 'MyInvocation works when dot source Script file' {
$a = . {$MyInvocation.ScriptName}
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should BeGreaterThan -1
}
}
}