Pester icon indicating copy to clipboard operation
Pester copied to clipboard

New-PesterConfiguration throw an exception when the 'Run.Path' content $null (Object reference not set to an instance of an object)

Open LaurentDardenne opened this issue 3 years ago • 0 comments

General summary of the issue

New-PesterConfiguration throw an exception when the 'Run.Path' content $null

Describe your environment

Pester version : 5.2.2 C:\Program Files\WindowsPowerShell\Modules\Pester\5.2.2\Pester.psm1 PowerShell version : 5.1.19041.1023 OS version : Microsoft Windows NT 10.0.19043.0

Steps to reproduce

$PesterOptions=@{
    Run = @{
       Path = $NotExist # typo $PscriptRoot 
    }

    Output = @{
       Verbosity = 'Detailed'
    }
}

$Configuration=New-PesterConfiguration -Hashtable $PesterOptions

Expected Behavior

An error message like "Variable XYZ not exist" or 'The key 'Run.Path' do not be $null' ?

Current Behavior

Exception: Cannot convert value "System.Collections.Hashtable" to type "PesterConfiguration". Error: "Object reference not set to an instance of an object."

Maybe check the $null value and an empty string?

$PesterOptions=@{
    Run = @{
       Path = "$NotExist"
    }

    Output = @{
       Verbosity = 'Detailed'
    }
}

$Configuration=New-PesterConfiguration -Hashtable $PesterOptions
[string]::Empty -eq $Configuration.run.Path.Value
#true

LaurentDardenne avatar Jul 11 '21 15:07 LaurentDardenne