-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
196 lines (164 loc) · 7.74 KB
/
Copy pathtest.ps1
File metadata and controls
196 lines (164 loc) · 7.74 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
# -----------------------------------------------------------------------
# Mud.HttpUtils 测试脚本
# 用法: .\test.ps1 [配置] [过滤器] [-AOT] [-AotStrictMode] [-FullTrim] [-PackageRef]
# 示例: .\test.ps1 Debug
# .\test.ps1 Debug "Resilience"
# .\test.ps1 -AOT # AOT 发布 + 运行验证(AotVerificationDemo)
# .\test.ps1 -AOT -AotStrictMode # 严格模式(-p:AotStrictMode=true)
# .\test.ps1 -AOT -AotStrictMode -FullTrim # 追加 TrimMode=full 场景
# .\test.ps1 -AOT -AotStrictMode -PackageRef # 追加 NuGet 消费方场景(需先 dotnet pack)
# -----------------------------------------------------------------------
param(
[string]$Configuration = "Debug",
[string]$Filter = "",
[switch]$AOT,
[switch]$AotStrictMode,
[switch]$FullTrim,
[switch]$PackageRef
)
$ErrorActionPreference = "Stop"
$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Mud.HttpUtils 测试脚本" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# 还原依赖
Write-Host "还原依赖..." -ForegroundColor Yellow
dotnet restore $RootDir\Mud.HttpUtils.slnx
if ($LASTEXITCODE -ne 0) {
Write-Host "还原依赖失败!" -ForegroundColor Red
exit 1
}
Write-Host "还原完成" -ForegroundColor Green
Write-Host ""
# 构建项目
Write-Host "构建项目..." -ForegroundColor Yellow
dotnet build $RootDir\Mud.HttpUtils.slnx -c $Configuration --no-restore
if ($LASTEXITCODE -ne 0) {
Write-Host "构建失败!" -ForegroundColor Red
exit 1
}
Write-Host "构建完成" -ForegroundColor Green
Write-Host ""
# 测试项目列表
$TestProjects = @(
"Tests/Mud.HttpUtils.Client.Tests",
"Tests/Mud.HttpUtils.Resilience.Tests",
"Tests/Mud.HttpUtils.Generator.Tests",
"Tests/Mud.HttpUtils.CodeFixes.Tests",
"Tests/Mud.HttpUtils.Integration.Tests",
"Tests/Mud.HttpUtils.OpenTelemetry.Tests",
"Tests/Mud.HttpUtils.JsonContextScaffolder.Tests",
"Tests/Mud.HttpUtils.Tests"
)
$TotalPassed = 0
$TotalFailed = 0
$FailedProjects = @()
foreach ($testProject in $TestProjects) {
$csproj = Join-Path $RootDir "$testProject/*.csproj"
if (-not (Test-Path (Join-Path $RootDir $testProject))) {
Write-Host "跳过 (未找到测试项目): $testProject" -ForegroundColor DarkGray
continue
}
Write-Host "测试: $testProject" -ForegroundColor Yellow
$filterArg = ""
if (-not [string]::IsNullOrWhiteSpace($Filter)) {
$filterArg = "--filter `"$Filter`""
}
# 说明:不再使用 --no-build。原因:test.ps1 的 $TestProjects 列表中包含
# Tests/Mud.HttpUtils.Tests —— 该工程不在 Mud.HttpUtils.slnx(解决方案构建不会产出其 DLL),
# 旧共享输出布局下靠 Tests/bin 的历史遗留产物侥幸通过;Directory.Build.props 已改为
# 各 .Tests 项目独立输出目录后,该路径不再有遗留产物,--no-build 会直接失败。
# 现在各测试项目输出目录互相隔离(并行构建不会互锁),dotnet test 自带增量构建:
# 已由 slnx 构建过的项目按 MSBuild up-to-date 直接跳过,未构建的(如 Mud.HttpUtils.Tests)
# 自动补齐,语义最稳。
$command = "dotnet test `"$RootDir\$testProject`" -c $Configuration --verbosity normal $filterArg"
Invoke-Expression $command
if ($LASTEXITCODE -ne 0) {
Write-Host " 失败: $testProject" -ForegroundColor Red
$FailedProjects += $testProject
} else {
Write-Host " 通过: $testProject" -ForegroundColor Green
}
Write-Host ""
}
Write-Host "========================================" -ForegroundColor Cyan
if ($FailedProjects.Count -gt 0) {
Write-Host " 测试完成,以下项目失败:" -ForegroundColor Red
foreach ($p in $FailedProjects) {
Write-Host " - $p" -ForegroundColor Red
}
exit 1
} else {
Write-Host " 所有测试通过!" -ForegroundColor Green
}
Write-Host "========================================" -ForegroundColor Cyan
# ──────────────────────────────────────────────
# Native AOT 发布验证(可选,通过 -AOT 参数触发)
# ──────────────────────────────────────────────
if ($AOT) {
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Native AOT 发布验证" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
$Rid = if ($IsLinux) { "linux-x64" } elseif ($IsMacOS) { "osx-x64" } else { "win-x64" }
Write-Host "[INFO] 本机仅验证 RID=$Rid;win-x64/linux-x64/osx-x64 的全 RID 覆盖由 CI OS 矩阵负责。" -ForegroundColor DarkGray
# Demo 列表(按开关追加)
$demoList = @(
@{ Name = "AotVerificationDemo"; Path = "Demos/AotVerificationDemo/AotVerificationDemo.csproj" }
)
if ($FullTrim) {
$demoList += @{ Name = "AotFullTrimVerificationDemo"; Path = "Demos/AotFullTrimVerificationDemo/AotFullTrimVerificationDemo.csproj" }
}
if ($PackageRef) {
Write-Host "[INFO] -PackageRef 需先执行 dotnet pack 生成 NuGet 包到 artifacts/。" -ForegroundColor DarkGray
$demoList += @{ Name = "AotPackageRefDemo"; Path = "Demos/AotPackageRefDemo/AotPackageRefDemo.csproj" }
}
# 严格模式参数(-p:AotStrictMode=true 使 AOT 相关诊断升级为错误;清单定义在 Directory.Build.targets)
$extraArgs = @()
if ($AotStrictMode) {
$extraArgs += "-p:AotStrictMode=true"
Write-Host "[INFO] 已启用 AOT 严格模式(AotStrictMode=true)。" -ForegroundColor DarkGray
}
$tfmList = @("net8.0", "net10.0")
foreach ($demo in $demoList) {
$demoName = $demo.Name
$demoCsproj = Join-Path $RootDir $demo.Path
$demoDir = Split-Path -Parent $demoCsproj
if (-not (Test-Path $demoCsproj)) {
Write-Host " 跳过 (未找到 Demo): $demoName" -ForegroundColor DarkGray
continue
}
foreach ($tfm in $tfmList) {
Write-Host "发布 AOT: $demoName ($tfm)..." -ForegroundColor Yellow
$publishArgs = @("publish", $demoCsproj, "-c", "Release", "-f", $tfm, "-r", $Rid) + $extraArgs
& dotnet @publishArgs
if ($LASTEXITCODE -ne 0) {
Write-Host " AOT 发布失败: $demoName ($tfm)!" -ForegroundColor Red
exit 1
}
$binPath = Join-Path $demoDir "bin/Release/$tfm/$Rid/publish/$demoName"
if ($Rid -eq "win-x64") {
$binPath += ".exe"
}
if (-not (Test-Path $binPath)) {
Write-Host " 二进制未找到: $binPath" -ForegroundColor Red
exit 1
}
Write-Host "运行 AOT 二进制: $demoName ($tfm)..." -ForegroundColor Yellow
$output = & $binPath 2>&1
$outputStr = $output -join "`n"
Write-Host $outputStr
if ($outputStr -match "AOT_OK") {
Write-Host " AOT 运行时验证通过: $demoName ($tfm)" -ForegroundColor Green
} else {
Write-Host " AOT 运行时验证失败: $demoName ($tfm) - 未找到 AOT_OK" -ForegroundColor Red
exit 1
}
Write-Host ""
}
}
Write-Host " AOT 验证全部通过!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
}