Skip to content

Commit 9bba8e0

Browse files
ci: exercise the built module in tests
Prefer the workflow-imported artifact so Pester coverage measures real module execution, exclude pinned YAML fixtures from repository config linting, and skip PlatyPS docs generation because it preloads a conflicting YamlDotNet assembly. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 4e472cf commit 9bba8e0

3 files changed

Lines changed: 56 additions & 24 deletions

File tree

.github/PSModule.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ Test:
1616
# Skip: true
1717
# MacOS:
1818
# Skip: true
19-
# Build:
20-
# Docs:
21-
# Skip: true
19+
Build:
20+
Docs:
21+
# PlatyPS loads a conflicting YamlDotNet assembly before importing this module.
22+
Skip: true
2223

2324
Linter:
2425
env:
26+
FILTER_REGEX_EXCLUDE: '.*tests/fixtures/.*'
2527
VALIDATE_BIOME_FORMAT: false
2628
VALIDATE_BIOME_LINT: false
2729
VALIDATE_GITHUB_ACTIONS_ZIZMOR: false

tests/Test-Yaml.Tests.ps1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,23 @@ Describe 'Test-Yaml' {
5959
$result = Test-Yaml -Yaml $yaml -MaxNodes 100 -MaxAliases 100
6060
$stopwatch.Stop()
6161

62-
$document = @(Read-YamlStreamCore -Yaml $yaml -Depth 100 -MaxNodes 100 -MaxAliases 100 `
63-
-MaxScalarLength 1048576)[0]
64-
$cache = [System.Collections.Generic.Dictionary[int, string]]::new()
65-
$hasher = [System.Security.Cryptography.SHA256]::Create()
66-
try {
67-
Test-YamlNodeGraph -Node $document -Visited ([System.Collections.Generic.HashSet[int]]::new()) `
68-
-FingerprintCache $cache -FingerprintHasher $hasher
69-
} finally {
70-
$hasher.Dispose()
71-
}
62+
$fingerprintLengths = @(Get-TestYamlFingerprintLength -Yaml $yaml)
7263

7364
$result | Should -BeTrue
7465
$stopwatch.Elapsed.TotalSeconds | Should -BeLessThan 5
75-
@($cache.Values | Where-Object Length -NE 44).Count | Should -Be 0
66+
@($fingerprintLengths | Where-Object { $_ -ne 44 }).Count | Should -Be 0
7667
}
7768

7869
It 'does not swallow an unexpected runtime failure' {
79-
Mock Read-YamlStream {
80-
throw [System.InvalidOperationException]::new('unexpected runtime failure')
70+
$loadedModule = Get-Module -Name Yaml | Select-Object -First 1
71+
if ($null -eq $loadedModule) {
72+
Mock Read-YamlStream {
73+
throw [System.InvalidOperationException]::new('unexpected runtime failure')
74+
}
75+
} else {
76+
Mock Read-YamlStream -ModuleName $loadedModule.Name {
77+
throw [System.InvalidOperationException]::new('unexpected runtime failure')
78+
}
8179
}
8280

8381
{ 'name: Ada' | Test-Yaml } |

tests/TestBootstrap.ps1

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
1-
$assemblyPath = Join-Path $PSScriptRoot '..\src\assemblies\YamlDotNet.dll'
2-
[void][System.Reflection.Assembly]::LoadFrom((Resolve-Path $assemblyPath))
1+
$yamlModule = Get-Module -Name Yaml | Select-Object -First 1
2+
if ($null -eq $yamlModule) {
3+
$assemblyPath = Join-Path $PSScriptRoot '..\src\assemblies\YamlDotNet.dll'
4+
[void][System.Reflection.Assembly]::LoadFrom((Resolve-Path $assemblyPath))
35

4-
Get-ChildItem -Path (Join-Path $PSScriptRoot '..\src\functions\private') -Filter '*.ps1' |
5-
Sort-Object Name |
6-
ForEach-Object { . $_.FullName }
6+
Get-ChildItem -Path (Join-Path $PSScriptRoot '..\src\functions\private') -Filter '*.ps1' |
7+
Sort-Object Name |
8+
ForEach-Object { . $_.FullName }
79

8-
Get-ChildItem -Path (Join-Path $PSScriptRoot '..\src\functions\public') -Filter '*.ps1' |
9-
Sort-Object Name |
10-
ForEach-Object { . $_.FullName }
10+
Get-ChildItem -Path (Join-Path $PSScriptRoot '..\src\functions\public') -Filter '*.ps1' |
11+
Sort-Object Name |
12+
ForEach-Object { . $_.FullName }
13+
}
14+
15+
function Get-TestYamlFingerprintLength {
16+
param (
17+
[Parameter(Mandatory)]
18+
[string] $Yaml
19+
)
20+
21+
$implementation = {
22+
param ([string] $YamlText)
23+
24+
$document = @(Read-YamlStreamCore -Yaml $YamlText -Depth 100 -MaxNodes 100 -MaxAliases 100 `
25+
-MaxScalarLength 1048576)[0]
26+
$cache = [System.Collections.Generic.Dictionary[int, string]]::new()
27+
$hasher = [System.Security.Cryptography.SHA256]::Create()
28+
try {
29+
Test-YamlNodeGraph -Node $document -Visited ([System.Collections.Generic.HashSet[int]]::new()) `
30+
-FingerprintCache $cache -FingerprintHasher $hasher
31+
} finally {
32+
$hasher.Dispose()
33+
}
34+
@($cache.Values | ForEach-Object Length)
35+
}
36+
37+
$loadedModule = Get-Module -Name Yaml | Select-Object -First 1
38+
if ($null -eq $loadedModule) {
39+
return @(& $implementation $Yaml)
40+
}
41+
return @(& $loadedModule $implementation $Yaml)
42+
}

0 commit comments

Comments
 (0)