-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
91 lines (75 loc) · 2.72 KB
/
test.ps1
File metadata and controls
91 lines (75 loc) · 2.72 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
# -----------------------------------------------------------------------
# Mud.HttpUtils 测试脚本
# 用法: .\test.ps1 [配置] [过滤器]
# 示例: .\test.ps1 Debug
# .\test.ps1 Debug "Resilience"
# -----------------------------------------------------------------------
param(
[string]$Configuration = "Debug",
[string]$Filter = ""
)
$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"
)
$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`""
}
$command = "dotnet test `"$RootDir\$testProject`" -c $Configuration --no-build --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