File tree Expand file tree Collapse file tree
src/tests/Module/PSModule
tests/outputEnumOnlyTestRepo
outputs/module/PSModuleEnumOnly Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,11 +16,18 @@ permissions: {}
1616
1717jobs :
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
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 }}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 @ ()
Original file line number Diff line number Diff line change 1+ Tracks the fixture tests directory required by the action setup step.
You can’t perform that action at this time.
0 commit comments