Files
PowerShell-PowerShell/test/powershell/Language/Scripting/MyInvocation.Tests.ps1
T
Steve Lee c1c5344a88 Update copyright and license headers (#6134)
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files.

Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks.

Separate PR coming to update contribution document for new source files: #6140

Manually reviewed each change.

Fix #6073
2018-02-13 09:23:53 -08:00

48 lines
1.4 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
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
}
Context 'MyInvocation works in Script block' {
It 'MyInvocation works in dot sourced Script block' {
$a = . {$MyInvocation.Line}
$a.IndexOf('$a = . {$MyInvocation.Line}') | Should BeGreaterThan -1
}
It 'MyInvocation works in & Script block2' {
$a = & {$MyInvocation.Line}
$a.IndexOf('$a = & {$MyInvocation.Line}') | Should BeGreaterThan -1
}
It 'MyInvocation works when run Script file' {
$a = & {$MyInvocation.ScriptName}
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should BeGreaterThan -1
}
It 'MyInvocation works when dot source Script file' {
$a = . {$MyInvocation.ScriptName}
$a.ToLower().IndexOf("myinvocation.tests.ps1") | Should BeGreaterThan -1
}
}
}