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
15 changes: 11 additions & 4 deletions .github/workflows/Action-Test-outputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ permissions: {}

jobs:
ActionTestOutputs:
name: Action-Test [outputs] - [${{ matrix.os }}]
name: Action-Test [outputs/${{ matrix.fixture.name }}] - [${{ matrix.os }}]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
fixture:
- name: PSModuleTest
workingDirectory: tests/outputTestRepo
coveragePercentTarget: 30
- name: PSModuleEnumOnly
workingDirectory: tests/outputEnumOnlyTestRepo
coveragePercentTarget: 0
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
Expand All @@ -32,7 +39,7 @@ jobs:
uses: ./
id: action-test
with:
Name: PSModuleTest
WorkingDirectory: tests/outputTestRepo
Name: ${{ matrix.fixture.name }}
WorkingDirectory: ${{ matrix.fixture.workingDirectory }}
Settings: Module
CodeCoverage_CoveragePercentTarget: 30
CodeCoverage_CoveragePercentTarget: ${{ matrix.fixture.coveragePercentTarget }}
4 changes: 2 additions & 2 deletions src/tests/Module/PSModule/PSModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ Describe 'PSModule - Module tests' {
BeforeAll {
Import-Module -Name $moduleManifestPath -Force
}
It 'Should register public enum [<_>] as a type accelerator' -ForEach $expectedEnumNames {
It 'Should register public enum [<_>] as a type accelerator' -ForEach $expectedEnumNames -AllowNullOrEmptyForEach {
$registered = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
$registered.Keys | Should -Contain $_ -Because 'the framework registers public enums as type accelerators'
}

It 'Should register public class [<_>] as a type accelerator' -ForEach $expectedClassNames {
It 'Should register public class [<_>] as a type accelerator' -ForEach $expectedClassNames -AllowNullOrEmptyForEach {
$registered = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')::Get
$registered.Keys | Should -Contain $_ -Because 'the framework registers public classes as type accelerators'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@{
RootModule = 'PSModuleEnumOnly.psm1'
ModuleVersion = '999.0.0'
CompatiblePSEditions = @(
'Core'
'Desktop'
)
GUID = 'b1c8c046-2253-4f30-8e08-e98a222a954a'
Author = 'PSModule'
CompanyName = 'PSModule'
Copyright = '(c) 2024 PSModule. All rights reserved.'
Description = 'Fixture module with enum type accelerators and no class type accelerators.'
PowerShellVersion = '5.1'
ProcessorArchitecture = 'None'
FunctionsToExport = @()
CmdletsToExport = @()
VariablesToExport = @()
AliasesToExport = @()
FileList = @(
'PSModuleEnumOnly.psd1'
'PSModuleEnumOnly.psm1'
)
PrivateData = @{
PSData = @{
Tags = @(
'workflow'
'powershell'
'powershell-module'
'PSEdition_Desktop'
'PSEdition_Core'
)
LicenseUri = 'https://github.com/PSModule/Test-PSModule/blob/main/LICENSE'
ProjectUri = 'https://github.com/PSModule/Test-PSModule'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[CmdletBinding()]
param()

enum ModuleLifecycle {
Loaded
Removed
}

#region Class exporter
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
'System.Management.Automation.TypeAccelerators'
)
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
$ExportableEnums = @(
[ModuleLifecycle]
)
$ExportableEnums | ForEach-Object { Write-Verbose "Exporting enum '$($_.FullName)'." }
foreach ($Type in $ExportableEnums) {
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
Write-Verbose "Enum already exists [$($Type.FullName)]. Skipping."
} else {
Write-Verbose "Importing enum '$Type'."
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
}
}
$ExportableClasses = @(
)
$ExportableClasses | ForEach-Object { Write-Verbose "Exporting class '$($_.FullName)'." }
foreach ($Type in $ExportableClasses) {
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
Write-Verbose "Class already exists [$($Type.FullName)]. Skipping."
} else {
Write-Verbose "Importing class '$Type'."
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
}
}

$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
$CurrentTypeAccelerators = $TypeAcceleratorsClass::Get
foreach ($Type in ($ExportableEnums + $ExportableClasses)) {
if ($CurrentTypeAccelerators[$Type.FullName] -eq $Type) {
$null = $TypeAcceleratorsClass::Remove($Type.FullName)
}
}
}.GetNewClosure()
#endregion Class exporter

Export-ModuleMember -Function @() -Alias @() -Variable @()
1 change: 1 addition & 0 deletions tests/outputEnumOnlyTestRepo/tests/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tracks the fixture tests directory required by the action setup step.
Loading