Skip to content

Commit 8e3fff0

Browse files
author
JustinGrote
committed
Update to latest tests
1 parent 104286e commit 8e3fff0

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

Tests/00-PowershellModule.Tests.ps1

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#requires -module BuildHelpers
2+
if (-not import-module BuildHelpers -PassThru -erroraction silentlycontinue) {
3+
install-module buildhelpers -scope currentuser -erroraction stop -force
4+
import-module BuildHelpers -erroraction stop
5+
}
6+
27
$PSVersion = $PSVersionTable.PSVersion.Major
38
$BuildOutputProject = Join-Path $env:BHBuildOutput $env:BHProjectName
4-
Describe "Module Build" {
5-
$ModuleManifestPath = Join-Path $BuildOutputProject "\*.psd1"
69

10+
Describe 'Powershell Module' {
11+
$ModuleManifestPath = Join-Path $BuildOutputProject '\*.psd1'
712
Context "$env:BHProjectName" {
813
$ModuleName = $env:BHProjectName
9-
It "Has a valid Module Manifest" {
10-
if ($isCoreCLR) {
14+
It 'Has a valid Module Manifest' {
15+
if ($isCoreCLR -or $PSVersionTable.PSVersion -ge [Version]"5.1") {
1116
$Script:Manifest = Test-ModuleManifest $ModuleManifestPath
1217
} else {
1318
#Copy the Module Manifest to a temp file in order to test to fix a bug where
@@ -19,47 +24,50 @@ Describe "Module Build" {
1924
}
2025
}
2126

22-
It "Has a valid root module" {
27+
It 'Has a valid root module' {
2328
$Manifest.RootModule | Should Be "$ModuleName.psm1"
2429
}
2530

26-
It "Has a valid Description" {
31+
It 'Has a valid Description' {
2732
$Manifest.Description | Should Not BeNullOrEmpty
2833
}
2934

30-
It "Has a valid GUID" {
35+
It 'Has a valid GUID' {
3136
[Guid]$Manifest.Guid | Should BeOfType 'System.GUID'
3237
}
3338

34-
It "Has a valid Copyright" {
39+
It 'Has a valid Copyright' {
3540
$Manifest.Copyright | Should Not BeNullOrEmpty
3641
}
3742

3843
It 'Exports all public functions' {
39-
$FunctionFiles = Get-ChildItem "$BuildOutputProject\Public" -Filter *.ps1 | Select-Object -ExpandProperty BaseName
40-
$FunctionNames = $FunctionFiles | ForEach-Object {$_ -replace '-', "-$($Manifest.Prefix)"}
44+
$FunctionFiles = Get-ChildItem "$BuildOutputProject\Public" -Filter *.ps1 | Select -ExpandProperty BaseName
45+
$FunctionNames = $FunctionFiles | foreach {$_ -replace '-', "-$($Manifest.Prefix)"}
4146
$ExFunctions = $Manifest.ExportedFunctions.Values.Name
4247
foreach ($FunctionName in $FunctionNames)
4348
{
4449
$ExFunctions -contains $FunctionName | Should Be $true
4550
}
4651
}
4752

48-
It "Has at least 1 exported command" {
53+
It 'Has at least 1 exported command' {
4954
$Script:Manifest.exportedcommands.count | Should BeGreaterThan 0
5055
}
51-
It "Can be imported as a module successfully" {
56+
It 'Can be imported as a module successfully' {
57+
Remove-Module $ModuleName -ErrorAction SilentlyContinue
5258
Import-Module $BuildOutputProject -PassThru -OutVariable BuildOutputModule | Should BeOfType System.Management.Automation.PSModuleInfo
5359
$BuildOutputModule.Name | Should Be $ModuleName
5460
}
55-
It "Is visible in Get-Module" {
56-
(Get-Module $ModuleName).Name | Should Be $ModuleName
61+
It 'Is visible in Get-Module' {
62+
$module = Get-Module $ModuleName
63+
$Module | Should BeOfType System.Management.Automation.PSModuleInfo
64+
$Module.Name | Should Be $ModuleName
5765
}
5866
}
5967
}
6068

61-
Describe "PSScriptAnalyzer" {
62-
$results = Invoke-ScriptAnalyzer -Path $BuildOutputProject -Recurse -ExcludeRule "PSAvoidUsingCmdletAliases"
69+
Describe 'PSScriptAnalyzer' {
70+
$results = Invoke-ScriptAnalyzer -Path $BuildOutputProject -Recurse -ExcludeRule "PSAvoidUsingCmdletAliases" -Verbose:$false
6371
It 'PSScriptAnalyzer returns zero errors for all files in the repository' {
6472
$results.Count | Should Be 0
6573
}

0 commit comments

Comments
 (0)