-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathintegration-tests.ps1
More file actions
213 lines (184 loc) · 8.31 KB
/
Copy pathintegration-tests.ps1
File metadata and controls
213 lines (184 loc) · 8.31 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
#! /usr/bin/env pwsh
#Requires -PSEdition Core
#Requires -Version 7
param()
$ErrorActionPreference = "Stop"
${env:RestoreLockedMode} = "true"
# -------------------------
# Helpers
# -------------------------
function Write-Info([string]$msg) { Write-Host "[INFO] $msg" }
function Write-Warn([string]$msg) { Write-Warning "[WARN] $msg" }
function Pack-And-Install-Tool {
param(
[string]$ToolProject,
[string]$ToolVersion,
[string]$PublishPath,
[string]$ToolPath
)
dotnet pack $ToolProject "-p:PackageVersion=${ToolVersion}" --output $PublishPath
if ($LASTEXITCODE -ne 0) { throw "dotnet pack failed with exit code ${LASTEXITCODE}" }
# Ensure we always use the freshly packed tool version in the local tool-path.
# `dotnet tool install` does not overwrite an existing local tool installation.
dotnet tool uninstall dotnet-stryker --tool-path $ToolPath 2>$null
if ($LASTEXITCODE -ne 0) { Write-Info "dotnet-stryker was not previously installed in '$ToolPath' (continuing)" }
dotnet tool install dotnet-stryker --add-source $PublishPath --allow-downgrade --tool-path $ToolPath --version $ToolVersion
if ($LASTEXITCODE -ne 0) { throw "dotnet tool install failed with exit code ${LASTEXITCODE}" }
}
function Run-Stryker {
param(
[string]$WorkingDirectory,
[string[]]$Arguments = @(),
[bool]$ContinueOnError = $false
)
$effectiveArguments = @(
$Arguments |
Where-Object { $_ -is [string] -and $_.Trim().Length -gt 0 }
)
$argumentText = ($effectiveArguments | ForEach-Object { $_ }) -join ' '
Write-Info "Running dotnet-stryker in '$WorkingDirectory' with args: $argumentText"
Push-Location $WorkingDirectory
try {
if ($effectiveArguments.Count -gt 0) {
& $stryker @effectiveArguments
} else {
& $stryker
}
} finally {
Pop-Location
}
if ($LASTEXITCODE -ne 0) {
if ($ContinueOnError) {
Write-Warn "dotnet-stryker failed in $WorkingDirectory with exit code $LASTEXITCODE (continuing)"
} else {
throw "dotnet-stryker failed in $WorkingDirectory with exit code $LASTEXITCODE"
}
}
}
function Run-ValidationTests {
param(
[string]$TestPath,
[string]$Filter
)
dotnet test $TestPath --filter $Filter
if ($LASTEXITCODE -ne 0) { throw "dotnet test failed with exit code ${LASTEXITCODE}" }
}
function Run-Category {
param(
[string]$Category,
[string]$Runtime,
[string]$RepoRoot
)
# Log chosen category and any OS-specific behavior here
Write-Info "Selected category: $Category"
Write-Info "Selected runtime: $Runtime"
switch ($Category) {
'InitCommand' {
$wd = Join-Path $RepoRoot 'integrationtest\TargetProjects'
Run-Stryker -WorkingDirectory $wd -Arguments @(
'init'
'--config-file'
'InitCommand/test-config.json'
'-p'
'TestProject.csproj'
)
break
}
'SingleTestProject' {
if ($Runtime -eq 'netcore') {
Run-Stryker -WorkingDirectory (Join-Path $RepoRoot 'integrationtest\TargetProjects\NetCore\NetCoreTestProject.XUnit')
} elseif ($Runtime -eq 'netframework') {
$netFrameworkTestProject = Join-Path $RepoRoot 'integrationtest\TargetProjects\NetFramework\FullFrameworkApp.Test'
Run-Stryker -WorkingDirectory $netFrameworkTestProject -Arguments @('--diag')
} else {
throw "Unknown runtime: $Runtime"
}
break
}
'MultipleTestProjects' {
if ($Runtime -ne 'netcore') { throw "MultipleTestProjects only supports runtime 'netcore'." }
$multiWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\NetCore\TargetProject'
if (Test-Path $multiWd) { Run-Stryker -WorkingDirectory $multiWd } else { Write-Warn "Multi test project not found at $multiWd" }
break
}
'MSTestMTP' {
if ($Runtime -ne 'netcore') { throw "MSTestMTP only supports runtime 'netcore'." }
$mtpWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\MicrosoftTestPlatform\UnitTests.MSTest'
if (Test-Path $mtpWd) { Run-Stryker -WorkingDirectory $mtpWd } else { Write-Warn "MTP test project not found at $mtpWd" }
break
}
'XUnitMTP' {
if ($Runtime -ne 'netcore') { throw "XUnitMTP only supports runtime 'netcore'." }
$xunitMtpWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\MicrosoftTestPlatform\UnitTests.XUnit'
if (Test-Path $xunitMtpWd) { Run-Stryker -WorkingDirectory $xunitMtpWd } else { Write-Warn "XUnit MTP test project not found at $xunitMtpWd" }
break
}
'NUnitMTP' {
if ($Runtime -ne 'netcore') { throw "NUnitMTP only supports runtime 'netcore'." }
$nunitMtpWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\MicrosoftTestPlatform\UnitTests.NUnit'
if (Test-Path $nunitMtpWd) { Run-Stryker -WorkingDirectory $nunitMtpWd } else { Write-Warn "NUnit MTP test project not found at $nunitMtpWd" }
break
}
'TUnit' {
if ($Runtime -ne 'netcore') { throw "TUnit only supports runtime 'netcore'." }
$tunitWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\MicrosoftTestPlatform\UnitTests.TUnit'
if (Test-Path $tunitWd) { Run-Stryker -WorkingDirectory $tunitWd } else { Write-Warn "TUnit test project not found at $tunitWd" }
break
}
'MTPSolution' {
if ($Runtime -ne 'netcore') { throw "MTPSolution only supports runtime 'netcore'." }
$mtpSolutionWd = Join-Path $RepoRoot 'integrationtest\TargetProjects'
$mtpSolutionPath = Join-Path $mtpSolutionWd 'MicrosoftTestPlatform.slnx'
if (Test-Path $mtpSolutionPath) { Run-Stryker -WorkingDirectory $mtpSolutionWd -Arguments @('--solution', $mtpSolutionPath, '--test-runner', 'mtp') } else { Write-Warn "MTP Solution not found at $mtpSolutionPath" }
break
}
'WebApiWithOpenApi' {
if ($Runtime -ne 'netcore') { throw "WebApiWithOpenApi only supports runtime 'netcore'." }
$webApiWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\NetCore\WebApiWithOpenApi'
if (Test-Path $webApiWd) { Run-Stryker -WorkingDirectory $webApiWd } else { Write-Warn "WebApiWithOpenApi folder not found at $webApiWd" }
break
}
'Solution' {
if ($Runtime -eq 'netcore') {
$netcoreWd = Join-Path $RepoRoot 'integrationtest\TargetProjects\NetCore'
$solutionPath = Join-Path $netcoreWd 'IntegrationTestApp.sln'
if (Test-Path $solutionPath) { Run-Stryker -WorkingDirectory $netcoreWd -Arguments @('--solution', $solutionPath) } else { Write-Warn "Solution not found at $solutionPath" }
} elseif ($Runtime -eq 'netframework') {
$wd = Join-Path $RepoRoot 'integrationtest\TargetProjects\NetFramework\FullFrameworkApp.Test'
Run-Stryker -WorkingDirectory $wd -Arguments @('--diag')
} else {
throw "Unknown runtime: $Runtime"
}
break
}
Default { throw "Unknown category: $Category" }
}
}
# -------------------------
# Main
# -------------------------
$repoRoot = ${env:GITHUB_WORKSPACE} ?? $PSScriptRoot
$publishPath = Join-Path $repoRoot "publish"
$netCoreTargetPath = Join-Path $repoRoot "integrationtest" "TargetProjects" "NetCore" "NetCoreTestProject.XUnit"
$netfxTargetPath = Join-Path $repoRoot "integrationtest" "TargetProjects" "NetFramework" "FullFrameworkApp.Test"
$testPath = Join-Path $repoRoot "integrationtest" "Validation" "ValidationProject"
$toolPath = Join-Path $repoRoot ".nuget" "tools"
$toolProject = Join-Path $repoRoot "src" "Stryker.CLI" "Stryker.CLI" "Stryker.CLI.csproj"
$toolVersion = "0.0.0-"
if (${env:GITHUB_ACTIONS} -eq "true") { $toolVersion += "github-${env:GITHUB_RUN_NUMBER}" } else { $toolVersion += "localdev" }
$stryker = Join-Path $toolPath "dotnet-stryker"
# Install tool
Pack-And-Install-Tool -ToolProject $toolProject -ToolVersion $toolVersion -PublishPath $publishPath -ToolPath $toolPath
if (${env:GITHUB_ACTIONS} -eq "true") {
$category = ${env:CATEGORY}
$runtime = ${env:RUNTIME}
if (-not $category) { throw "In GitHub Actions the CATEGORY environment variable must be set." }
if (-not $runtime) { throw "In GitHub Actions the RUNTIME environment variable must be set." }
} else {
Write-Info "Not running in GitHub Actions; defaulting to category 'Solution' and runtime 'netcore'"
$category = 'Solution'
$runtime = 'netcore'
}
$testFilter = "Category=$category&Runtime=$runtime"
Run-Category -Category $category -Runtime $runtime -RepoRoot $repoRoot
Run-ValidationTests -TestPath $testPath -Filter $testFilter