Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSFTest #145

Open
FriedrichWeinmann opened this issue Apr 6, 2021 · 0 comments
Open

PSFTest #145

FriedrichWeinmann opened this issue Apr 6, 2021 · 0 comments

Comments

@FriedrichWeinmann
Copy link
Member

Add tests for validate script & validate pattern attributes

E.g.:

function Test-ValidatePattern {
    [CmdletBinding()]
    param (
        [string]
        $Path
    )

    $ast = [System.Management.Automation.Language.Parser]::ParseInput((Get-Content $Path -Raw), [ref]$null, [ref]$null)
    $attributes = $ast.FindAll( {
            if ($args[0] -isnot [System.Management.Automation.Language.AttributeAst]) { return }
            if ('ValidatePattern' -ne $args[0].TypeName.Name) { return }
            $true
        }, $true)
    
    foreach ($attribute in $attributes) {
        Write-PSFMessage -Message "Processing {0}" -StringValues $attribute -Target $attribute
        try { $null = "" -match $attribute.PositionalArguments[0].Value }
        catch {
            [PSCustomObject]@{
                Text = $attribute.Extent.ToString()
                Item = $attribute
                Line = $attribute.Extent.StartLineNumber
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant