我正在寻找xUnit类型的单元测试框架,它允许我使用PowerShell脚本测试PowerShell函数.
我想做这样的事情.索引到函数数组并为所需的循环索引应用适当的函数.
for ($i = 0; $i -lt 9; $i++)
{
$Fields[$i] = $Fields[$i] | $($FunctionTable[$i])
}
#F1..F9 are defined functions or rather filter functions
$FunctionTable = {F1},
{F2},
{F3},
{F4},
{F5},
{F6},
{F7},
{F8},
{F9}
Run Code Online (Sandbox Code Playgroud) 是否可以访问Register-ObjectEvent cmdlet的-Action脚本块中的Event参数?如果是,怎么样?
这是一个例子:
function ChildF()
{
#Creating new function dynamically
$DynFEx =
@"
function DynF()
{
"Hello DynF"
}
"@
Invoke-Expression $DynFEx
#Calling in ChildF scope Works
DynF
}
ChildF
#Calling in parent scope doesn't. It doesn't exist here
DynF
Run Code Online (Sandbox Code Playgroud)
我想知道你是否能够以这样的方式定义DynF,使其在ChildF之外"可见".
例如:
function TestThis()
{
[MySpecialCustomAttribute]
[CmdletBinding()]
Param(...)
Process{...}
}
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚我的脚本是在PowerShell.exe中运行还是在ISE中运行.如果我在PowerShell.exe中运行,那么我想改变控制台窗口的大小,但如果不这样做,我不想影响ISE.
powershell ×6
function ×3
arrays ×1
attributes ×1
dynamic ×1
events ×1
mono ×1
pointers ×1
scope ×1
unit-testing ×1