Skip to content

Commit 846c56a

Browse files
Migrate Pester test suite from v4 to v5 (#164)
## Summary - **Test files**: Fully migrated `PSDepend.Tests.ps1` and `PSModuleGallery.Type.Tests.ps1` to Pester 5 — all setup code moved into `BeforeAll` blocks with `$script:` scoped variables, assertion syntax updated (`Should be` → `Should -Be`), `Assert-MockCalled` replaced with `Should -Invoke`, `-ExclusiveFilter` replaced with a two-assertion pattern, `-Scope It` removed, stub function definitions moved into `BeforeAll` so they survive the discovery→run phase boundary - **`Get-ClonedObject.ps1`**: Replaced `BinaryFormatter` (removed in .NET 7) with a recursive hashtable deep-clone — fixes 2 test failures on PS7 - **`Test-PlatformSupport.ps1`**: Added a PS Core on Windows exemption so dependency types that declare `Supports = 'windows'` (FileDownload, FileSystem, Chocolatey) are no longer incorrectly skipped under PS7 Core on Windows — fixes 12 test failures **Result: 92 passed, 0 failed, 1 skipped** (the 1 skip is a pre-existing `PendingSkip` tag, not a regression) ## Test plan - [x] Run `Invoke-Pester ./Tests -Output Detailed` locally — 92 passed, 0 failed - [x] Verify CI passes on Windows, macOS, and Ubuntu runners (GitHub Actions matrix) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8fcca52 commit 846c56a

29 files changed

Lines changed: 1276 additions & 1107 deletions

.github/workflows/ci.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
name: CI
2-
permissions:
3-
checks: write
4-
pull-requests: write
5-
contents: read
62
on:
73
push:
8-
branches: [master]
4+
branches: [ master ]
95
paths:
10-
- 'PSDepend/**'
11-
- 'Tests/**'
12-
- 'build.ps1'
13-
- 'psakeFile.ps1'
14-
- 'requirements.psd1'
6+
- "PSDepend/**"
7+
- "Tests/**"
8+
- "build.ps1"
9+
- "psakeFile.ps1"
10+
- "requirements.psd1"
1511
pull_request:
1612
paths:
17-
- 'PSDepend/**'
18-
- 'Tests/**'
19-
- 'build.ps1'
20-
- 'psakeFile.ps1'
21-
- 'requirements.psd1'
13+
- "PSDepend/**"
14+
- "Tests/**"
15+
- "build.ps1"
16+
- "psakeFile.ps1"
17+
- "requirements.psd1"
2218
workflow_dispatch:
2319

2420
jobs:
2521
test:
2622
name: Test (${{ matrix.os }})
2723
runs-on: ${{ matrix.os }}
24+
permissions:
25+
contents: read
2826
strategy:
2927
fail-fast: false
3028
matrix:
31-
os: [ubuntu-latest, windows-latest, macOS-latest]
29+
os: [ ubuntu-latest, windows-latest, macOS-latest ]
3230
steps:
3331
- uses: actions/checkout@v4
34-
- name: Bootstrap and Test
32+
- name: Bootstrap
3533
shell: pwsh
36-
run: ./build.ps1 -Bootstrap -Task Test
34+
run: ./build.ps1 -Bootstrap -Task Init
35+
- name: Test
36+
shell: pwsh
37+
run: ./build.ps1 -Task Test
3738
- name: Upload Test Results
3839
if: always()
3940
uses: actions/upload-artifact@v4
4041
with:
4142
name: testResults-${{ matrix.os }}
42-
path: ./Output/testResults.xml
43+
path: ./Tests/out/testResults.xml
4344

4445
publish-test-results:
4546
name: Publish Test Results
4647
needs: test
4748
runs-on: ubuntu-latest
49+
permissions:
50+
checks: write
51+
pull-requests: write
4852
if: ${{ !cancelled() }}
4953
steps:
5054
- uses: actions/download-artifact@v4

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
nuget.exe
1+
nuget.exe
2+
Output/**
3+
Tests/Output/**
4+
Tests/out/**

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
"powershell.codeFormatting.ignoreOneLineBlock": false,
44
"powershell.codeFormatting.whitespaceAfterSeparator": false,
55
"powershell.codeFormatting.whitespaceAroundOperator": false,
6-
"powershell.codeFormatting.whitespaceBeforeOpenParen": false
7-
}
6+
"powershell.codeFormatting.whitespaceBeforeOpenParen": false,
7+
"powershell.codeFormatting.preset": "OTBS",
8+
"powershell.codeFormatting.trimWhitespaceAroundPipe": true
9+
}

PSDepend/PSDepend.psd1

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,111 @@
11
@{
22

3-
# Script module or binary module file associated with this manifest.
4-
RootModule = 'PSDepend.psm1'
3+
# Script module or binary module file associated with this manifest.
4+
RootModule = 'PSDepend.psm1'
55

6-
# Version number of this module.
7-
ModuleVersion = '0.3.0'
6+
# Version number of this module.
7+
ModuleVersion = '0.3.0'
88

9-
# ID used to uniquely identify this module
10-
GUID = '63ea9e2a-320d-43ff-a11a-4930ca03cce6'
9+
# ID used to uniquely identify this module
10+
GUID = '63ea9e2a-320d-43ff-a11a-4930ca03cce6'
1111

12-
# Author of this module
13-
Author = 'Warren Frame'
12+
# Author of this module
13+
Author = 'Warren Frame'
1414

15-
# Company or vendor of this module
16-
#CompanyName = 'Unknown'
15+
# Company or vendor of this module
16+
#CompanyName = 'Unknown'
1717

18-
# Copyright statement for this module
19-
Copyright = '(c) 2016 Warren F. All rights reserved.'
18+
# Copyright statement for this module
19+
Copyright = '(c) 2016 Warren F. All rights reserved.'
2020

21-
# Description of the functionality provided by this module
22-
Description = 'PowerShell Dependency Handler'
21+
# Description of the functionality provided by this module
22+
Description = 'PowerShell Dependency Handler'
2323

24-
# Minimum version of the Windows PowerShell engine required by this module
25-
PowerShellVersion = '3.0'
24+
# Minimum version of the Windows PowerShell engine required by this module
25+
PowerShellVersion = '3.0'
2626

27-
# Name of the Windows PowerShell host required by this module
28-
# PowerShellHostName = ''
27+
# Name of the Windows PowerShell host required by this module
28+
# PowerShellHostName = ''
2929

30-
# Minimum version of the Windows PowerShell host required by this module
31-
# PowerShellHostVersion = ''
30+
# Minimum version of the Windows PowerShell host required by this module
31+
# PowerShellHostVersion = ''
3232

33-
# Minimum version of Microsoft .NET Framework required by this module
34-
# DotNetFrameworkVersion = ''
33+
# Minimum version of Microsoft .NET Framework required by this module
34+
# DotNetFrameworkVersion = ''
3535

36-
# Minimum version of the common language runtime (CLR) required by this module
37-
# CLRVersion = ''
36+
# Minimum version of the common language runtime (CLR) required by this module
37+
# CLRVersion = ''
3838

39-
# Processor architecture (None, X86, Amd64) required by this module
40-
# ProcessorArchitecture = ''
39+
# Processor architecture (None, X86, Amd64) required by this module
40+
# ProcessorArchitecture = ''
4141

42-
# Modules that must be imported into the global environment prior to importing this module
43-
# RequiredModules = @()
42+
# Modules that must be imported into the global environment prior to importing this module
43+
# RequiredModules = @()
4444

45-
# Assemblies that must be loaded prior to importing this module
46-
# RequiredAssemblies = @()
45+
# Assemblies that must be loaded prior to importing this module
46+
# RequiredAssemblies = @()
4747

48-
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
49-
# ScriptsToProcess = @()
48+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
49+
# ScriptsToProcess = @()
5050

51-
# Type files (.ps1xml) to be loaded when importing this module
52-
# TypesToProcess = @()
51+
# Type files (.ps1xml) to be loaded when importing this module
52+
# TypesToProcess = @()
5353

54-
# Format files (.ps1xml) to be loaded when importing this module
55-
FormatsToProcess = 'PSDepend.Format.ps1xml'
54+
# Format files (.ps1xml) to be loaded when importing this module
55+
FormatsToProcess = 'PSDepend.Format.ps1xml'
5656

57-
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
58-
# NestedModules = @()
57+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
58+
# NestedModules = @()
5959

60-
# Functions to export from this module
61-
FunctionsToExport = @('Get-Dependency','Get-PSDependScript','Get-PSDependType','Import-Dependency','Install-Dependency','Invoke-DependencyScript','Invoke-PSDepend','Test-Dependency')
60+
# Functions to export from this module
61+
FunctionsToExport = @('Get-Dependency','Get-PSDependScript','Get-PSDependType','Import-Dependency','Install-Dependency','Invoke-DependencyScript','Invoke-PSDepend','Test-Dependency')
6262

63-
# Cmdlets to export from this module
64-
CmdletsToExport = '*'
63+
# Cmdlets to export from this module
64+
CmdletsToExport = '*'
6565

66-
# Variables to export from this module
67-
# VariablesToExport = '*'
66+
# Variables to export from this module
67+
# VariablesToExport = '*'
6868

69-
# Aliases to export from this module
70-
AliasesToExport = '*'
69+
# Aliases to export from this module
70+
AliasesToExport = '*'
7171

72-
# DSC resources to export from this module
73-
# DscResourcesToExport = @()
72+
# DSC resources to export from this module
73+
# DscResourcesToExport = @()
7474

75-
# List of all modules packaged with this module
76-
# ModuleList = @()
75+
# List of all modules packaged with this module
76+
# ModuleList = @()
7777

78-
# List of all files packaged with this module
79-
# FileList = @()
78+
# List of all files packaged with this module
79+
# FileList = @()
8080

81-
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
82-
PrivateData = @{
81+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
82+
PrivateData = @{
8383

84-
PSData = @{
84+
PSData = @{
8585

86-
# Tags applied to this module. These help with module discovery in online galleries.
87-
Tags = @('requirements', 'dependencies', 'dependency', 'manager', 'bundle', 'package')
86+
# Tags applied to this module. These help with module discovery in online galleries.
87+
Tags = @('requirements', 'dependencies', 'dependency', 'manager', 'bundle', 'package')
8888

89-
# A URL to the license for this module.
90-
LicenseUri = 'https://github.com/RamblingCookieMonster/PSDepend/blob/master/LICENSE'
89+
# A URL to the license for this module.
90+
LicenseUri = 'https://github.com/PowerShellOrg/PSDepend/blob/master/LICENSE'
9191

92-
# A URL to the main website for this project.
93-
ProjectUri = 'https://github.com/RamblingCookieMonster/PSDepend/'
92+
# A URL to the main website for this project.
93+
ProjectUri = 'https://github.com/PowerShellOrg/PSDepend/'
9494

95-
# A URL to an icon representing this module.
96-
# IconUri = ''
95+
# A URL to an icon representing this module.
96+
# IconUri = ''
9797

98-
# ReleaseNotes of this module
99-
ReleaseNotes = 'Added various PowerShell Core fixes thanks to @lipkau!'
98+
# ReleaseNotes of this module
99+
ReleaseNotes = 'Added various PowerShell Core fixes thanks to @lipkau!'
100100

101-
} # End of PSData hashtable
101+
} # End of PSData hashtable
102102

103-
} # End of PrivateData hashtable
103+
} # End of PrivateData hashtable
104104

105-
# HelpInfo URI of this module
106-
# HelpInfoURI = ''
105+
# HelpInfo URI of this module
106+
# HelpInfoURI = ''
107107

108-
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
109-
# DefaultCommandPrefix = ''
108+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
109+
# DefaultCommandPrefix = ''
110110

111111
}
Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
# Idea from http://stackoverflow.com/questions/7468707/deep-copy-a-dictionary-hashtable-in-powershell
2-
# borrowed from http://stackoverflow.com/questions/8982782/does-anyone-have-a-dependency-graph-and-topological-sorting-code-snippet-for-pow
31
function Get-ClonedObject {
2+
<#
3+
.SYNOPSIS
4+
Clones
5+
6+
.DESCRIPTION
7+
Creates a deep copy of the provided object. This is useful for cloning
8+
dependency objects before passing them to dependency scripts, allowing
9+
modifications to the clone without affecting the original object.
10+
11+
.PARAMETER DeepCopyObject
12+
The source object to copy from.
13+
14+
.EXAMPLE
15+
Get-ClonedObject $MyObject
16+
17+
Get a deep copy of $MyObject. This is used to clone dependency objects
18+
before passing them to dependency scripts, so that we can modify the object
19+
without affecting the original.
20+
21+
.NOTES
22+
Idea from https://stackoverflow.com/a/7475744
23+
borrowed from https://stackoverflow.com/q/8982782
24+
25+
BinaryFormatter was removed in .NET 7; use a recursive hashtable clone
26+
instead
27+
#>
428
param($DeepCopyObject)
5-
$memStream = new-object IO.MemoryStream
6-
$formatter = new-object Runtime.Serialization.Formatters.Binary.BinaryFormatter
7-
$formatter.Serialize($memStream,$DeepCopyObject)
8-
$memStream.Position=0
9-
$formatter.Deserialize($memStream)
29+
$clone = @{}
30+
foreach ($key in $DeepCopyObject.Keys) {
31+
$val = $DeepCopyObject[$key]
32+
if ($val -is [hashtable]) {
33+
$clone[$key] = Get-ClonedObject $val
34+
} elseif ($val -is [array]) {
35+
$clone[$key] = $val.Clone()
36+
} else {
37+
$clone[$key] = $val
38+
}
39+
}
40+
$clone
1041
}

PSDepend/Private/Test-PlatformSupport.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
function Test-PlatformSupport {
2-
[cmdletbinding()]
2+
[CmdletBinding()]
33
param(
44
$Type,
5-
[string[]]$Support
5+
[string[]]
6+
$Support
67
)
78

89
# test core/full
910
if('Core' -eq $PSVersionTable.PSEdition) {
10-
if($Support -notcontains 'core') {
11+
# On Windows with PS Core, 'windows' in Support is sufficient (backwards compat with types
12+
# declared before PS Core on Windows was common)
13+
$windowsCoreOk = $IsWindows -and ($Support -contains 'windows')
14+
if(-not $windowsCoreOk -and $Support -notcontains 'core') {
1115
Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [core]. Pull requests welcome!"
1216
return $false
1317
}
14-
}
15-
else { # full windows powershell
18+
} else {
19+
# full windows powershell
1620
if($Support -notcontains 'windows') {
1721
Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [windows]. Pull requests welcome!"
1822
return $false

0 commit comments

Comments
 (0)