-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun-ui-tests.ps1
More file actions
264 lines (236 loc) · 11.8 KB
/
Copy pathrun-ui-tests.ps1
File metadata and controls
264 lines (236 loc) · 11.8 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
[CmdletBinding()]
param(
[string]$ExecutablePath,
[string]$Filter = 'TestCategory=UI',
[string]$Logger = 'console;verbosity=normal',
[switch]$NoBuild,
[switch]$ListTests,
[switch]$ConfirmIsolatedProfile,
[string[]]$AdditionalDotNetArguments = @()
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repositoryRoot = $PSScriptRoot
$testProject = Join-Path $repositoryRoot 'tests\FileManager.UiTests\FileManager.UiTests.csproj'
function Resolve-FileManagerExecutable {
param([string]$RequestedPath)
if (-not [string]::IsNullOrWhiteSpace($RequestedPath)) {
# An explicit selection is authoritative so a typo cannot silently run a different executable.
if (-not (Test-Path -LiteralPath $RequestedPath -PathType Leaf)) {
throw "The requested FileManager executable was not found: $RequestedPath"
}
return (Resolve-Path -LiteralPath $RequestedPath).Path
}
$candidates = [System.Collections.Generic.List[string]]::new()
if (-not [string]::IsNullOrWhiteSpace($env:FILEMANAGER_UI_EXE)) {
# Preserve an explicit caller selection before checking this checkout's standard build locations.
$candidates.Add($env:FILEMANAGER_UI_EXE)
}
foreach ($relativePath in @(
'src\vcxproj\salamander\Debug_x64\salamand.exe',
'src\vcxproj\salamander\Release_x64\salamand.exe',
'src\vcxproj\salamander\Debug_x86\salamand.exe',
'src\vcxproj\salamander\Release_x86\salamand.exe'
)) {
# Checkout-relative discovery remains portable across users, drive letters, and repository locations.
$candidates.Add((Join-Path $repositoryRoot $relativePath))
}
foreach ($candidate in $candidates) {
if (-not [string]::IsNullOrWhiteSpace($candidate) -and
(Test-Path -LiteralPath $candidate -PathType Leaf)) {
return (Resolve-Path -LiteralPath $candidate).Path
}
}
# Do not silently fall back to an installed copy: a stale executable makes every native-command test fail misleadingly.
throw 'No checkout salamand.exe was found. Build the current branch or pass -ExecutablePath explicitly.'
}
function Test-FtpUiRuntime {
param([Parameter(Mandatory = $true)][string]$ResolvedExecutable)
$runtimeRoot = Split-Path -Parent $ResolvedExecutable
$requiredFiles = @(
(Join-Path $runtimeRoot 'salmon.exe'),
(Join-Path $runtimeRoot 'plugins\ftp\ftp.spl'),
(Join-Path $runtimeRoot 'plugins\ftp\lang\english.slg')
)
# FTP command IDs exist only after the plug-in loads, so an executable alone is not a valid runtime for the default UI suite.
return @($requiredFiles | Where-Object { -not (Test-Path -LiteralPath $_ -PathType Leaf) }).Count -eq 0
}
function Test-HandoffUiRuntime {
param([Parameter(Mandatory = $true)][string]$ResolvedExecutable)
$runtimeRoot = Split-Path -Parent $ResolvedExecutable
# Delivery Handoff UI tests fail (not skip) without the plug-in, so the focused runner must provide it like FTP.
$requiredFiles = @(
(Join-Path $runtimeRoot 'plugins\handoff\handoff.spl'),
(Join-Path $runtimeRoot 'plugins\handoff\lang\english.slg')
)
return @($requiredFiles | Where-Object { -not (Test-Path -LiteralPath $_ -PathType Leaf) }).Count -eq 0
}
function New-FtpUiTestRuntime {
param(
[Parameter(Mandatory = $true)][string]$ResolvedExecutable,
[Parameter(Mandatory = $true)][string]$StagingRoot,
# Also stage Delivery Handoff when the filter can select its fixtures.
[switch]$IncludeHandoff
)
if ((Test-FtpUiRuntime $ResolvedExecutable) -and (-not $IncludeHandoff -or (Test-HandoffUiRuntime $ResolvedExecutable))) {
return $ResolvedExecutable
}
$sourceRuntimeRoot = Split-Path -Parent $ResolvedExecutable
$repositoryPrefix = ([IO.Path]::GetFullPath($repositoryRoot).TrimEnd('\') + '\')
if (-not $ResolvedExecutable.StartsWith($repositoryPrefix, [StringComparison]::OrdinalIgnoreCase)) {
throw "The selected FileManager runtime is incomplete. Required files include salmon.exe, plugins\ftp\ftp.spl, and plugins\ftp\lang\english.slg beside: $ResolvedExecutable"
}
$configuration = Split-Path -Leaf $sourceRuntimeRoot
$ftpBuildRoot = Join-Path $repositoryRoot "src\plugins\ftp\vcxproj\salamander\$configuration\plugins\ftp"
$ftpPlugin = Join-Path $ftpBuildRoot 'ftp.spl'
$ftpLanguage = Join-Path $ftpBuildRoot 'lang\english.slg'
$crashReporter = Join-Path $sourceRuntimeRoot 'salmon.exe'
$requiredBuildArtifacts = @($crashReporter, $ftpPlugin, $ftpLanguage)
$handoffBuildRoot = Join-Path $repositoryRoot "src\plugins\handoff\vcxproj\salamander\$configuration\plugins\handoff"
$handoffPlugin = Join-Path $handoffBuildRoot 'handoff.spl'
$handoffLanguage = Join-Path $handoffBuildRoot 'lang\english.slg'
if ($IncludeHandoff) {
$requiredBuildArtifacts += @($handoffPlugin, $handoffLanguage)
}
$missingBuildArtifacts = @($requiredBuildArtifacts |
Where-Object { -not (Test-Path -LiteralPath $_ -PathType Leaf) })
if ($missingBuildArtifacts.Count -ne 0) {
throw "The checkout build is incomplete. Build the complete $configuration solution before running UI tests. Missing: $($missingBuildArtifacts -join ', ')"
}
try {
New-Item -ItemType Directory -Path $StagingRoot -Force | Out-Null
foreach ($fileName in @('salamand.exe', 'salmon.exe', 'salbroker.exe')) {
$sourceFile = Join-Path $sourceRuntimeRoot $fileName
if (Test-Path -LiteralPath $sourceFile -PathType Leaf) {
Copy-Item -LiteralPath $sourceFile -Destination $StagingRoot -Force
}
}
foreach ($directoryName in @('lang', 'toolbars', 'utils')) {
$sourceDirectory = Join-Path $sourceRuntimeRoot $directoryName
if (Test-Path -LiteralPath $sourceDirectory -PathType Container) {
Copy-Item -LiteralPath $sourceDirectory -Destination $StagingRoot -Recurse -Force
}
}
$stagedFtpRoot = Join-Path $StagingRoot 'plugins\ftp'
$stagedFtpLanguageRoot = Join-Path $stagedFtpRoot 'lang'
New-Item -ItemType Directory -Path $stagedFtpLanguageRoot -Force | Out-Null
# Stage only runtime payloads from the matching checkout configuration; build intermediates must not leak into the test installation.
Copy-Item -LiteralPath $ftpPlugin -Destination $stagedFtpRoot -Force
Copy-Item -LiteralPath $ftpLanguage -Destination $stagedFtpLanguageRoot -Force
if ($IncludeHandoff) {
$stagedHandoffLanguageRoot = Join-Path $StagingRoot 'plugins\handoff\lang'
New-Item -ItemType Directory -Path $stagedHandoffLanguageRoot -Force | Out-Null
Copy-Item -LiteralPath $handoffPlugin -Destination (Join-Path $StagingRoot 'plugins\handoff') -Force
Copy-Item -LiteralPath $handoffLanguage -Destination $stagedHandoffLanguageRoot -Force
}
$stagedExecutable = Join-Path $StagingRoot 'salamand.exe'
if (-not (Test-FtpUiRuntime $stagedExecutable) -or ($IncludeHandoff -and -not (Test-HandoffUiRuntime $stagedExecutable))) {
throw "The temporary FileManager runtime could not be staged completely below: $StagingRoot"
}
return $stagedExecutable
}
catch {
if (Test-Path -LiteralPath $StagingRoot -PathType Container) {
Remove-Item -LiteralPath $StagingRoot -Recurse -Force
}
throw
}
}
if (-not $ConfirmIsolatedProfile) {
# Explicit acknowledgement keeps interactive UI work out of a normal unattended desktop session.
throw 'Re-run with -ConfirmIsolatedProfile to use the guarded filesystem and registry test sandbox.'
}
if (-not (Test-Path -LiteralPath $testProject -PathType Leaf)) {
throw "The UI test project was not found: $testProject"
}
if ($null -eq (Get-Command dotnet -ErrorAction SilentlyContinue)) {
throw 'dotnet was not found on PATH.'
}
$sandboxParent = Join-Path ([IO.Path]::GetTempPath()) ('OpenSalamanderUiTests-' + [Guid]::NewGuid().ToString('N'))
$testDataRoot = Join-Path $sandboxParent 'filemanager-testdata'
$runtimeStagingRoot = Join-Path $sandboxParent 'runtime'
$resolvedExecutable = Resolve-FileManagerExecutable $ExecutablePath
$ftpRuntimeRequired = [string]::IsNullOrWhiteSpace($Filter) -or
$Filter -match '(?i)(TestCategory\s*=\s*UI|BasicUiTests|UI_007|Ftp|Quick_connect)'
$handoffRuntimeRequired = [string]::IsNullOrWhiteSpace($Filter) -or
$Filter -match '(?i)(TestCategory\s*=\s*UI|Handoff)'
if ($ftpRuntimeRequired -or $handoffRuntimeRequired) {
# Raw Visual Studio output scatters plug-ins by project; use a disposable coherent runtime without modifying the caller's build tree.
$resolvedExecutable = New-FtpUiTestRuntime -ResolvedExecutable $resolvedExecutable -StagingRoot $runtimeStagingRoot `
-IncludeHandoff:$handoffRuntimeRequired
}
elseif (-not (Test-Path -LiteralPath (Join-Path (Split-Path -Parent $resolvedExecutable) 'salmon.exe') -PathType Leaf)) {
# Every UI launch needs its sibling crash reporter even when the selected fixture does not exercise FTP.
throw "The selected FileManager runtime is incomplete; salmon.exe is missing beside: $resolvedExecutable"
}
$configurationRoot = 'Software\Open Salamander\6.0-filemanager-testdata'
$savedEnvironment = @{
FILEMANAGER_UI_ISOLATED = $env:FILEMANAGER_UI_ISOLATED
FILEMANAGER_UI_EXE = $env:FILEMANAGER_UI_EXE
FILEMANAGER_UI_TESTDATA_ROOT = $env:FILEMANAGER_UI_TESTDATA_ROOT
FILEMANAGER_UI_CONFIG_ROOT = $env:FILEMANAGER_UI_CONFIG_ROOT
}
$testExitCode = 1
try {
$env:FILEMANAGER_UI_ISOLATED = '1'
$env:FILEMANAGER_UI_EXE = $resolvedExecutable
$env:FILEMANAGER_UI_TESTDATA_ROOT = $testDataRoot
$env:FILEMANAGER_UI_CONFIG_ROOT = $configurationRoot
$arguments = [System.Collections.Generic.List[string]]::new()
$arguments.Add('test')
$arguments.Add($testProject)
if ($NoBuild) {
# A no-build rerun also avoids restore, which would regenerate ignored NuGet intermediates.
$arguments.Add('--no-build')
$arguments.Add('--no-restore')
}
if ($ListTests) {
$arguments.Add('--list-tests')
}
if (-not [string]::IsNullOrWhiteSpace($Filter)) {
$arguments.Add('--filter')
$arguments.Add($Filter)
}
if (-not [string]::IsNullOrWhiteSpace($Logger)) {
$arguments.Add('--logger')
$arguments.Add($Logger)
}
foreach ($argument in $AdditionalDotNetArguments) {
$arguments.Add($argument)
}
Write-Host 'Running FileManager UI tests'
Write-Host " Project: $testProject"
Write-Host " Executable: $resolvedExecutable"
Write-Host " Sandbox: $testDataRoot"
Write-Host " Filter: $Filter"
Push-Location $repositoryRoot
try {
& dotnet @($arguments.ToArray())
$testExitCode = $LASTEXITCODE
}
finally {
Pop-Location
}
}
finally {
# Restore the caller's shell exactly so focused reruns cannot contaminate later commands.
foreach ($name in $savedEnvironment.Keys) {
$value = $savedEnvironment[$name]
if ($null -eq $value) {
Remove-Item -Path "Env:$name" -ErrorAction SilentlyContinue
}
else {
Set-Item -Path "Env:$name" -Value $value
}
}
if (Test-Path -LiteralPath $runtimeStagingRoot -PathType Container) {
# The temporary runtime contains only files copied by this invocation below its GUID-owned parent.
Remove-Item -LiteralPath $runtimeStagingRoot -Recurse -Force
}
# NUnit removes the marked child on a healthy run; remove only the unique empty parent created above.
if ((Test-Path -LiteralPath $sandboxParent -PathType Container) -and
@(Get-ChildItem -LiteralPath $sandboxParent -Force).Count -eq 0) {
Remove-Item -LiteralPath $sandboxParent
}
}
exit $testExitCode