Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tests/Help.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BeforeDiscovery {
# the values it needs (BHPSModuleManifest, BHProjectName) — when running
# via ./build.ps1 this happens before psake; running tests in isolation
# bypasses that, so we do it here.
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
$invokePsakeParameters = @{
TaskList = 'Build'
Expand All @@ -62,10 +62,10 @@ BeforeDiscovery {
}

# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Parent $PSScriptRoot
$sourceManifest = Join-Path $projectRoot "$Env:BHProjectName/$Env:BHProjectName.psd1"
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path $projectRoot "Output/$Env:BHProjectName/$moduleVersion"
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
$moduleManifestFilename = $Env:BHProjectName + '.psd1'
Expand All @@ -77,18 +77,18 @@ BeforeDiscovery {
'Classes'
) | ForEach-Object {
$path = Join-Path -Path $Env:BHBuildOutput -ChildPath $_
if (Test-Path $path) {
if (Test-Path -Path $path) {
$global:CustomTypes += (Get-ChildItem -Path $path -Recurse -ErrorAction 'SilentlyContinue').BaseName
}
}

# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Get-Module -Name $Env:BHProjectName | Remove-Module -Force -ErrorAction 'Ignore'
Import-Module -Name $moduleManifestPath -Verbose:$false -ErrorAction 'Stop'

# Get module commands
$getCommandParameters = @{
Module = (Get-Module $Env:BHProjectName)
Module = (Get-Module -Name $Env:BHProjectName)
CommandType = [System.Management.Automation.CommandTypes[]]'Cmdlet, Function' # Not alias
}
if ($PSVersionTable.PSVersion.Major -lt 6) {
Expand All @@ -108,7 +108,7 @@ BeforeAll {
# the values it needs (BHPSModuleManifest, BHProjectName) — when running
# via ./build.ps1 this happens before psake; running tests in isolation
# bypasses that, so we do it here.
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
$invokePsakeParameters = @{
TaskList = 'Build'
Expand Down
20 changes: 10 additions & 10 deletions tests/Manifest.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BeforeDiscovery {
# the values it needs (BHPSModuleManifest, BHProjectName) — when running
# via ./build.ps1 this happens before psake; running tests in isolation
# bypasses that, so we do it here.
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
$invokePsakeParameters = @{
TaskList = 'Build'
Expand All @@ -74,10 +74,10 @@ BeforeDiscovery {
}

# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Parent $PSScriptRoot
$sourceManifest = Join-Path $projectRoot "$Env:BHProjectName/$Env:BHProjectName.psd1"
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path $projectRoot "Output/$Env:BHProjectName/$moduleVersion"
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
$moduleManifestFilename = $Env:BHProjectName + '.psd1'
Expand Down Expand Up @@ -108,7 +108,7 @@ BeforeAll {
# the values it needs (BHPSModuleManifest, BHProjectName) — when running
# via ./build.ps1 this happens before psake; running tests in isolation
# bypasses that, so we do it here.
Set-BuildEnvironment -Path (Split-Path -Parent $PSScriptRoot) -Force
Set-BuildEnvironment -Path (Split-Path -Path $PSScriptRoot -Parent) -Force
$buildFilePath = Join-Path -Path $PSScriptRoot -ChildPath '..\build.psake.ps1'
$invokePsakeParameters = @{
TaskList = 'Build'
Expand All @@ -118,10 +118,10 @@ BeforeAll {
}

# PowerShellBuild outputs to Output/<ModuleName>/<Version>/, override BHBuildOutput
$projectRoot = Split-Path -Parent $PSScriptRoot
$sourceManifest = Join-Path $projectRoot "$Env:BHProjectName/$Env:BHProjectName.psd1"
$projectRoot = Split-Path -Path $PSScriptRoot -Parent
$sourceManifest = Join-Path -Path $projectRoot -ChildPath "$Env:BHProjectName/$Env:BHProjectName.psd1"
$moduleVersion = (Import-PowerShellDataFile -Path $sourceManifest).ModuleVersion
$Env:BHBuildOutput = Join-Path $projectRoot "Output/$Env:BHProjectName/$moduleVersion"
$Env:BHBuildOutput = Join-Path -Path $projectRoot -ChildPath "Output/$Env:BHProjectName/$moduleVersion"

# Define the path to the module manifest
$moduleManifestFilename = $Env:BHProjectName + '.psd1'
Expand All @@ -145,12 +145,12 @@ BeforeAll {
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'ManifestHelpers.psm1') -Verbose:$false -Force

$requirementsPath = Join-Path -Path $env:BHProjectPath -ChildPath 'requirements.psd1'
$requirements = Import-PowerShellDataFile -Path $requirementsPath -ErrorAction Stop
$requirements = Import-PowerShellDataFile -Path $requirementsPath -ErrorAction 'Stop'

# Parse the version from the changelog
$changelogPath = Join-Path -Path $Env:BHProjectPath -ChildPath 'CHANGELOG.md'
$changelogVersionPattern = '^##\s\\?\[(?<Version>(\d+\.){1,3}\d+)\\?\]' # Matches on a line that starts with '## [Version]' or '## \[Version\]'
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
$changelogVersion = Get-Content -Path $changelogPath | ForEach-Object {
if ($_ -match $changelogVersionPattern) {
$changelogVersion = $matches.Version
break
Expand Down
6 changes: 3 additions & 3 deletions tests/Meta.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ BeforeAll {
$projectRoot = $PSScriptRoot
}

$allTextFiles = Get-TextFilesList $projectRoot
$allTextFiles = Get-TextFilesList -Root $projectRoot
$unicodeFilesCount = 0
$totalTabsCount = 0
foreach ($textFile in $allTextFiles) {
if (Test-FileUnicode $textFile) {
if (Test-FileUnicode -FileInfo $textFile) {
$unicodeFilesCount++
Write-Warning (
"File $($textFile.FullName) contains 0x00 bytes." +
Expand All @@ -24,7 +24,7 @@ BeforeAll {
$unicodeFilesCount | Should -Be 0

$fileName = $textFile.FullName
(Get-Content $fileName -Raw) | Select-String "`t" | Foreach-Object {
(Get-Content -Path $fileName -Raw) | Select-String -Pattern "`t" | Foreach-Object {
Write-Warning (
"There are tabs in $fileName." +
' Use Fixer "Get-TextFilesList `$pwd | ConvertTo-SpaceIndentation".'
Expand Down
6 changes: 5 additions & 1 deletion tests/MetaFixers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function ConvertTo-UTF8 {
[OutputType([void])]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNull()]
[System.IO.FileInfo]$FileInfo
)

Expand Down Expand Up @@ -56,6 +57,7 @@ function ConvertTo-SpaceIndentation {
[OutputType([void])]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNull()]
[System.IO.FileInfo]$FileInfo
)

Expand Down Expand Up @@ -85,6 +87,7 @@ function Get-TextFilesList {
[OutputType([System.IO.FileInfo])]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[string]$Root
)

Expand Down Expand Up @@ -159,10 +162,11 @@ function Get-UnicodeFilesList {
[OutputType([System.IO.FileInfo])]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Root
)

$root | Get-TextFilesList | Where-Object {
Comment thread
tablackburn marked this conversation as resolved.
Test-FileUnicode $_
Test-FileUnicode -FileInfo $_
}
}
Loading