1111[CmdletBinding ()]
1212param ()
1313
14- $importedYamlCommand = Get-Command - Name ConvertFrom-Yaml - ErrorAction SilentlyContinue
15- $skipArtifactTests = [string ]::IsNullOrWhiteSpace($env: PSMODULE_YAML_TEST_ARTIFACT ) -and (
16- $null -eq $importedYamlCommand -or $importedYamlCommand.ModuleName -ne ' Yaml'
17- )
14+ $script :repositoryRoot = $null
15+ $script :resolvedArtifactManifestPath = $null
16+ $script :artifactManifestPath = $null
1817
1918BeforeAll {
2019 . (Join-Path $PSScriptRoot ' TestBootstrap.ps1' )
21- $repositoryRoot = Split-Path - Parent $PSScriptRoot
22- $loadedYamlModule = if (-not [string ]::IsNullOrWhiteSpace(
23- $env: PSMODULE_YAML_TEST_ARTIFACT
24- )) {
25- Import-Module - Name $env: PSMODULE_YAML_TEST_ARTIFACT - Force - Global - PassThru |
20+ $script :repositoryRoot = (Resolve-Path - LiteralPath (Join-Path $PSScriptRoot ' ..' )).Path
21+ $defaultArtifactManifestPath = Join-Path $script :repositoryRoot ' outputs\module\Yaml\Yaml.psd1'
22+ $script :resolvedArtifactManifestPath = if (
23+ -not [string ]::IsNullOrWhiteSpace($env: PSMODULE_YAML_TEST_ARTIFACT )
24+ ) {
25+ $env: PSMODULE_YAML_TEST_ARTIFACT
26+ } elseif (Test-Path - LiteralPath $defaultArtifactManifestPath - PathType Leaf) {
27+ $defaultArtifactManifestPath
28+ } else {
29+ $null
30+ }
31+ $loadedYamlModule = if (-not [string ]::IsNullOrWhiteSpace($script :resolvedArtifactManifestPath )) {
32+ Import-Module - Name $script :resolvedArtifactManifestPath - Force - Global - PassThru |
2633 Where-Object Name -EQ ' Yaml' |
2734 Select-Object - First 1
28- } else {
29- $command = Get-Command - Name ConvertFrom-Yaml - ErrorAction SilentlyContinue
30- if ($null -ne $command -and $command.ModuleName -eq ' Yaml' ) {
31- $command.Module
32- }
3335 }
34- $artifactManifestPath = if ($null -ne $loadedYamlModule ) {
36+ $script : artifactManifestPath = if ($null -ne $loadedYamlModule ) {
3537 Join-Path $loadedYamlModule.ModuleBase ' Yaml.psd1'
3638 } else {
3739 $null
@@ -41,16 +43,16 @@ BeforeAll {
4143Describe ' Dependency-free package source' {
4244 It ' contains no external parser assembly, license, or notice payload' {
4345 @ (
44- Get-ChildItem - Path (Join-Path $repositoryRoot ' src\assemblies' ) `
46+ Get-ChildItem - Path (Join-Path $script : repositoryRoot ' src\assemblies' ) `
4547 - File - ErrorAction SilentlyContinue
4648 ).Count | Should - Be 0
47- Test-Path (Join-Path $repositoryRoot ' src\licenses\YamlDotNet.LICENSE.txt' ) | Should - BeFalse
48- Test-Path (Join-Path $repositoryRoot ' src\THIRD-PARTY-NOTICES.txt' ) | Should - BeFalse
49+ Test-Path (Join-Path $script : repositoryRoot ' src\licenses\YamlDotNet.LICENSE.txt' ) | Should - BeFalse
50+ Test-Path (Join-Path $script : repositoryRoot ' src\THIRD-PARTY-NOTICES.txt' ) | Should - BeFalse
4951 }
5052
5153 It ' keeps RequiredAssemblies out of the source manifest' {
5254 $manifest = Import-PowerShellDataFile - Path (
53- Join-Path $repositoryRoot ' src\manifest.psd1'
55+ Join-Path $script : repositoryRoot ' src\manifest.psd1'
5456 )
5557
5658 $manifest.PowerShellVersion | Should - Be ' 7.6'
@@ -60,7 +62,7 @@ Describe 'Dependency-free package source' {
6062 }
6163
6264 It ' contains no external parser references or custom assembly loader' {
63- $sourceFiles = Get-ChildItem - Path (Join-Path $repositoryRoot ' src' ) - Recurse - File
65+ $sourceFiles = Get-ChildItem - Path (Join-Path $script : repositoryRoot ' src' ) - Recurse - File
6466 $source = $sourceFiles |
6567 Where-Object Extension -In @ (' .ps1' , ' .psd1' , ' .psm1' ) |
6668 Get-Content - Raw
@@ -71,7 +73,7 @@ Describe 'Dependency-free package source' {
7173 }
7274
7375 It ' keeps the owned processor layers explicit and source-level' {
74- $privatePath = Join-Path $repositoryRoot ' src\functions\private'
76+ $privatePath = Join-Path $script : repositoryRoot ' src\functions\private'
7577 @ (
7678 ' New-YamlReaderContext.ps1' ,
7779 ' Read-YamlDirectiveBlock.ps1' ,
@@ -90,7 +92,7 @@ Describe 'Dependency-free package source' {
9092
9193 It ' uses Process-PSModule 6.1.13 and treats tests as important changes' {
9294 $workflow = Get-Content - Path (
93- Join-Path $repositoryRoot ' .github\workflows\Process-PSModule.yml'
95+ Join-Path $script : repositoryRoot ' .github\workflows\Process-PSModule.yml'
9496 ) - Raw
9597
9698 $workflow | Should -Match ' workflow\.yml@fb1bdb8fefd243292f779d2a856a38db6fe6daf4 # v6\.1\.13'
@@ -100,28 +102,28 @@ Describe 'Dependency-free package source' {
100102
101103 It ' does not skip generated documentation' {
102104 $configuration = Get-Content - Path (
103- Join-Path $repositoryRoot ' .github\PSModule.yml'
105+ Join-Path $script : repositoryRoot ' .github\PSModule.yml'
104106 ) - Raw
105107
106108 $configuration | Should -Not -Match ' (?ms)Build:\s+Docs:\s+.*Skip:\s*true'
107109 }
108110
109111 It ' uses zensical configuration and does not skip site build' {
110112 $configuration = Get-Content - Path (
111- Join-Path $repositoryRoot ' .github\PSModule.yml'
113+ Join-Path $script : repositoryRoot ' .github\PSModule.yml'
112114 ) - Raw
113115
114116 $configuration | Should -Not -Match ' (?ms)Build:\s+Site:\s+.*Skip:\s*true'
115- Test-Path - Path (Join-Path $repositoryRoot ' .github\zensical.toml' ) | Should - BeTrue
116- Test-Path - Path (Join-Path $repositoryRoot ' .github\mkdocs.yml' ) | Should - BeFalse
117+ Test-Path - Path (Join-Path $script : repositoryRoot ' .github\zensical.toml' ) | Should - BeTrue
118+ Test-Path - Path (Join-Path $script : repositoryRoot ' .github\mkdocs.yml' ) | Should - BeFalse
117119 }
118120}
119121
120122Describe ' Generated artifact package' {
121123 It ' has no RequiredAssemblies or packaged DLL and has a complete FileList' `
122- - Skip:$skipArtifactTests {
123- $manifest = Import-PowerShellDataFile - Path $artifactManifestPath
124- $moduleBase = Split-Path - Parent $artifactManifestPath
124+ - Skip:([ string ]::IsNullOrWhiteSpace( $ env: PSMODULE_YAML_TEST_ARTIFACT ) -and -not ( Test-Path - LiteralPath ( Join-Path ( Resolve-Path - LiteralPath ( Join-Path $PSScriptRoot ' .. ' )).Path ' outputs\module\Yaml\Yaml.psd1 ' ) - PathType Leaf)) {
125+ $manifest = Import-PowerShellDataFile - Path $script : artifactManifestPath
126+ $moduleBase = Split-Path - Parent $script : artifactManifestPath
125127
126128 $manifest.PowerShellVersion | Should - Be ' 7.6'
127129 @ ($manifest.CompatiblePSEditions ) | Should - Be @ (' Core' )
@@ -137,7 +139,7 @@ Describe 'Generated artifact package' {
137139 }
138140
139141 It ' imports in a fresh PowerShell 7 process and preserves arrays, aliases, and depth' `
140- - Skip:($skipArtifactTests -or $null -eq (Get-Command pwsh - ErrorAction SilentlyContinue)) {
142+ - Skip:(([ string ]::IsNullOrWhiteSpace( $ env: PSMODULE_YAML_TEST_ARTIFACT ) -and -not ( Test-Path - LiteralPath ( Join-Path ( Resolve-Path - LiteralPath ( Join-Path $PSScriptRoot ' .. ' )).Path ' outputs\module\Yaml\Yaml.psd1 ' ) - PathType Leaf)) -or $null -eq (Get-Command pwsh - ErrorAction SilentlyContinue)) {
141143 $script = @'
142144$ErrorActionPreference = 'Stop'
143145$ps = $PSVersionTable.PSVersion
@@ -180,7 +182,7 @@ if (-not (Test-Yaml -Yaml $deepYaml -Depth 128 -MaxNodes 300)) {
180182 throw 'The public maximum serialization depth failed.'
181183}
182184'powershell-7-ok'
183- '@ .Replace(' __MANIFEST__' , $artifactManifestPath.Replace (" '" , " ''" ))
185+ '@ .Replace(' __MANIFEST__' , $script : artifactManifestPath.Replace (" '" , " ''" ))
184186
185187 (& pwsh - NoLogo - NoProfile - Command $script ) |
186188 Should - Contain ' powershell-7-ok'
0 commit comments