Skip to content

bug: Assert-AreEqualPath EndsWith '/' #84

@rulasg

Description

@rulasg

When runing Convert-Path powershell will not consolidate the last '/' if the Path has it, so it may be the same path but the Assert will fail.

Poposed code 
function Assert-AreEqualPath {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)] [object] $Expected,
        [Parameter(Mandatory)] [object] $Presented,
        [Parameter()] [string] $Comment

    )

    $ex = &{ if ($Expected  | Test-Path) { $Expected  | Convert-Path} else {$Expected} }
    $pr = &{ if ($Presented | Test-Path) { $Presented | Convert-Path} else {$Presented}}

    # trim last '/' if exists
    if($ex.EndsWith('/')){ $ex = $ex.Substring(0, $ex.Length - 1) }
    if($pr.EndsWith('/')){ $pr = $pr.Substring(0, $pr.Length - 1) }

    Assert-AreEqual -Expected $ex -Presented $pr -Comment ("Path not equal - " + $Comment)
}

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

    )

    $ex = &{ if ($Expected  | Test-Path) { $Expected  | Convert-Path} else {$Expected} }
    $pr = &{ if ($Presented | Test-Path) { $Presented | Convert-Path} else {$Presented}}

    # trim last '/' if exists
    if($ex.EndsWith('/')){ $ex = $ex.Substring(0, $ex.Length - 1) }
    if($pr.EndsWith('/')){ $pr = $pr.Substring(0, $pr.Length - 1) }

    Assert-AreNotEqual -Expected $ex -Presented $pr -Comment ("Path equal - " + $Comment)
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions