Files
PowerShell-PowerShell/test/powershell/Language/Scripting/ConstrainedLanguageMode.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

43 lines
1.5 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Test constrained language mode" -Tags "CI" {
It "dynamic invocation on non-PowerShell thread should work" {
$refAssemblies = @()
if (!$IsCoreCLR) {
$refAssemblies += "Microsoft.CSharp"
}
$t,$null = Add-Type -ReferencedAssemblies $refAssemblies -WarningAction Ignore -PassThru @"
public class BinderBug$(Get-Date -Format FileDateTime)
{
public static object Test(System.Management.Automation.PSObject psobj)
{
// Invoke a method through PSObject, but with dynamic, so we get PowerShell's dynamic site binder involved
// And we do this on a different thread so there is no ExecutionContext/runspace to check the language mode
// The actual method called doesn't really matter.
return System.Threading.Tasks.Task.Run(() => ((dynamic)psobj).AddCommand("Get-Command")).Result;
}
}
"@
$o = [powershell]::Create()
$t::Test($o) | Should Be $o
try
{
# Set language mode to ConstrainedLanguage on a different runspace (so it doesn't affect this runspace)
$ps = [powershell]::Create()
$null = $ps.AddScript('$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"')
$null = $ps.Invoke()
$t::Test($o) | Should Be $o
}
finally
{
$ps.Dispose()
}
}
}