Skip to content

Tests (especially Get-FileHash) depend on machine-specific details #6413

Description

@rjmholt

There are a number of tests in the PowerShell test suite that depend on a file asset in a way that depends on the specific bytes of the file. These tests fail on platforms that somehow differ from the expected encodings. For example, my Git configuration converts LF line endings to CRLF locally on Windows when checking out (and converts back on check-in), which is the default Git configuration on Windows, but because of this and Windows introducing a BOM, my file hashes come out differently.

I've made a small list of the tests I see failing on my machine because of this:

  • Get-FileHash tests depend on file encoding -- CRLF/BOM breaks it
  • A Get-Process test depends on having a process with the name "notepad"
  • Write-Error ErrorRecord tests seem to be affected (get 11 and not the expected 4)
  • Get-PSSessionConfiguration assumes there is only a single PSSessionConfiguration on the machine
  • NativeStreams testing using the $longtext like in the Write-Error tests have a similar outcome

There might be a couple more tests like this too (I will update if I find any).

For the string/encoding-dependent tests, my suggestion is to use byte streams directly instead.

Steps to reproduce

cd $powershellBuildDir
Import-Module ./build.psm1
cd ./test/powershell/Modules/Microsoft.PowerShell.Utility
Start-PSPester Get-FileHash.Tests.ps1

Expected behavior

Get-FileHash tests pass.

Actual behavior

Hashes all come out differently

Get-FileHash tests all failing on Win10

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1-261-g71cb49a99d00ae4257e63f6564fd122325b64a48
OS                             Microsoft Windows 10.0.16299 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. rjmholt commented on Mar 16, 2018

    @rjmholt
    CollaboratorAuthor

    This may be the cause of #5960 and #6369.

  2. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Maintainers-Buildspecific to affecting the build

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions