Skip to content

Commit 8485d30

Browse files
Merge remote-tracking branch 'origin/main' into fix/bump-install-psmodulehelpers
2 parents cd87b63 + 033609e commit 8485d30

5 files changed

Lines changed: 98 additions & 6 deletions

File tree

.github/workflows/Action-Test-outputs.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ permissions: {}
1616

1717
jobs:
1818
ActionTestOutputs:
19-
name: Action-Test [outputs] - [${{ matrix.os }}]
19+
name: Action-Test [outputs/${{ matrix.fixture.name }}] - [${{ matrix.os }}]
2020
strategy:
2121
fail-fast: false
2222
matrix:
2323
os: [ubuntu-latest, macos-latest, windows-latest]
24+
fixture:
25+
- name: PSModuleTest
26+
workingDirectory: tests/outputTestRepo
27+
coveragePercentTarget: 30
28+
- name: PSModuleEnumOnly
29+
workingDirectory: tests/outputEnumOnlyTestRepo
30+
coveragePercentTarget: 0
2431
runs-on: ${{ matrix.os }}
2532
steps:
2633
- name: Checkout repo
@@ -32,7 +39,7 @@ jobs:
3239
uses: ./
3340
id: action-test
3441
with:
35-
Name: PSModuleTest
36-
WorkingDirectory: tests/outputTestRepo
42+
Name: ${{ matrix.fixture.name }}
43+
WorkingDirectory: ${{ matrix.fixture.workingDirectory }}
3744
Settings: Module
38-
CodeCoverage_CoveragePercentTarget: 30
45+
CodeCoverage_CoveragePercentTarget: ${{ matrix.fixture.coveragePercentTarget }}

src/tests/Module/PSModule/PSModule.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ Describe 'PSModule - Module tests' {
9999
BeforeAll {
100100
Import-Module -Name $moduleManifestPath -Force
101101
}
102-
It 'Should register public enum [<_>] as a type accelerator' -ForEach $expectedEnumNames {
102+
It 'Should register public enum [<_>] as a type accelerator' -ForEach $expectedEnumNames -AllowNullOrEmptyForEach {
103103
$registered = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
104104
$registered.Keys | Should -Contain $_ -Because 'the framework registers public enums as type accelerators'
105105
}
106106

107-
It 'Should register public class [<_>] as a type accelerator' -ForEach $expectedClassNames {
107+
It 'Should register public class [<_>] as a type accelerator' -ForEach $expectedClassNames -AllowNullOrEmptyForEach {
108108
$registered = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
109109
$registered.Keys | Should -Contain $_ -Because 'the framework registers public classes as type accelerators'
110110
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@{
2+
RootModule = 'PSModuleEnumOnly.psm1'
3+
ModuleVersion = '999.0.0'
4+
CompatiblePSEditions = @(
5+
'Core'
6+
'Desktop'
7+
)
8+
GUID = 'b1c8c046-2253-4f30-8e08-e98a222a954a'
9+
Author = 'PSModule'
10+
CompanyName = 'PSModule'
11+
Copyright = '(c) 2024 PSModule. All rights reserved.'
12+
Description = 'Fixture module with enum type accelerators and no class type accelerators.'
13+
PowerShellVersion = '5.1'
14+
ProcessorArchitecture = 'None'
15+
FunctionsToExport = @()
16+
CmdletsToExport = @()
17+
VariablesToExport = @()
18+
AliasesToExport = @()
19+
FileList = @(
20+
'PSModuleEnumOnly.psd1'
21+
'PSModuleEnumOnly.psm1'
22+
)
23+
PrivateData = @{
24+
PSData = @{
25+
Tags = @(
26+
'workflow'
27+
'powershell'
28+
'powershell-module'
29+
'PSEdition_Desktop'
30+
'PSEdition_Core'
31+
)
32+
LicenseUri = 'https://github.com/PSModule/Test-PSModule/blob/main/LICENSE'
33+
ProjectUri = 'https://github.com/PSModule/Test-PSModule'
34+
}
35+
}
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[CmdletBinding()]
2+
param()
3+
4+
enum ModuleLifecycle {
5+
Loaded
6+
Removed
7+
}
8+
9+
#region Class exporter
10+
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
11+
'System.Management.Automation.TypeAccelerators'
12+
)
13+
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
14+
$ExportableEnums = @(
15+
[ModuleLifecycle]
16+
)
17+
$ExportableEnums | ForEach-Object { Write-Verbose "Exporting enum '$($_.FullName)'." }
18+
foreach ($Type in $ExportableEnums) {
19+
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
20+
Write-Verbose "Enum already exists [$($Type.FullName)]. Skipping."
21+
} else {
22+
Write-Verbose "Importing enum '$Type'."
23+
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
24+
}
25+
}
26+
$ExportableClasses = @(
27+
)
28+
$ExportableClasses | ForEach-Object { Write-Verbose "Exporting class '$($_.FullName)'." }
29+
foreach ($Type in $ExportableClasses) {
30+
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
31+
Write-Verbose "Class already exists [$($Type.FullName)]. Skipping."
32+
} else {
33+
Write-Verbose "Importing class '$Type'."
34+
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
35+
}
36+
}
37+
38+
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
39+
$CurrentTypeAccelerators = $TypeAcceleratorsClass::Get
40+
foreach ($Type in ($ExportableEnums + $ExportableClasses)) {
41+
if ($CurrentTypeAccelerators[$Type.FullName] -eq $Type) {
42+
$null = $TypeAcceleratorsClass::Remove($Type.FullName)
43+
}
44+
}
45+
}.GetNewClosure()
46+
#endregion Class exporter
47+
48+
Export-ModuleMember -Function @() -Alias @() -Variable @()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tracks the fixture tests directory required by the action setup step.

0 commit comments

Comments
 (0)