Skip to content

Added tests for hashtabletoPSCustomObjectConversion, OutErrorVairable… - #2160

Merged
sergei (vors) merged 14 commits into
PowerShell:masterfrom
bingbing8:Add-Tests-to-Language-Part-4
Sep 13, 2016
Merged

sergei (vors) merged 14 commits into
PowerShell:masterfrom
bingbing8:Add-Tests-to-Language-Part-4

Conversation

@bingbing8

Copy link
Copy Markdown
Contributor

Added tests for hashtabletoPSCustomObjectConversion, OutErrorVairable. Please review.

@msftclas

Hi Yanbing (@bingbing8), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Yanbing Wang). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@msftclas

Hi Yanbing (@bingbing8), I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Yanbing Wang). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@JamesWTruher

James Truher (JamesWTruher) commented Sep 2, 2016 •

Copy link
Copy Markdown
Collaborator

��D�e�s�c�r�i�b�e� �"�T�e�s�t�s� �f�o�r� �h�a�s�h�t�a�b�l�e� �t�o� �P�S�C�u�s�t�o�m�O�b�j�e�c�t� �c�o�n�v�e�r�s�i�o�n�"� �-�T�a�g�s� �"�C�I�"� �{�

this file looks to be the wrong encoding - can you be sure that the BOM is not present and that the file is UTF8 (or ascii) - it's really hard to read


Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:1 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

@JamesWTruher

Copy link
Copy Markdown
Collaborator

� � � � � � � � �I�t� �'�$�a� �t�y�p�e�'� �{� �$�a� �-�i�s� �[�S�y�s�t�e�m�.�M�a�n�a�g�e�m�e�n�t�.�A�u�t�o�m�a�t�i�o�n�.�P�S�O�b�j�e�c�t�]� �|� �S�h�o�u�l�d� �B�e� �$�t�r�u�e� �}� � � � � � � � �

this can be

it '$a type' { $a | should BeOfType "System.Management.automation.psobject" }

Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:15 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

@JamesWTruher

Copy link
Copy Markdown
Collaborator

�

I don't think we really need a new type here - wouldn't this be ok?

describe "good description here" {
    it "good test name here" {
        try {
            new-object System.Management.Automation.MetadataException -property @{ Source = "foobar"; aa = 1 }
            throw "OK"
        }
        catch {
            $_.Exception | Should BeOfType "InvalidOperationException"
            $_.Exception.Message | Should Match "aa"
            $_.FullyQualifiedErrorId | should be "InvalidOperationException,Microsoft.PowerShell.Commands.NewObjectCommand"
        }
    }
}

Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:66 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

}

Context 'Updating OutVariable Case 1: pipe string' {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't going to do anything because they're not in it blocks, also these really look like they could all be done via test cases


$testcases = @{ Title = "Updating OutVariable Case 1: pipe string"; command = "get-foo1"; OutVariable = "a"; Expected = "foo" },
        @{ Title = 'Updating OutVariable Case 2: $pscmdlet.writeobject'; command = "get-foo1"; OutVariable = "a"; Expected = "foo" }

Describe Tests {
    BeforeAll {

        function get-foo1
        {
            [CmdletBinding()]
            param()

            "foo"
        }

        function get-foo2
        {
            [CmdletBinding()]
            param()

            $pscmdlet.writeobject("foo")
        }

        function get-bar 
        {
            [CmdletBinding()]
            param()

            "bar"
            get-foo1 -outVariable global:a
        }

    }
    It "<Title>" -TestCases $testcases {
        param ( $command, $arguments, $Expected, $OutVariable )
        & $command -OutVariable $OutVariable > $null
        Get-Variable -ValueOnly $outVariable | should be $Expected
    }

}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


In reply to: 77278055 [](ancestors = 77278055)

@bingbing8

Copy link
Copy Markdown
Contributor Author

��D�e�s�c�r�i�b�e� �"�T�e�s�t�s� �f�o�r� �h�a�s�h�t�a�b�l�e� �t�o� �P�S�C�u�s�t�o�m�O�b�j�e�c�t� �c�o�n�v�e�r�s�i�o�n�"� �-�T�a�g�s� �"�C�I�"� �{�

fixed


In reply to: 244248919 [](ancestors = 244248919)


Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:1 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

@bingbing8

Copy link
Copy Markdown
Contributor Author

� � � � � � � � �I�t� �'�$�a� �t�y�p�e�'� �{� �$�a� �-�i�s� �[�S�y�s�t�e�m�.�M�a�n�a�g�e�m�e�n�t�.�A�u�t�o�m�a�t�i�o�n�.�P�S�O�b�j�e�c�t�]� �|� �S�h�o�u�l�d� �B�e� �$�t�r�u�e� �}� � � � � � � � �

fixed


In reply to: 244249354 [](ancestors = 244249354)


Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:15 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

@bingbing8

Copy link
Copy Markdown
Contributor Author

�

fixed


In reply to: 244251597 [](ancestors = 244251597)


Refers to: test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1:66 in 31f22c6. [](commit_id = 31f22c6, deletion_comment = False)

@bingbing8

Copy link
Copy Markdown
Contributor Author

James Truher (@JamesWTruher) I updated the tests based on your feedback. some of the replies don't show in browser. please check out. Thanks!

@vors

Copy link
Copy Markdown
Collaborator

Assigning the PR to James Truher (@JamesWTruher)


It '$a should not be $null' { $script:a | Should Not Be $null }
It '$a type' { $script:a | should BeOfType "System.Management.automation.psobject" }
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that this is much too complicated, can't it just be:

It 'New-Object cmdlet should accept empty hashtable or $null as Property argument' {
      $a = new-object psobject -property
      $a | should not BeNullOrEmpty
      $a | should BeOfType "System.Management.Automation.PSObject"
}

I don't see the point of the extra it statements, if the first line throws the test will fail

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


In reply to: 78253881 [](ancestors = 78253881)

@JamesWTruher

James Truher (JamesWTruher) commented Sep 9, 2016 •

Copy link
Copy Markdown
Collaborator

:shipit:

@bingbing8

Copy link
Copy Markdown
Contributor Author

James Truher (@JamesWTruher) Thanks for your feedback. I addressed all of them. Please check.

@JamesWTruher

Copy link
Copy Markdown
Collaborator

:shipit:

Comment thread test/csharp/csharp.nuget.props Outdated
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove this file from the PR.
In #2182 Douglas Thrift (@douglaswth) added it to ,gitignore.

Particularly because this file contains env-specific line

<NuGetPackageRoot>C:\git\part4\Packages</NuGetPackageRoot>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sergei (@sergei) Vorobev good catch. I removed the file. Thanks!


In reply to: 78430315 [](ancestors = 78430315)

@vors

Copy link
Copy Markdown
Collaborator

🕐

@vors
sergei (vors) merged commit fd4552b into PowerShell:master Sep 13, 2016
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
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 this pull request may close these issues.

6 participants