Skip to content

fea: Assert-Contains to accept patterns #54

@rulasg

Description

@rulasg

Take the code sample from
DemoPsModuleTest/public/Tests-publish.ps1#Assert-ContainsPattern

function Assert-ContainsPattern{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [string] $Expected,
        [Parameter(Mandatory)] [string[]] $Presented,
        [Parameter()] [string] $Comment
    )

    $found = $false
    foreach($p in $Presented){
        if ($p -like $Expected) {
            $found = $true
            break
        }
    }

    Assert-IsTrue -Condition $found -Comment "Not found pattern [$Expected] in $Presented - $Comment "
}

function Assert-ContainsNotPattern{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [string] $Expected,
        [Parameter(Mandatory)] [string[]] $Presented,
        [Parameter()] [string] $Comment
    )

    $found = $false
    foreach($p in $Presented){
        if ($p -like $Expected) {
            $found = $true
            break
        }
    }

    Assert-IsFalse -Condition $found -Comment "Found pattern [$Expected] in $Presented - $Comment"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions