-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun-LaunchTests.ps1
More file actions
248 lines (221 loc) · 10.4 KB
/
Run-LaunchTests.ps1
File metadata and controls
248 lines (221 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using namespace System.Collections.Generic
# ─────────────────────────────────────────────────────────────────────────────────────────────
# Region - INTERACTIVE LAUNCH TESTS (Layer 3)
# ─────────────────────────────────────────────────────────────────────────────────────────────
#
# Walks through every meaningful parameter combination, launching the real script so that
# RegEdit or Registry Finder actually opens. You are the oracle: approve each UAC prompt,
# check the window opened to the correct key, close it, then press P(ass) or F(ail).
#
# This is the test layer that Pester cannot automate, because each run requires a UAC
# click and visual verification of the regedit window state.
#
# Usage:
# .\Run-LaunchTests.ps1 # run every scenario
# .\Run-LaunchTests.ps1 -Only RegEdit # only regedit scenarios
# .\Run-LaunchTests.ps1 -Only Finder # only Registry Finder scenarios
# .\Run-LaunchTests.ps1 -Skip 1,2 # skip scenarios by number
#
# EndRegion
[CmdletBinding()]
param(
[ValidateSet('All', 'RegEdit', 'Finder')]
[string] $Only = 'All',
[int[]] $Skip = @()
)
$ErrorActionPreference = 'Stop'
# ─────────────────────────────────────────────────────────────────────────────────────────────
# Region - SCENARIO DEFINITIONS
# ─────────────────────────────────────────────────────────────────────────────────────────────
[string] $scriptUnderTest = Join-Path $PSScriptRoot 'FMRegJump.ps1'
if (-not (Test-Path -LiteralPath $scriptUnderTest)) {
throw "FMRegJump.ps1 not found at: $scriptUnderTest"
}
# Create a sample file + folder for the InputFile-based scenarios
[string] $sampleDir = Join-Path $PSScriptRoot '_launch-test-fixtures'
[string] $sampleFile = Join-Path $sampleDir 'sample.txt'
[string] $sampleFolder = Join-Path $sampleDir 'sample-folder'
New-Item -ItemType Directory -Path $sampleDir -Force | Out-Null
New-Item -ItemType Directory -Path $sampleFolder -Force | Out-Null
Set-Content -LiteralPath $sampleFile -Value 'hello world'
[object[]] $scenarios = @(
@{
Id = 1
App = 'RegEdit'
Desc = 'PresetDestination=Folder via RegEdit'
Expect = 'HKEY_CLASSES_ROOT\Folder'
Splat = @{ PresetDestination = 'Folder'; AppToUse = 'RegEdit' }
}
@{
Id = 2
App = 'RegEdit'
Desc = 'PresetDestination=DirectoryBackground via RegEdit'
Expect = 'HKEY_CLASSES_ROOT\Directory\Background\shell'
Splat = @{ PresetDestination = 'DirectoryBackground'; AppToUse = 'RegEdit' }
}
@{
Id = 3
App = 'RegEdit'
Desc = 'PresetDestination=EnvVariablesCurrentUser via RegEdit'
Expect = 'HKEY_USERS\<your-SID>\Environment'
Splat = @{ PresetDestination = 'EnvVariablesCurrentUser'; AppToUse = 'RegEdit' }
}
@{
Id = 4
App = 'RegEdit'
Desc = 'PresetDestination=MyComputer via RegEdit (-SingleInstance)'
Expect = 'HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell'
Splat = @{
PresetDestination = 'MyComputer'
AppToUse = 'RegEdit'
SingleInstance = $true
}
}
@{
Id = 5
App = 'RegEdit'
Desc = 'InputFile=sample.txt (default SystemFileAssociations root) via RegEdit'
Expect = 'HKCR\SystemFileAssociations\.txt\Shell'
Splat = @{ InputFile = $sampleFile; AppToUse = 'RegEdit' }
}
@{
Id = 6
App = 'RegEdit'
Desc = 'InputFile=sample.txt (-InputFileRoot HKEY_CLASSES_ROOT) via RegEdit'
Expect = 'HKCR\.txt\Shell'
Splat = @{
InputFile = $sampleFile
InputFileRoot = 'HKEY_CLASSES_ROOT'
AppToUse = 'RegEdit'
}
}
@{
Id = 7
App = 'RegEdit'
Desc = 'InputFile=<folder> via RegEdit'
Expect = 'HKCR\Directory\shell'
Splat = @{ InputFile = $sampleFolder; AppToUse = 'RegEdit' }
}
@{
Id = 8
App = 'Finder'
Desc = 'PresetDestination=Folder via Registry Finder'
Expect = 'HKCR\Folder'
Splat = @{ PresetDestination = 'Folder'; AppToUse = 'RegistryFinder' }
}
@{
Id = 9
App = 'Finder'
Desc = 'PresetDestination=DirectoryBackground via Registry Finder'
Expect = 'HKCR\Directory\Background\shell'
Splat = @{
PresetDestination = 'DirectoryBackground'
AppToUse = 'RegistryFinder'
}
}
@{
Id = 10
App = 'Finder'
Desc = 'InputFile=sample.txt via Registry Finder (-SingleInstance)'
Expect = 'HKCR\SystemFileAssociations\.txt\Shell'
Splat = @{
InputFile = $sampleFile
AppToUse = 'RegistryFinder'
SingleInstance = $true
}
}
)
# EndRegion
# ─────────────────────────────────────────────────────────────────────────────────────────────
# Region - INTERACTIVE HARNESS
# ─────────────────────────────────────────────────────────────────────────────────────────────
function Write-Banner {
param([string] $Text, [ConsoleColor] $Color = 'Cyan')
Write-Host ''
Write-Host ('─' * 80) -ForegroundColor $Color
Write-Host $Text -ForegroundColor $Color
Write-Host ('─' * 80) -ForegroundColor $Color
}
function Invoke-Scenario {
param([hashtable] $Scenario)
Write-Banner "Scenario $($Scenario.Id) — $($Scenario.Desc)"
Write-Host "Expected key : " -NoNewline -ForegroundColor Yellow
Write-Host $Scenario.Expect
Write-Host "Invocation : " -NoNewline -ForegroundColor Yellow
Write-Host (".\FMRegJump.ps1 " + (($Scenario.Splat.GetEnumerator() |
ForEach-Object {
if ($_.Value -is [switch] -or $_.Value -eq $true) { "-$($_.Key)" }
else { "-$($_.Key) '$($_.Value)'" }
}) -join ' '))
Write-Host ''
$null = Read-Host "Press Enter to launch (then approve UAC)"
try {
$splat = $Scenario.Splat
& $scriptUnderTest @splat
} catch {
Write-Host "ERROR: $_" -ForegroundColor Red
return [pscustomobject]@{
Id = $Scenario.Id; Desc = $Scenario.Desc; Result = 'ERROR'
Notes = $_.Exception.Message
}
}
Write-Host ''
Write-Host "Verify: Did a registry window open at the expected key?" -ForegroundColor Green
Write-Host " Close it, then record the result." -ForegroundColor Green
Write-Host ''
[string] $verdict = ''
while ($verdict -notin 'p','f','s') {
$verdict = (Read-Host "[P]ass / [F]ail / [S]kip").ToLower()
}
[string] $notes = ''
if ($verdict -in 'f','s') {
$notes = Read-Host "Notes (optional)"
}
return [pscustomobject]@{
Id = $Scenario.Id
Desc = $Scenario.Desc
Result = @{ p = 'PASS'; f = 'FAIL'; s = 'SKIP' }[$verdict]
Notes = $notes
}
}
# EndRegion
# ─────────────────────────────────────────────────────────────────────────────────────────────
# Region - MAIN LOOP
# ─────────────────────────────────────────────────────────────────────────────────────────────
Clear-Host
Write-Banner "FMRegJump Interactive Launch Tests" 'Magenta'
Write-Host "Script under test : $scriptUnderTest"
Write-Host "Filter : $Only"
if ($Skip) { Write-Host "Skipping : $($Skip -join ', ')" }
Write-Host ''
Write-Host "You'll see UAC prompts. Approve them, verify the opened window, then record." `
-ForegroundColor DarkGray
Write-Host ''
[object[]] $filtered = $scenarios | Where-Object {
($Only -eq 'All' -or $_.App -eq $Only) -and ($_.Id -notin $Skip)
}
if (-not $filtered) {
Write-Host "No scenarios match the current filter." -ForegroundColor Yellow
return
}
[List[object]] $results = [List[object]]::new()
foreach ($scn in $filtered) {
$results.Add((Invoke-Scenario -Scenario $scn))
}
# ── Summary ──────────────────────────────────────────────────
Write-Banner "Summary" 'Magenta'
$results | Format-Table -AutoSize Id, Result, Desc, Notes
[int] $pass = ($results | Where-Object Result -EQ 'PASS').Count
[int] $fail = ($results | Where-Object Result -EQ 'FAIL').Count
[int] $skip = ($results | Where-Object Result -EQ 'SKIP').Count
[int] $err = ($results | Where-Object Result -EQ 'ERROR').Count
Write-Host ''
Write-Host "PASS : $pass" -ForegroundColor Green
Write-Host "FAIL : $fail" -ForegroundColor $(if ($fail) { 'Red' } else { 'DarkGray' })
Write-Host "SKIP : $skip" -ForegroundColor DarkGray
Write-Host "ERROR: $err" -ForegroundColor $(if ($err) { 'Red' } else { 'DarkGray' })
# Cleanup fixtures on clean pass
if ($fail -eq 0 -and $err -eq 0) {
Remove-Item -LiteralPath $sampleDir -Recurse -Force -ErrorAction SilentlyContinue
}
# EndRegion