Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should -HaveParameter <parameter name> -HasArgumentCompleter does not cover all scenarios #1890

Closed
dtewinkel opened this issue Apr 5, 2021 · 8 comments · Fixed by #1979
Closed

Comments

@dtewinkel
Copy link
Contributor

General summary of the issue

The assertion Should -HaveParameter <parameter name> -HasArgumentCompleter does not work for argument completers that are registered with Register-ArgumentCompleter.

Describe your environment

Pester version : 5.1.1 C:\Users\User\Documents\PowerShell\Modules\Pester\5.1.1\Pester.psm1
PowerShell version : 7.1.3
OS version : Microsoft Windows NT 10.0.19042.0

Steps to reproduce

Describe "Reproduce" {
	BeforeAll	{
		function Reproduce()
		{
			param(
				[Parameter()]
#				[ArgumentCompleter({param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)})]
				[String] $Foo
			)
		}

		Register-ArgumentCompleter -CommandName Reproduce -ParameterName Foo -ScriptBlock {
			param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
		}

	}

	It "should pass" {
		Get-Command Reproduce | Should -HaveParameter Foo -HasArgumentCompleter
	}
}

Expected Behavior

The test should Pass. The Argument has an argument completer.

Current Behavior

The test fails with error:

[-] Reproduce.should pass 16ms (14ms|2ms)
 Expected command Reproduce to have a parameter Foo, has ArgumentCompletion, but has no ArgumentCompletion.
 at Get-Command Reproduce | Should -HaveParameter Foo -HasArgumentCompleter, Reproduce.Tests.ps1:19
 at <ScriptBlock>, Reproduce.Tests.ps1:19

Test will succeed with using the (commented out) ArgumentCompleter attribute.

@nohwnd
Copy link
Member

nohwnd commented Apr 7, 2021

@lipkau I think you were adding this? Any ideas?

@dtewinkel
Copy link
Contributor Author

I guess this gist on github may help in solving this issue: Get-ArgumentCompleter.ps1.
It provides a way to find the registered argument completers.

@nohwnd
Copy link
Member

nohwnd commented Jun 5, 2021

@dtewinkel @indented-automation @lipkau Is anyone of you interested in making a PR for this? 🙂

@indented-automation
Copy link
Contributor

I don't mind taking a look unless someone else gets there first :)

@dtewinkel
Copy link
Contributor Author

Thank you @indented-automation. I am looking forward to the next release.

@nohwnd
Copy link
Member

nohwnd commented Jun 24, 2021

@dtewinkel there will be at least 2 pre releases till then. Please help us test it. I will try to make one this morning.

@dtewinkel
Copy link
Contributor Author

@nohwnd, Sure, no problem. I'll try to have a look at it and test it in my project a.s.a.p.

@dtewinkel
Copy link
Contributor Author

@nohwnd, @indented-automation, to me it is working as expected now :-). Both for succeeding the test if the argument completer is present and for failing the test if the argument completer is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants