1+ # Copyright (c) Microsoft Corporation.
2+ # Licensed under the MIT License.
3+
14Describe " Verify macOS Package" {
25 BeforeAll {
36 Write-Verbose " In Describe BeforeAll" - Verbose
47 Import-Module $PSScriptRoot / ../ ../ ../ build.psm1
5-
8+
69 # Find the macOS package
710 $packagePath = $env: PACKAGE_FOLDER
811 if (-not $packagePath ) {
912 $packagePath = Get-Location
1013 }
11-
14+
1215 Write-Verbose " Looking for package in: $packagePath " - Verbose
1316 $package = Get-ChildItem - Path $packagePath - Filter " *.pkg" - ErrorAction SilentlyContinue | Select-Object - First 1
14-
17+
1518 if (-not $package ) {
1619 Write-Warning " No .pkg file found in $packagePath "
1720 } else {
1821 Write-Verbose " Found package: $ ( $package.FullName ) " - Verbose
1922 }
20-
23+
2124 # Set up test directories
2225 $script :package = $package
2326 $script :expandDir = $null
2427 $script :payloadDir = $null
2528 $script :extractedFiles = @ ()
26-
29+
2730 if ($package ) {
2831 # Use TestDrive for temporary directories - pkgutil will create the expand directory
2932 $script :expandDir = Join-Path " TestDrive:" - ChildPath " package-contents-test"
3033 $expandDirResolved = (Resolve-Path " TestDrive:" ).ProviderPath
3134 $script :expandDir = Join-Path $expandDirResolved - ChildPath " package-contents-test"
32-
35+
3336 Write-Verbose " Expanding package to: $ ( $script :expandDir ) " - Verbose
3437 # pkgutil will create the directory itself, so don't pre-create it
3538 Start-NativeExecution {
3639 pkgutil -- expand $package.FullName $script :expandDir
3740 }
38-
41+
3942 # Extract the payload to verify files
4043 $script :payloadDir = Join-Path " TestDrive:" - ChildPath " package-payload-test"
4144 $payloadDirResolved = (Resolve-Path " TestDrive:" ).ProviderPath
4245 $script :payloadDir = Join-Path $payloadDirResolved - ChildPath " package-payload-test"
43-
46+
4447 # Create payload directory since cpio needs it
4548 if (-not (Test-Path $script :payloadDir )) {
4649 $null = New-Item - ItemType Directory - Path $script :payloadDir - Force
4750 }
48-
51+
4952 $componentPkg = Get-ChildItem - Path $script :expandDir - Filter " *.pkg" - Recurse | Select-Object - First 1
5053 if ($componentPkg ) {
5154 Write-Verbose " Extracting payload from: $ ( $componentPkg.FullName ) " - Verbose
@@ -57,40 +60,60 @@ Describe "Verify macOS Package" {
5760 Pop-Location
5861 }
5962 }
60-
63+
6164 # Get all extracted files for verification
6265 $script :extractedFiles = Get-ChildItem - Path $script :payloadDir - Recurse - ErrorAction SilentlyContinue
6366 Write-Verbose " Extracted $ ( $script :extractedFiles.Count ) files" - Verbose
6467 }
6568 }
66-
69+
6770 AfterAll {
6871 # TestDrive automatically cleans up, but we can ensure cleanup happens
6972 # No manual cleanup needed as TestDrive handles it
7073 }
71-
74+
7275 Context " Package existence and structure" {
7376 It " Package file should exist" {
7477 $script :package | Should -Not - BeNullOrEmpty - Because " A .pkg file should be created"
7578 $script :package.Extension | Should - Be " .pkg"
7679 }
77-
80+
81+ It " Package name should follow correct naming convention" {
82+ $script :package | Should -Not - BeNullOrEmpty
83+
84+ # Regex pattern for valid macOS PKG package names.
85+ # Valid examples:
86+ # - powershell-7.4.13-osx-x64.pkg (Intel x64 - note: x64 with hyphens for compatibility)
87+ # - powershell-7.4.13-osx-arm64.pkg (Apple Silicon)
88+ # - powershell-preview-7.6.0-preview.6-osx-x64.pkg
89+ # - powershell-lts-7.4.13-osx-arm64.pkg
90+ $pkgPackageNamePattern = ' ^powershell(-preview|-lts)?-\d+\.\d+\.\d+(-[a-z]+\.\d+)?-osx-(x64|arm64)\.pkg$'
91+
92+ $script :package.Name | Should -Match $pkgPackageNamePattern - Because " Package name should follow the standard naming convention"
93+ }
94+
95+ It " Package name should NOT use x86_64 with underscores" {
96+ $script :package | Should -Not - BeNullOrEmpty
97+
98+ $script :package.Name | Should -Not -Match ' x86_64' - Because " Package should use 'x64' not 'x86_64' (with underscores) for compatibility"
99+ }
100+
78101 It " Package should expand successfully" {
79102 $script :expandDir | Should - Exist
80103 Get-ChildItem - Path $script :expandDir | Should -Not - BeNullOrEmpty
81104 }
82-
105+
83106 It " Package should have a component package" {
84107 $componentPkg = Get-ChildItem - Path $script :expandDir - Filter " *.pkg" - Recurse - ErrorAction SilentlyContinue
85108 $componentPkg | Should -Not - BeNullOrEmpty - Because " Package should contain a component.pkg"
86109 }
87-
110+
88111 It " Payload should extract successfully" {
89112 $script :payloadDir | Should - Exist
90113 $script :extractedFiles | Should -Not - BeNullOrEmpty - Because " Package payload should contain files"
91114 }
92115 }
93-
116+
94117 Context " Required files in package" {
95118 BeforeAll {
96119 $expectedFilePatterns = @ {
@@ -99,31 +122,31 @@ Describe "Verify macOS Package" {
99122 " Man page" = " usr/local/share/man/man1/pwsh*.gz"
100123 " Launcher application plist" = " Applications/PowerShell*.app/Contents/Info.plist"
101124 }
102-
125+
103126 $testCases = @ ()
104127 foreach ($key in $expectedFilePatterns.Keys ) {
105128 $testCases += @ {
106129 Description = $key
107130 Pattern = $expectedFilePatterns [$key ]
108131 }
109132 }
110-
133+
111134 $script :testCases = $testCases
112135 }
113-
136+
114137 It " Should contain <Description>" - TestCases $script :testCases {
115138 param ($Description , $Pattern )
116-
139+
117140 $found = $script :extractedFiles | Where-Object { $_.FullName -like " *$Pattern *" }
118141 $found | Should -Not - BeNullOrEmpty - Because " $Description should exist in the package at path matching '$Pattern '"
119142 }
120143 }
121-
144+
122145 Context " PowerShell binary verification" {
123146 It " PowerShell executable should be executable" {
124147 $pwshBinary = $script :extractedFiles | Where-Object { $_.FullName -like " */pwsh" -and $_.FullName -like " */microsoft/powershell/*" }
125148 $pwshBinary | Should -Not - BeNullOrEmpty
126-
149+
127150 # Check if file has executable permissions (on Unix-like systems)
128151 if ($IsLinux -or $IsMacOS ) {
129152 $permissions = (Get-Item $pwshBinary [0 ].FullName).UnixFileMode
@@ -132,27 +155,27 @@ Describe "Verify macOS Package" {
132155 }
133156 }
134157 }
135-
158+
136159 Context " Launcher application" {
137160 It " Launcher app should have proper bundle structure" {
138161 $plistFile = $script :extractedFiles | Where-Object { $_.FullName -like " *PowerShell*.app/Contents/Info.plist" }
139162 $plistFile | Should -Not - BeNullOrEmpty
140-
163+
141164 # Verify the bundle has required components
142165 $appPath = Split-Path (Split-Path $plistFile [0 ].FullName - Parent) - Parent
143166 $macOSDir = Join-Path $appPath " Contents/MacOS"
144167 $resourcesDir = Join-Path $appPath " Contents/Resources"
145-
168+
146169 Test-Path $macOSDir | Should - Be $true - Because " App bundle should have Contents/MacOS directory"
147170 Test-Path $resourcesDir | Should - Be $true - Because " App bundle should have Contents/Resources directory"
148171 }
149-
172+
150173 It " Launcher script should exist and be executable" {
151- $launcherScript = $script :extractedFiles | Where-Object {
152- $_.FullName -like " *PowerShell*.app/Contents/MacOS/PowerShell.sh"
174+ $launcherScript = $script :extractedFiles | Where-Object {
175+ $_.FullName -like " *PowerShell*.app/Contents/MacOS/PowerShell.sh"
153176 }
154177 $launcherScript | Should -Not - BeNullOrEmpty - Because " Launcher script should exist"
155-
178+
156179 if ($IsLinux -or $IsMacOS ) {
157180 $permissions = (Get-Item $launcherScript [0 ].FullName).UnixFileMode
158181 $permissions.ToString () | Should -Match ' x' - Because " Launcher script should have execute permissions"
0 commit comments