【发布时间】:2021-01-08 11:07:32
【问题描述】:
我正在尝试为 Pester 的 Should cmdlet 创建一个包装器(代理)。可能的用例包括transparent logging of test input even in case of success 和improve the way Pester logs objects of certain types, e. g. hashtable。
由于Should 是一个高级功能,因此通过$args splatting 转发参数不起作用。
所以我尝试使用System.Management.Automation.ProxyCommand::Create() 生成包装器,如this answer 所述:
$cmd = Get-Command Should
$wrapperSource = [System.Management.Automation.ProxyCommand]::Create( $cmd )
$wrapperSource >should_wrapper.ps1
调用包装器时,Powershell 输出以下错误消息:
应该:无法使用指定的命名解析参数集 参数。发出的一个或多个参数不能一起使用或 提供的参数数量不足。
看起来包装器生成器不理解dynamicparam declaration of Should。
如何在不复制 Pester 代码的情况下为 Pester 的 Should 编写通用包装器?
【问题讨论】:
标签: powershell wrapper pester