我正在尝试解析 Pester 脚本并从
最终,我希望返回一个集合,其中包含
-Tag
参数中提取值。有人知道如何使用 [System.Management.Automation.PSParser]
实现这一点吗?我曾经考虑过必须循环遍历从[System.Management.Automation.PSParser]::Tokenize()
返回的标记,但这似乎相当不可靠,因为-Tag
的值可以以许多不同的格式给出,所以并不实用。最终,我希望返回一个集合,其中包含
Describe
块名称以及该块的标记列表(如果有)。Name Tags
---- ----
Section1 {tag1, tag2}
Section2 {foo, bar}
Section3 {asdf}
Section4 {}
这里是我正在使用的样例 Pester 测试。
describe 'Section1' -Tag @('tag1', 'tag2') {
it 'blah1' {
$true | should be $true
}
}
describe 'Section2' -Tag 'foo', 'bar' {
it 'blah2' {
$true | should be $true
}
}
describe 'Section3' -Tag 'asdf'{
it 'blah3' {
$true | should be $true
}
}
describe 'Section4' {
it 'blah4' {
$true | should be $true
}
}
有人对如何解决这个问题有什么想法吗?使用 [System.Management.Automation.PSParser]
是正确的方法还是有更好的方法?
谢谢