pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

Inconsistent use of BOM in UTF8 files #1747

Closed fflaten closed 3 years ago

fflaten commented 3 years ago

Question

Pester uses BOM inconsistently in files with UTF8. Only some files, like Mock.ps1, Mock.Tests.ps1 etc. use BOM, while the rest use UTF8 without BOM.

CI failed for PS v3/v4 in #1745 after BOM was removed in Mock.ps1 by mistake. It caused mock-test Command with single quote in name should be mockable to fail due to use of smart-quotes AFAIK.

As BOM seems to it's required for older PowerShell-versions on Windows, should all files have BOM? Or is the use of smart-quotes in the test itself the issue? Copy-paste from mail/word-document?

Environment data

N/A. Pester 5.1.0-beta3+

nohwnd commented 3 years ago

Or is the use of smart-quotes in the test itself the issue?

This. It's probably copy-paste error as you say. I think the test is (was?) necessary because in soma places we emit the mock template as text, to define the hook functions, and so misplacing quotes there would break the template.

The test also works because PowerShell is clever about quotes and considers any valid UTF quote to be quote, such as the smart quotes used here.

So imho you can change them to just normal apostrophes, and the test should still be valid.

fflaten commented 3 years ago

With BOM the test works (and tests mocking with unicode at the same time), so not sure if it's worth changing only the Mock* files. Looks like these files are currently using UTF8 with BOM

src\Pester.psm1 src\csharp\Pester.sln src\csharp\Pester\Block.cs src\csharp\Pester\Constants.cs src\csharp\Pester\Container.cs src\csharp\Pester\ContainerInfo.cs src\csharp\Pester\InvocationResult.cs src\csharp\Pester\OutputTypes.cs src\csharp\Pester\Pester.csproj src\csharp\Pester\Run.cs src\csharp\Pester\Test.cs src\csharp\Pester\ToStringConverter.cs src\en-US\about_BeforeEach_AfterEach.help.txt src\en-US\about_Mocking.help.txt src\en-US\about_Pester.help.txt src\en-US\about_Should.help.txt src\en-US\about_TestDrive.help.txt src\functions\Mock.ps1 src\functions\assertions\Should.ps1 tst\Pester.Tests.ps1 tst\axiom\Verify-Equal.ps1 tst\axiom\Verify-NotSame.ps1 tst\axiom\Verify-Type.ps1 tst\functions\Mock.Tests.ps1 tst\functions\Output.Tests.ps1 tst\functions\TestsRunningInCleanRunspace.Tests.ps1 tst\functions\assertions\FileContentMatch.Tests.ps1 tst\functions\assertions\FileContentMatchExactly.Tests.ps1

Should we try to have a standard encoding? PowerShell 6+, vscode and Win10 has gone UTF8 without BOM as default. At the same time the PowerShell/vscode docs says "If you work across platforms, you should prefer UTF-8 with BOM." and PSSA has a PSSA rule that recommends BOM when non-ascii characters are used. So MS recommendations are a bit confusing you might say.

If we'd like to have use a standard I can make a draft PR with removed BOM and see how the CI behaves. If so, what about help-files and C# (mostly using BOM now)? Will Visual Studio (full version) work fine without BOM?

nohwnd commented 3 years ago

Yeah let's do this now and use with BOM as suggested.