Files

66 lines
2.0 KiB
PowerShell
Raw Permalink Normal View History

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe 'Testing of MyInvocation' -Tags "CI" {
2016-09-15 11:27:44 -07:00
It 'MyInvocation works in Function' {
function myfunc
{
$MyInvocation.Line.IndexOf("myfunc") | Should -BeGreaterThan -1
2016-09-15 11:27:44 -07:00
}
{ . myfunc } | Should -Not -Throw
{& myfunc } | Should -Not -Throw
2016-09-15 11:27:44 -07:00
}
It 'MyInvocation works in Filter' {
filter myfilter
{
$MyInvocation.Line.IndexOf("myfilter") | Should -BeGreaterThan -1
2016-09-15 11:27:44 -07:00
}
{. myfilter } | Should -Not -Throw
{ & myfilter } | Should -Not -Throw
2016-09-15 11:27:44 -07:00
}
Context 'MyInvocation works with multi-line invocations' {
It 'MyInvocation.Statement works in & Script block' {
$a = & {
$MyInvocation.Statement
}
$a.IndexOf('& {
$MyInvocation.Statement
}') |Should -BeGreaterThan -1
}
It 'MyInvocation.Statement works in dot sourced Script block' {
$a = . {
$MyInvocation.Statement
}
$a.IndexOf('. {
$MyInvocation.Statement
}') |Should -BeGreaterThan -1
}
}
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}
$a.IndexOf('$a = . {$MyInvocation.Line}') | Should -BeGreaterThan -1
2016-09-15 11:27:44 -07:00
}
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
2016-09-15 11:27:44 -07:00
}
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
2016-09-15 11:27:44 -07:00
}
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
2016-09-15 11:27:44 -07:00
}
}
}