-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
233 lines (195 loc) · 8.53 KB
/
test.ps1
File metadata and controls
233 lines (195 loc) · 8.53 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
$ErrorActionPreference = "Stop"
$outputDir = Join-Path $PSScriptRoot "build"
$testExe = Join-Path $outputDir "mini_click_tests.exe"
$compiler = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe"
$temporaryRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("MiniClickInstallTests-" + [System.Guid]::NewGuid().ToString("N"))
$temporaryInstallDir = Join-Path $temporaryRoot "install"
$unexpectedInstallDir = Join-Path ([System.IO.Path]::GetPathRoot($temporaryRoot)) ("MiniClickUnexpected-" + [System.Guid]::NewGuid().ToString("N"))
$arbitraryTemporaryDir = Join-Path ([System.IO.Path]::GetTempPath()) ("MiniClickArbitrary-" + [System.Guid]::NewGuid().ToString("N"))
$sources = @(Get-ChildItem -LiteralPath (Join-Path $PSScriptRoot "src") -Filter "*.cs" -File | Sort-Object Name | Select-Object -ExpandProperty FullName)
if (-not (Test-Path -LiteralPath $compiler)) {
throw "csc.exe not found: $compiler"
}
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null
try {
& (Join-Path $PSScriptRoot "build.ps1") | Out-Null
Add-Type -AssemblyName System.Drawing
$logoPath = Join-Path $PSScriptRoot "assets\miniclick-logo-512.png"
$iconPath = Join-Path $PSScriptRoot "assets\miniclick.ico"
$builtExe = Join-Path $outputDir "mini_click.exe"
$logo = [System.Drawing.Bitmap]::FromFile($logoPath)
try {
if ($logo.Width -ne 512 -or $logo.Height -ne 512) {
throw "MiniClick production logo must be 512x512."
}
if ($logo.GetPixel(0, 0).A -ne 0) {
throw "MiniClick production logo must keep transparent corners."
}
}
finally {
$logo.Dispose()
}
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($builtExe)
if ($null -eq $icon) {
throw "MiniClick executable does not expose an application icon."
}
$icon.Dispose()
$resourceNames = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($builtExe).GetManifestResourceNames()
if ($resourceNames -notcontains "MiniClick.Assets.Logo.png") {
throw "MiniClick executable does not embed its logo resource."
}
Write-Host "PASS generated logo alpha, embedded PNG resource, and executable icon"
& $compiler `
/nologo `
/target:exe `
/platform:x64 `
/optimize+ `
/reference:System.Windows.Forms.dll `
/reference:System.Drawing.dll `
/reference:System.Runtime.Serialization.dll `
/main:MiniClick.Tests.TestProgram `
/out:$testExe `
$sources `
(Join-Path $PSScriptRoot "tests\MiniClick.Tests.cs")
if ($LASTEXITCODE -ne 0) {
throw "MiniClick test build failed."
}
& $testExe
if ($LASTEXITCODE -ne 0) {
throw "MiniClick tests failed."
}
$checkProcess = Start-Process `
-FilePath (Join-Path $outputDir "mini_click.exe") `
-ArgumentList "--check" `
-WindowStyle Hidden `
-Wait `
-PassThru
if ($checkProcess.ExitCode -ne 0) {
throw "MiniClick check mode failed."
}
$hookCheckProcess = Start-Process `
-FilePath (Join-Path $outputDir "mini_click.exe") `
-ArgumentList "--hook-check" `
-WindowStyle Hidden `
-Wait `
-PassThru
if ($hookCheckProcess.ExitCode -ne 0) {
throw "MiniClick hook check mode failed."
}
Write-Host "PASS keyboard and mouse hooks install and detach cleanly"
$uiCheckProcess = Start-Process `
-FilePath (Join-Path $outputDir "mini_click.exe") `
-ArgumentList "--ui-check" `
-WindowStyle Hidden `
-Wait `
-PassThru
if ($uiCheckProcess.ExitCode -ne 0) {
throw "MiniClick UI check mode failed."
}
Write-Host "PASS interface constructs with two tabs, embedded logo, and bounded non-overlapping card layout"
$helpProcess = Start-Process `
-FilePath (Join-Path $outputDir "mini_click.exe") `
-ArgumentList "--help" `
-WindowStyle Hidden `
-Wait `
-PassThru
if ($helpProcess.ExitCode -ne 0) {
throw "MiniClick help mode failed."
}
$invalidProcess = Start-Process `
-FilePath (Join-Path $outputDir "mini_click.exe") `
-ArgumentList "--unknown" `
-WindowStyle Hidden `
-Wait `
-PassThru
if ($invalidProcess.ExitCode -eq 0) {
throw "MiniClick should reject unknown options."
}
& (Join-Path $PSScriptRoot "install.ps1") `
-InstallDir $temporaryInstallDir `
-SkipBuildAndTest `
-WhatIf | Out-Null
if (Test-Path -LiteralPath $temporaryInstallDir) {
throw "MiniClick installation preview mutated temporary state."
}
Write-Host "PASS installation preview is non-mutating"
New-Item -ItemType Directory -Force -Path $temporaryInstallDir | Out-Null
$legacyFile = Join-Path $temporaryInstallDir "legacy-version.txt"
Set-Content -LiteralPath $legacyFile -Value "obsolete"
& (Join-Path $PSScriptRoot "install.ps1") `
-InstallDir $temporaryInstallDir `
-SkipBuildAndTest | Out-Null
$installedExe = Join-Path $temporaryInstallDir "mini_click.exe"
if (-not (Test-Path -LiteralPath $installedExe)) {
throw "MiniClick isolated installation did not copy the executable."
}
if (Test-Path -LiteralPath $legacyFile) {
throw "MiniClick isolated installation preserved a legacy file."
}
Write-Host "PASS isolated install removes legacy files and copies executable"
& (Join-Path $PSScriptRoot "uninstall.ps1") `
-InstallDir $temporaryInstallDir `
-WhatIf | Out-Null
if (-not (Test-Path -LiteralPath $installedExe)) {
throw "MiniClick uninstallation preview mutated temporary state."
}
Write-Host "PASS uninstallation preview is non-mutating"
& (Join-Path $PSScriptRoot "uninstall.ps1") `
-InstallDir $temporaryInstallDir | Out-Null
if (Test-Path -LiteralPath $temporaryInstallDir) {
throw "MiniClick isolated uninstallation left state behind."
}
Write-Host "PASS isolated uninstall removes executable"
$productionPreview = & (Join-Path $PSScriptRoot "install.ps1") -WhatIf
if ($productionPreview.Applied) {
throw "MiniClick production installation preview reported an applied mutation."
}
if ($productionPreview.InstalledExe) {
throw "MiniClick production registration should not preserve a copied executable."
}
if (-not [System.String]::Equals($productionPreview.ShortcutTarget, $builtExe, [System.StringComparison]::OrdinalIgnoreCase)) {
throw "MiniClick production shortcut preview does not target the current build."
}
Write-Host "PASS production registration preview targets only the current build"
try {
& (Join-Path $PSScriptRoot "install.ps1") -SkipBuildAndTest -WhatIf | Out-Null
throw "MiniClick accepted SkipBuildAndTest for the real installation."
}
catch {
if ($_.Exception.Message -notlike "SkipBuildAndTest is allowed only*") {
throw
}
}
Write-Host "PASS test-only build bypass refuses real installation"
try {
& (Join-Path $PSScriptRoot "install.ps1") -InstallDir $unexpectedInstallDir -WhatIf | Out-Null
throw "MiniClick accepted an unexpected installation directory."
}
catch {
if ($_.Exception.Message -notlike "Refusing to install into an unexpected target:*") {
throw
}
}
Write-Host "PASS unexpected installation directory rejected"
try {
& (Join-Path $PSScriptRoot "uninstall.ps1") -InstallDir $arbitraryTemporaryDir -WhatIf | Out-Null
throw "MiniClick accepted an arbitrary temporary uninstallation directory."
}
catch {
if ($_.Exception.Message -notlike "Refusing to uninstall an unexpected target:*") {
throw
}
}
Write-Host "PASS arbitrary temporary uninstallation directory rejected"
}
finally {
Remove-Item -LiteralPath $testExe -Force -ErrorAction SilentlyContinue
$resolvedTemporaryRoot = [System.IO.Path]::GetFullPath($temporaryRoot)
$temporaryBase = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath()).TrimEnd([System.IO.Path]::DirectorySeparatorChar)
$temporaryPrefix = Join-Path $temporaryBase "MiniClickInstallTests-"
$temporaryPattern = '^' + [System.Text.RegularExpressions.Regex]::Escape($temporaryPrefix) + '[0-9a-f]{32}$'
if ($resolvedTemporaryRoot -notmatch $temporaryPattern) {
throw "Refusing to remove an unexpected test directory: $resolvedTemporaryRoot"
}
Remove-Item -LiteralPath $resolvedTemporaryRoot -Recurse -Force -ErrorAction SilentlyContinue
}