forked from microsoft/WindowsAppSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestAll.ps1
132 lines (113 loc) · 3.89 KB
/
TestAll.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
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
<#
.SYNOPSIS
Run the TAEF dlls generated by WinAppSDK
.DESCRIPTION
The TestAll script will take the folder input and look for subfolders containing a .testdef file. WinAppSDK
components define a testdef with the following schema and runs the TAEF dll in the subfolder.
Example:
{
"Tests": [
{
"Description": "This module tests the push notifications component in WinAppSDK.",
"Filename": "PushNotificationTests.dll",
"Parameters": "",
"Architectures": ["x86", "x64", "arm64"],
"Status": "Enabled"
}
]
}
.PARAMETER OutputFolder
Set the base folder for the script to look for testdefs
.PARAMETER Platform
Only run tests for the selected platform
.PARAMETER Configuration
Only run tests the selected configuration
.PARAMETER List
List the tests available in BuildOutput with their settings
.PARAMETER Test
Runs the tests available in BuildOutput
#>
param(
[Parameter(Mandatory=$true)]
[string]$OutputFolder,
[Parameter(Mandatory=$true)]
[string]$Platform,
[Parameter(Mandatory=$true)]
[string]$Configuration,
[Parameter(Mandatory=$false)]
[Switch]$Test,
[Parameter(Mandatory=$false)]
[Switch]$List
)
$StartTime = Get-Date
$lastexitcode = 0
Set-StrictMode -Version 3.0
function Get-TaefTests
{
$configPlat = Join-Path $Configuration $Platform
$outputFolderPath = Join-Path $OutputFolder $configPlat
$tests = @()
foreach ($testdef in (Get-ChildItem -Recurse -Filter "*.testdef" $outputFolderPath))
{
$testJson = Get-Content -Raw $testdef.FullName | ConvertFrom-Json
$count = 0
$baseId = $testdef.BaseName
foreach ($testConfig in $testJson.Tests)
{
$id = $baseId + "-Test$count"
$t = [PSCustomObject]@{}
$t | Add-Member -MemberType NoteProperty -Name 'Test' -Value $id
$t | Add-Member -MemberType NoteProperty -Name 'Description' -Value $testConfig.Description
$t | Add-Member -MemberType NoteProperty -Name 'Filename' -Value $testConfig.Filename
$t | Add-Member -MemberType NoteProperty -Name 'Parameters' -Value $testConfig.Parameters
$t | Add-Member -MemberType NoteProperty -Name 'Architectures' -Value $testConfig.Architectures
$t | Add-Member -MemberType NoteProperty -Name 'Status' -Value $testConfig.Status
$t | Add-Member -MemberType NoteProperty -Name 'TestDef' -Value $testdef.FullName
$tests += $t
$count += 1
}
}
$tests
}
function List-TaefTests
{
$tests = Get-TaefTests
$tests | Sort-Object -Property Test | Format-Table Test,Description,Filename,Parameters,Architectures,Status -AutoSize | Out-String -Width 512
}
function Run-TaefTests
{
$tests = Get-TaefTests
foreach ($test in $tests)
{
Write-Host "$($test.Filename) - $($test.Description)"
$validPlatform = $test.Architectures.Contains($Platform)
$testEnabled = $test.Status -eq "Enabled"
if ($validPlatform -and $testEnabled)
{
$testFolder = Split-Path -parent $test.TestDef
$tePath = Join-Path $testFolder "te.exe"
$dllFile = Join-Path $testFolder $test.Filename
& $tePath $dllFile $test.Parameters
}
elseif (-not($validPlatform))
{
Write-Host "$Platform not listed in supported architectures."
}
elseif (-not($testEnabled))
{
Write-Host "Test is disabled. Not running."
}
}
}
if ($List -eq $true)
{
$null = List-TaefTests
}
if ($Test -eq $true)
{
Run-TaefTests
}
$TotalTime = (Get-Date)-$StartTime
$TotalMinutes = $TotalTime.Minutes
$TotalSeconds = $TotalTime.Seconds
Write-Host "Total Running Time: $TotalMinutes minutes and $TotalSeconds seconds"