Skip to content

Pester throws if a test calls New-HashSet from ListFunctions package #2113

Open
@scottbilas

Description

@scottbilas

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

  1. Install-Module ListFunctions (requires PSGallery as a PSRepository)
  2. Copy this script into test.ps1
#Requires -Modules ListFunctions
Describe 'Demo' {
    It 'Shows the issue' { New-HashSet }
}
  1. 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:

 invoke-pester C:\temp\test.ps1

Starting discovery in 1 files.
Discovery found 1 tests in 1.14s.
Running tests.
System.Management.Automation.ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'Condition'. Cannot convert the "System.Collections.Generic.List`1[Pester.Block]" value of type "System.Collections.Generic.List`1[[Pester.Block, Pester, Version=5.3.1.0, Culture=neutral, PublicKeyToken=null]]" to type "System.Management.Automation.ScriptBlock".
 ---> System.Management.Automation.ArgumentTransformationMetadataException: Cannot convert the "System.Collections.Generic.List`1[Pester.Block]" value of type "System.Collections.Generic.List`1[[Pester.Block, Pester, Version=5.3.1.0, Culture=neutral, PublicKeyToken=null]]" to type "System.Management.Automation.ScriptBlock".
 ---> System.Management.Automation.PSInvalidCastException: Cannot convert the "System.Collections.Generic.List`1[Pester.Block]" value of type "System.Collections.Generic.List`1[[Pester.Block, Pester, Version=5.3.1.0, Culture=neutral, PublicKeyToken=null]]" to type "System.Management.Automation.ScriptBlock".
   at System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type resultType)
   at System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
   at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)                                                                                                at System.Management.Automation.ArgumentTypeConverterAttribute.Transform(EngineIntrinsics engineIntrinsics, Object inputData, Boolean bindingParameters, Boolean bindingScriptCmdlet)                                                                                             --- End of inner exception stack trace ---
   at System.Management.Automation.ArgumentTypeConverterAttribute.Transform(EngineIntrinsics engineIntrinsics, Object inputData, Boolean bindingParameters, Boolean bindingScriptCmdlet)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
at none, C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 234
at PostProcess-ExecutedBlock<Process>, C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2713
at Run-Test, C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 1671
at Invoke-Test, C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 2465
at Invoke-Pester<End>, C:\Users\scott\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 5225
at <ScriptBlock>, <No file>: line 1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions