2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 18:23:53 +01:00
|
|
|
# Licensed under the MIT License.
|
|
|
|
Describe 'Testing of MyInvocation' -Tags "CI" {
|
2016-09-15 20:27:44 +02:00
|
|
|
It 'MyInvocation works in Function' {
|
|
|
|
|
|
|
|
function myfunc
|
|
|
|
{
|
2018-03-21 18:47:08 +01:00
|
|
|
$MyInvocation.Line.IndexOf("myfunc") | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
2018-03-21 18:47:08 +01:00
|
|
|
{ . myfunc } | Should -Not -Throw
|
|
|
|
{& myfunc } | Should -Not -Throw
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It 'MyInvocation works in Filter' {
|
|
|
|
|
|
|
|
filter myfilter
|
|
|
|
{
|
2018-03-21 18:47:08 +01:00
|
|
|
$MyInvocation.Line.IndexOf("myfilter") | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
2018-03-21 18:47:08 +01:00
|
|
|
{. myfilter } | Should -Not -Throw
|
|
|
|
{ & myfilter } | Should -Not -Throw
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:31:14 +01:00
|
|
|
Context 'MyInvocation works in Script block' {
|
2016-09-15 20:27:44 +02:00
|
|
|
|
|
|
|
It 'MyInvocation works in dot sourced Script block' {
|
2017-01-16 22:31:14 +01:00
|
|
|
$a = . {$MyInvocation.Line}
|
2018-03-21 18:47:08 +01:00
|
|
|
$a.IndexOf('$a = . {$MyInvocation.Line}') | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
2017-01-16 22:31:14 +01:00
|
|
|
It 'MyInvocation works in & Script block2' {
|
2016-09-15 20:27:44 +02:00
|
|
|
$a = & {$MyInvocation.Line}
|
2018-03-21 18:47:08 +01:00
|
|
|
$a.IndexOf('$a = & {$MyInvocation.Line}') | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:31:14 +01:00
|
|
|
It 'MyInvocation works when run Script file' {
|
2016-09-15 20:27:44 +02:00
|
|
|
$a = & {$MyInvocation.ScriptName}
|
2018-03-21 18:47:08 +01:00
|
|
|
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
2017-01-16 22:31:14 +01:00
|
|
|
|
2016-09-15 20:27:44 +02:00
|
|
|
It 'MyInvocation works when dot source Script file' {
|
|
|
|
$a = . {$MyInvocation.ScriptName}
|
2018-03-21 18:47:08 +01:00
|
|
|
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should -BeGreaterThan -1
|
2016-09-15 20:27:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|