This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGenerateTestSolution.ps1
79 lines (50 loc) · 1.89 KB
/
GenerateTestSolution.ps1
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
# Copyright (c) SourceCode Technology Holdings Inc. All rights reserved.
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$InputSolution,
[Parameter(Mandatory=$False,Position=2)]
[string]$OutputSolution,
[Parameter(Mandatory=$False,Position=3)]
[string]$TestPattern
)
Write-Host "Test Solution Generator version 0.0.1"
Write-Host "Copyright (C) SourceCode Technology Holdings Inc. All rights reserved."
if (-not $OutputSolution) { $OutputSolution = [IO.Path]::ChangeExtension($InputSolution, ".Tests.sln") }
if (Test-Path $OutputSolution) { Remove-Item $OutputSolution }
if (-not $TestPattern) { $TestPattern = '.+?\.Tests' }
$TestPattern = "^\s*Project\("".+?""\)\s*=\s*""$TestPattern"",.+$"
Write-Host "InputSolution: $InputSolution"
Write-Host "OutputSolution: $OutputSolution"
Write-Host "TestPattern: $TestPattern"
$State = 0
foreach ($SlnLine in Get-Content $InputSolution) {
if ($SlnLine -match '^\s*GlobalSection\(NestedProjects\)') {
$State = 4
} elseif ($State -eq 4 -and $SlnLine -match '^\s*EndGlobalSection') {
$State = 3
continue;
} elseif ($SlnLine -match '^\s*Global$') {
$State = 3
}
if ($State -eq 3) {
# Copy build configuration
Add-Content $OutputSolution $SlnLine
} elseif ($SlnLine -match $TestPattern) {
# Copy test projects
$State = 2
Add-Content $OutputSolution $SlnLine
Write-Host "Matched project: $SlnLine"
} elseif ($SlnLine -match '^\s*Project\(') {
#Ignore any preceding non-test projects
$State = 1
} elseif ($State -eq 2) {
# Copy project metadata
Add-Content $OutputSolution $SlnLine
if ($SlnLine -match '^\s*EndProject$') { $State = 1 }
} elseif ($State -eq 0) {
# Copy header
Add-Content $OutputSolution $SlnLine
}
}
Write-Host "Created $OutputSolution."