WTF Powershell ?

188 views
Skip to first unread message

Frank Behrens

unread,
Apr 26, 2014, 4:59:29 PM4/26/14
to pes...@googlegroups.com
Thanks for Pester,

I am really thankfull that you created and shared it.

Having worked a lot in ruby I have to share my opinion about testing frameworks:
They should be simple and inviting to use the language.

So I don't need the sophisticated rspec matchers,
I am very confident with what minitest provides.

So please don't overdo it.

Apropos the language:
Why is this ?
 
@{a=1}  | Should Be @{a=1}
 [-] Hashtables should compare 10ms
   Expected: {System.Collections.Hashtable}, But was {System.Collections.Hashtable}
   at line: 3 in C:\local\psdb\learn\pester.Tests.ps1

and this ?

 { 1/0 } | Should Throw
Es wurde versucht, durch 0 (null) zu teilen.
Bei C:\local\psdb\learn\pester.Tests.ps1:19 Zeichen:9
+     { 1/ <<<< 0 } | Should Throw
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

Yeah I am from germany
Obviously the exception could not be catched.

Frank 

Frank Behrens

unread,
Apr 26, 2014, 5:11:26 PM4/26/14
to pes...@googlegroups.com
PS C:\local\psdb\learn> 1 -eq 1
True

PS C:\local\psdb\learn> @{a=1} -eq @{a=1}
False

PS C:\local\psdb\learn> @(1) -eq @(1)

PS C:\local\psdb\learn> @(1) -eq 1
1

PS C:\local\psdb\learn> 1 -eq @(1)
False

Powershell WTF?

Scott Muc

unread,
Apr 26, 2014, 8:47:32 PM4/26/14
to Frank Behrens, pes...@googlegroups.com
Danke for the feedback Frank!

You know, you've articulated something that's been in the back of my mind. I feel that I sort of went down the route of too much complexity around the matchers. I also like minitest's simple matchers.

The above examples that you brought forward are definitely issues. My guess is Pester is only handling checked exceptions, but I'm not quite sure.

Again, thank you for the feedback.

Scott

PS I'll be in Germany (Hamburg, Berlin, Hockenheim) in July!


--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jakub Jareš

unread,
Jun 8, 2014, 2:39:43 PM6/8/14
to pes...@googlegroups.com
Hello, the Should Throw works ok for me. 

Although the results might seem weird, the different comparisons work as they should: 
    When the input to an operator is a scalar value, comparison operators
    return a Boolean value. When the input is a collection of values, the 
    comparison operators return any matching values. If there are no matches
    in a collection, comparison operators do not return anything. 

    The exceptions are the containment operators (-Contains, -NotContains),
    the In operators (-In, -NotIn), and the type operators (-Is, -IsNot),
    which always return a Boolean value.

1 -eq 1 returns true because you provide scalar values.

The hash tables are not equal because they are two different objects. When comparing objects (with exception for some types, for example those implementing IComparable) their references are compared not their values.

The first array example does not return anything because the first array is expanded (see above) and the items contained in it are compared with the value on the right side. There you provide new array object so the reference is different and no match is found. To get a match you'd have to wrap the array in array and then compare it with the same object: 
$item = @(1)
$array = @($null)
$areay[0] = $item 
$array -eq $item # returns the object in $item

The second array example: The values in array are expanded and 1 is equal to the 1 so 1 is output. 

1 -eq @(1) The type of the left operand determines the type in which the operands are compared. 1 is integer so cast to integer is made. [int]@(1) silently fails so the result is false. try '1' -eq @(1), in that case cast to string is made which returns '1', the values are equal and the result is true. 
hope this made it clearer. 

Frank Behrens

unread,
Jun 13, 2014, 8:38:43 AM6/13/14
to pes...@googlegroups.com
Hello Jakub,

thanks for the explanation,
it all makes (some) sense if you understand how it works.

I hope I have soon some time to dig into the pester code.

have a nice day
Frank

Jakub Jareš

unread,
Jun 27, 2014, 2:22:21 PM6/27/14
to pes...@googlegroups.com
I hope you do too. We always welcome patches and insight of others :)

Dne pátek, 13. června 2014 14:38:43 UTC+2 Frank Behrens napsal(a):
Reply all
Reply to author
Forward
0 new messages