Skip to content

Commit

Permalink
Merge branch 'hotfix/0.12.1'
Browse files Browse the repository at this point in the history
* hotfix/0.12.1:
  (chocolatey#2539) Update tests to test line endings
  (chocolatey#2539) Add tests for PowerShell file encoding
  (chocolatey#2539) Update PowerShell files to include BOM
  (chocolatey#2546) Fix template command help reference
  (version) v0.12.1-beta
  • Loading branch information
gep13 committed Jan 25, 2022
2 parents 2962306 + 6f3b2fb commit 67bece3
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .uppercut
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<property name="version.use_semanticversioning" value="true" overwrite="false" />
<property name="version.major" value="0" overwrite="false" />
<property name="version.minor" value="12" overwrite="false" />
<property name="version.patch" value="0" overwrite="false" />
<property name="version.patch" value="1" overwrite="false" />
<property name="version.fix" value="0" overwrite="false" />
<property name="version.nuget.prerelease" value="" overwrite="false" />
<property name="version.use.build_date" value="false" overwrite="false" />
<property name="version.nuget.prerelease" value="beta" overwrite="false" />
<property name="version.use.build_date" value="true" overwrite="false" />
<property name="assembly.description" value="${project.name} is a product of ${company.name} - All Rights Reserved." overwrite="false" />
<property name="assembly.copyright" value="Copyright © 2017 - 2021 ${company.name} Copyright © 2011 - 2017, RealDimensions Software, LLC - All Rights Reserved." overwrite="false" />
<property name="sign.project_with_key" value="true" overwrite="false" />
Expand Down
2 changes: 1 addition & 1 deletion GenerateDocs.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2017 Chocolatey Software, Inc
# Copyright © 2017 Chocolatey Software, Inc
# Copyright © 2011 - 2017 RealDimensions Software, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
75 changes: 75 additions & 0 deletions ScriptFormat.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#Requires -Module @{ ModuleName = 'pester'; ModuleVersion = '5.3.1' }

Describe "Verifying integrity of module files" {
BeforeDiscovery {
$FilesToVerify = Get-ChildItem -Include '*.psm1', '*.ps1' -Recurse
$DirectoriesToExclude = @(
# These directories contain dependencies we bring in, we don't control their file formats
'lib'
'packages'
'.nuget'
# These directories contain output of builds, if there's anything in these with "bad" formatting it's likely an old build, or not relevant
'bin'
'obj'
# This directory currently contains scripts to assist in creating the docker container. It is not formatted and should not require signing (at this time)
'docker'
# These directories contain uppercut configurations. Here be dragons
'.build'
'.build.custom'
# GitHub/git configs. No PowerShell here?
'.github'
'.git'
)
$Slash = [System.IO.Path]::DirectorySeparatorChar
$FilesBeingTested = $FilesToVerify | Where-Object { $null -ne $env:CHOCO_TEST_ALL -or $_.FullName -notmatch "\$Slash($($DirectoriesToExclude -join '|'))\$Slash" }
}

BeforeAll {
function Get-FileEncoding {
<#
.SYNOPSIS
Tests a file for encoding.
.DESCRIPTION
Tests a file for encoding.
.PARAMETER Path
The file to test
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[Alias('FullName')]
[string]
$Path
)

if ($PSVersionTable.PSVersion.Major -lt 6) {
[byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
}
else {
[byte[]]$byte = Get-Content -AsByteStream -ReadCount 4 -TotalCount 4 -Path $Path
}

if ($byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf) { 'UTF8 BOM' }
elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff) { 'Unicode' }
elseif ($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff) { 'UTF32' }
elseif ($byte[0] -eq 0x2b -and $byte[1] -eq 0x2f -and $byte[2] -eq 0x76) { 'UTF7' }
else { 'Unknown' }
}
}

Context "Validating PowerShell file <_.FullName>" -Foreach $FilesBeingTested {
BeforeAll {
$FileUnderTest = $_
}

It "Should have Byte Order Mark" {
Get-FileEncoding -Path $FileUnderTest.FullName | Should -Be 'UTF8 BOM'
}

It "Should have 'CRLF' Line Endings" {
(Get-Content $FileUnderTest -Raw) -match '([^\r]\n|\r[^\n])' | Should -BeFalse
}
}
}
2 changes: 1 addition & 1 deletion setup.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### install chocolatey ###
### install chocolatey ###
if(-not $env:ChocolateyInstall -or -not (Test-Path "$env:ChocolateyInstall")){
iex ((new-object net.webclient).DownloadString("https://community.chocolatey.org/install.ps1"))
}
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey.resources/helpers/chocolateyInstaller.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2017 - 2021 Chocolatey Software, Inc.
# Copyright © 2017 - 2021 Chocolatey Software, Inc.
# Copyright © 2015 - 2017 RealDimensions Software, LLC
# Copyright © 2011 - 2015 RealDimensions Software, LLC & original authors/contributors from https://github.com/chocolatey/chocolatey
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ .template packages are displayed.

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
"chocolatey".Log().Info(@"
choco pin [list]|info [<options/switches>]");
choco template [list]|info [<options/switches>]");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples");
"chocolatey".Log().Info(@"
Expand Down

0 comments on commit 67bece3

Please sign in to comment.