X Tutup
The Wayback Machine - https://web.archive.org/web/20201124210507/https://github.com/pester/pester/issues/1163
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

Improve Get-ShouldOperator #1163

Open
nohwnd opened this issue Dec 14, 2018 · 12 comments
Open

Improve Get-ShouldOperator #1163

nohwnd opened this issue Dec 14, 2018 · 12 comments

Comments

@nohwnd
Copy link
Member

@nohwnd nohwnd commented Dec 14, 2018

Get-ShouldOperator shows:

NAME
    Should-Be

on the top, and does not show aliases. It would be nice to replace the name section with this:

NAME
    Be

ALIASES
    EQ
    EQUAL
    BeEq

(the two last aliases don't actually exist on Be)

Related to #878

@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Dec 14, 2018

still available? if so, i'll be happy to check this one

@nohwnd
Copy link
Member Author

@nohwnd nohwnd commented Dec 14, 2018

@Stephanevg yup. Looks like you are the first one.

@omiossec
Copy link

@omiossec omiossec commented Dec 14, 2018

I will be happy too

@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Dec 15, 2018

@nohwnd I think you meant: Get-ShouldOperator -Name be Shows:

NAME
    Be

ALIASES
    EQ
    EQUAL
    BeEq

right?

Cause I have this when I use Get-ShouldOperator (Without any parameters):


Get-ShouldOperator

Name                      Alias
----                      -----
Be                        EQ
BeExactly                 CEQ
BeGreaterThan             GT
...
@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Dec 15, 2018

I am sorry to ask, but either I didn't fully understand what problem we need to fix here, or I am missing something.

I originally thought that this issue would be as easy as editing the 'comment Based Help' of the BE operator, but It seems there is a bit more to it.

Perhaps you can give me a hint of where I should look? ;)

Let me explain my rationale:

for example, any other 'ShouldOperator' return the same output.
Where .NAME shows the $InternalName (which is also often the name of the file where the function resides).

Be exactly

[DBG]:   Get-ShouldOperator -Name BeExactly

NAME
    Should-BeExactly

SYNOPSIS
    Compares one object with another for equality and throws if the
    two objects are not the same. This comparison is case sensitive.


    -------------------------- EXAMPLE 1 --------------------------

    PS C:\>$actual = "Actual value"

    PS C:\>$actual | Should -Be "Actual value"

    This test will pass. The two strings are identical.




    -------------------------- EXAMPLE 2 --------------------------

    PS C:\>$actual = "Actual value"

    PS C:\>$actual | Should -Be "actual value"

    This test will fail, as the two strings do not match case sensitivity.

This actually highlights that the issue is not an isoolated issue, as in opposition of what I thought.

Process understanding:

It seems to me, that I missing a (obvious) part

The assertion operator nd it Alias is declared in be.ps1 with the following code:

Add-AssertionOperator -Name               Be `
                      -InternalName       Should-Be `
                      -Test               ${function:Should-Be} `
                      -Alias              'EQ' `
                      -SupportsArrayInput

and later is called via the Get-ShouldOperator function located in Get-ShouldOperator.ps1 using this part:

$operator = $AssertionOperators.Values | Where-Object { $Name -eq $_.Name -or $_.Alias -contains $Name }
$help = Get-Help $operator.InternalName -Examples -ErrorAction SilentlyContinue

Unfortunatley, it is not possible to add simply a '.ALIASES' part to a comment based help section. It seems like there is a limited list, that we can used for Internal comment based help keywords See here for more details.
It seems like, if the help content is located in an external file, it would be possible to create that .ALIASES section, but it seems like we are not using it in this module.

With all that said, I can think of two options, which both I don't like:

  1. Grab that $Help object, and return build and send a custom object similarly on how it is done when no '-Name' parameter is used.
  2. dig more into the external help possibility.

Or perhaps I missed something? in that case, please hint me in the right direction :)

Cheers

@nohwnd
Copy link
Member Author

@nohwnd nohwnd commented Dec 15, 2018

@Stephanevg

  1. Yes I meant the call with -Name parameter.

  2. Sorry, I thought we are returning string from it not the help object... 😔 I see that you can fool the template by setting $o.details.name. But the aliases don't work, there is some type magic going on, and when I assing $o.aliases = $foreach.aliases then the type of object on $o and $foreach is different. Some adaption and projection is going on there. So you could just set the name for now. I will ask around if anyone knows how to fool the aliases as well. (Alternatively we could return string and add -Raw switch that would return the help object, but I don't want to add that yet, because if we can change the help object successfully then no switch will be needed.)

@nohwnd
Copy link
Member Author

@nohwnd nohwnd commented Jan 5, 2019

@Stephanevg Still interested in implementing this?

@nohwnd nohwnd added the taken label Jan 5, 2019
@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Jan 8, 2019

Hi @nohwnd
I still am, but this week is going to be busy one for me.
Also, I think I bumped into an issue, as 'simply' setting the name, actually didn't worked (If i remember correctly) - and that's why there is no PR yet ;)

I'll look into it later this week if ok. If this is urgent, somebody else could potentially do it then.

@nohwnd
Copy link
Member Author

@nohwnd nohwnd commented Jan 8, 2019

Not urgent :)

@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Mar 24, 2019

Hey @nohwnd sorry It took me ages to come back to this one.

I just looked at it again. Launching a short test, I see this:

image

I asume that this is now fixed, right?

@nohwnd
Copy link
Member Author

@nohwnd nohwnd commented Mar 24, 2019

I don’t think it is. The issue is about the detail of the operator, not the overview (in your screenshot).

@Stephanevg
Copy link
Contributor

@Stephanevg Stephanevg commented Mar 24, 2019

Ok, I have got something working here, but I am not really a big fan of the output, and that is something I think we ned to discuss.

I did a PR (#1272) so we can maybe discuss directly in the code there.
Otherwise, here is fine too :)

@renehernandez renehernandez added this to the Better Should milestone May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.
X Tutup