Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 3d6c7ef

Browse files
author
Asbjørn Mangabat Bach Merling
committed
Get name property regardsless of it is named or positional
1 parent 9cebf9a commit 3d6c7ef

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Modules/OperationValidation/OperationValidation.psm1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,19 @@ function Get-TestFromScript
8989
}, $true) |
9090
ForEach-Object {
9191
# This is the name of the 'describe' block
92-
$describeName = ($_.CommandElements | Where-Object { $_.StaticType.name -eq 'string' })[1].SafeGetValue()
93-
92+
for ($x = 0; $x -lt $_.CommandElements.Count; $x++)
93+
{
94+
#Name parameter is named
95+
if ($_.CommandElements[$x] -is [System.Management.Automation.Language.CommandParameterAst] -and $_.CommandElements[$x].ParameterName -eq 'Name')
96+
{
97+
$describeName = $_.CommandElements[$x + 1].value
98+
}
99+
#if we have a string without a parameter name, return first hit. Name parameter is at position 0.
100+
ElseIf (($_.CommandElements[$x] -is [System.Management.Automation.Language.StringConstantExpressionAst]) -and ($_.CommandElements[$x - 1] -is [System.Management.Automation.Language.StringConstantExpressionAst]))
101+
{
102+
$describeName = $_.CommandElements[$x].value
103+
}
104+
}
94105
$item = [PSCustomObject][ordered]@{
95106
Name = $describeName
96107
Tags = @()

0 commit comments

Comments
 (0)