Skip to content
This repository was archived by the owner on Jun 4, 2026. It is now read-only.

Commit 668363f

Browse files
committed
Build: Clean up powershell test
use constants to remove repeated strings
1 parent b470f34 commit 668363f

1 file changed

Lines changed: 20 additions & 31 deletions

File tree

UI/tests/prebuild_windows.test.ps1

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# test that all needed scenarios of the prebuild_windows script work.
2+
13
Describe "Mesen Prebuild Logic Verification" {
24
BeforeAll {
35
# set up sandbox in Temp
@@ -11,6 +13,9 @@ Describe "Mesen Prebuild Logic Verification" {
1113

1214
$script:OldProfile = $env:USERPROFILE
1315
$env:USERPROFILE = "T:\Users\testuser"
16+
17+
$PREBUILD_SCRIPT = "$PSScriptRoot/../prebuild_windows.ps1"
18+
$RUNTIME_ID = "win-x64"
1419
}
1520

1621
AfterAll {
@@ -32,52 +37,36 @@ Describe "Mesen Prebuild Logic Verification" {
3237

3338
Mock Get-ChildItem {
3439
param($Path, $Filter)
35-
# This MUST contain 'runtimes\win-x64\native' or the script's filter fails
3640
if ($Path -like "*\.nuget\*") {
37-
return [PSCustomObject]@{ FullName = "T:\Users\testuser\.nuget\packages\runtimes\win-x64\native\libHarfBuzzSharp.dll" }
41+
return [PSCustomObject]@{ FullName = Join-Path $env:USERPROFILE ".nuget\packages\runtimes\$RUNTIME_ID\native\$Filter" }
3842
}
3943
if ($Filter -eq "MesenCore.dll") {
40-
return [PSCustomObject]@{ FullName = "T:\Users\testuser\code\mesen\bin\win-x64\Release\MesenCore.dll" }
44+
return [PSCustomObject]@{ FullName = Join-Path $env:USERPROFILE "code\mesen\bin\$RUNTIME_ID\Release\MesenCore.dll" }
4145
}
4246
}
4347
}
4448

4549
It "Should handle Relative OutDir (Local Style)" {
4650
$params = @{
47-
ProjectDir = "T:\Users\testuser\code\UI"
51+
ProjectDir = Join-Path $env:USERPROFILE "code\UI"
4852
OutDir = "..\bin\Release"
49-
RuntimeIdentifier = "win-x64"
53+
RuntimeIdentifier = $RUNTIME_ID
5054
}
51-
{ & "$PSScriptRoot/../prebuild_windows.ps1" @params } | Should -Not -Throw
55+
{ & $PREBUILD_SCRIPT @params } | Should -Not -Throw
5256
}
5357

5458
It "Should handle Absolute OutDir (CI Style)" {
5559
$params = @{
56-
ProjectDir = "T:\Users\testuser\code\UI"
57-
OutDir = "T:\Users\testuser\code\bin\Release"
58-
RuntimeIdentifier = "win-x64"
60+
ProjectDir = Join-Path $env:USERPROFILE "code\UI"
61+
OutDir = Join-Path $env:USERPROFILE "code\bin\Release"
62+
RuntimeIdentifier = $RUNTIME_ID
5963
}
60-
{ & "$PSScriptRoot/../prebuild_windows.ps1" @params } | Should -Not -Throw
64+
{ & $PREBUILD_SCRIPT @params } | Should -Not -Throw
6165
}
6266

6367
It "Matches the vcxproj OutDir structure" {
6468
$Repo = "T:\MesenRepo"
6569
$ProjectDir = "$Repo\UI"
66-
# This matches your vcxproj logic: $(SolutionDir)\bin\win-$(PlatformTarget)\$(Configuration)\
67-
$ActualDllLocation = "$Repo\bin\win-x64\Release\MesenCore.dll"
68-
69-
# 1. Mock NuGet (The script hits this first!)
70-
Mock Get-ChildItem {
71-
param($Path, $Filter)
72-
if ($Path -like "*\.nuget\*") {
73-
return [PSCustomObject]@{ FullName = "T:\Users\testuser\.nuget\packages\runtimes\win-x64\native\$Filter" }
74-
}
75-
# 2. Mock MesenCore discovery
76-
if ($Filter -eq "MesenCore.dll") {
77-
return [PSCustomObject]@{ FullName = $ActualDllLocation }
78-
}
79-
return $null
80-
} -Verifiable
8170

8271
Mock Test-Path { return $true }
8372
Mock Copy-Item { }
@@ -88,22 +77,22 @@ Describe "Mesen Prebuild Logic Verification" {
8877

8978
$params = @{
9079
ProjectDir = $ProjectDir
91-
OutDir = "..\bin\win-x64\Release"
92-
RuntimeIdentifier = "win-x64"
80+
OutDir = "..\bin\$RUNTIME_ID\Release"
81+
RuntimeIdentifier = $RUNTIME_ID
9382
}
9483

95-
{ & "$PSScriptRoot/../prebuild_windows.ps1" @params } | Should -Not -Throw
84+
{ & $PREBUILD_SCRIPT @params } | Should -Not -Throw
9685
}
9786

9887
It "Should verify the zip ends up in the ProjectDir" {
99-
$ProjectDir = "T:\Users\testuser\code\mesen\UI"
88+
$ProjectDir = Join-Path $env:USERPROFILE "code\mesen\UI"
10089

10190
$params = @{
10291
ProjectDir = $ProjectDir
10392
OutDir = "T:\Some\Other\Path"
104-
RuntimeIdentifier = "win-x64"
93+
RuntimeIdentifier = $RUNTIME_ID
10594
}
106-
{ & "$PSScriptRoot/../prebuild_windows.ps1" @params } | Should -Not -Throw
95+
{ & $PREBUILD_SCRIPT @params } | Should -Not -Throw
10796

10897
$ExpectedDestination = Join-Path $ProjectDir "Dependencies.zip"
10998

0 commit comments

Comments
 (0)