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

Inconsistent use of BOM in UTF8 files #1747

Closed
fflaten opened this issue Oct 30, 2020 · 3 comments · Fixed by #1950
Closed

Inconsistent use of BOM in UTF8 files #1747

fflaten opened this issue Oct 30, 2020 · 3 comments · Fixed by #1950

Comments

@fflaten
Copy link
Collaborator

fflaten commented Oct 30, 2020

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
Copy link
Member

nohwnd commented Oct 30, 2020

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
Copy link
Collaborator Author

fflaten commented Nov 1, 2020

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
Copy link
Member

nohwnd commented May 17, 2021

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

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 a pull request may close this issue.

2 participants