Open scottbilas opened 2 years ago
I don't remember writing that function, but it sounds like function name conflict maybe.
This is caused by an alias in the module that hijacks an internal Pester-function.
Try importing the module without aliases (or specify the one you need except 'any' with -Alias 'name','of','aliases'
)
BeforeAll {
Import-Module ListFunctions -Function *
}
Describe 'Demo' {
It 'Shows the issue' {
New-HashSet
}
}
Time to rename all non-public functions to Verb-PesterNoun
and make our so much more non-standard again?
Or register them in SafeCommands?
Yeah that is an option too.
Yeah that is an option too.
Any preference?
We could probably limit it to some or all of these single word functions at first. Less risk of someone adding aliases for conflicting verb-noun.
function any ($InputObject) { # Mandatory
function combineNonNull ($Array) {
function defined { # Mandatory
function none ($InputObject) { # Mandatory
function notDefined { # Mandatory
function or { # Mandatory
function sum ($InputObject, $PropertyName, $Zero) { # Mandatory
function tryAddValue {
function tryGetProperty {
function tryGetValue {
function tryRemoveKey ($Hashtable, $Key) {
function trySetProperty {
Updating all of those functions with a call via safeCommands will make the complicated code look even more complex. How about a naming convention instead? We could just suffix the name with underscore or underscore and some other char like any_-
? Intellisense keeps working and we have very small likelyhood of conflicts.
I agree. Suffix or "pesterAny" etc sounds good. We real only need to fix the ones above to if you want. Don't think Fold-Block
etc will be stolen by an alias, but.. you never know 😁
Ok let me suffix them with "_"
General summary of the issue
Pester fails with a quite deep call stack if I have a test that uses
New-HashSet
from the ListFunctions package (Gallery; GitHub).Describe your environment
Pester version : 5.3.1 C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1 PowerShell version : 7.1.3 OS version : Microsoft Windows NT 10.0.22000.0
(I also tried on the posh classic, same issue)
Pester version : 5.3.1 C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1 PowerShell version : 5.1.22000.282 OS version : Microsoft Windows NT 10.0.22000.0
Steps to reproduce
Install-Module ListFunctions
(requires PSGallery as a PSRepository)Invoke-Pester test.ps1
Expected Behavior
Should not throw an exception. (If I run New-HashSet on its own, there's no problem.)
The code to
New-HashSet
is at New-HashSet.ps1. Nothing in there seems particularly weird to me, but it is apparently confusing Pester.Current Behavior
I get a call stack like this: