Make Invoke-AppVeyorTest run elevated and non-elevated tests separately

- Add RequireAdminOnWindows to the list of blessed tags
- Fix a bug in Get-PesterTag where we accepted 'Slow' as a proper priority
- Fix missed comma in Start-PSPester parameters
- Add documentation about new Pester tag
- Fix finishing logic for Start-PSPester -Unelevate
This commit is contained in:
Sergei Vorobev 2016-09-15 19:33:54 -07:00
parent 339c7d80e4
commit d1d82d03b4
3 changed files with 54 additions and 26 deletions

View file

@ -545,13 +545,19 @@ function Get-PesterTag {
$warnings += "TAGS must be static strings, error in ${fullname}, line $lineno"
}
$values = $vAst.FindAll({$args[0] -is "System.Management.Automation.Language.StringConstantExpressionAst"},$true).Value
$values | %{
if ( $_ -notmatch "CI|FEATURE|SCENARIO|SLOW" ) {
$values | % {
if (@('REQUIREADMINONWINDOWS', 'SLOW') -contains $_) {
# These are valid tags also, but they are not the priority tags
}
elseif (@('CI', 'FEATURE', 'SCENARIO') -contains $_) {
$foundTag = $true
}
else {
$warnings += "${fullname} includes improper tag '$_', line '$lineno'"
}
$alltags[$_]++
}
$foundTag = $true
}
}
}
if ( ! $foundTag ) {
@ -598,7 +604,7 @@ function Start-PSPester {
[switch]$FullCLR,
[string]$binDir = (Split-Path (New-PSOptions -FullCLR:$FullCLR).Output),
[string]$powershell = (Join-Path $binDir 'powershell'),
[string]$Pester = ([IO.Path]::Combine($binDir, "Modules", "Pester"))
[string]$Pester = ([IO.Path]::Combine($binDir, "Modules", "Pester")),
[switch]$Unelevate
)
@ -662,7 +668,7 @@ function Start-PSPester {
$Command += "'" + $Path + "'"
if ($Unelevate)
{
$Command += "; Stop-Transcript; '__THE_END__' > $outputBufferFilePath"
$Command += "; Stop-Transcript; '__UNELEVATED_TESTS_THE_END__' >> $outputBufferFilePath"
}
Write-Verbose $Command
@ -682,15 +688,13 @@ function Start-PSPester {
while ($true)
{
$lines = Get-Content $outputBufferFilePath | Select-Object -Skip $currentLines
$count = ($lines | measure-object).Count
# Write-Verbose "Read $count lines"
$line = $lines | Select-Object -Last 1
if ($line -eq '__THE_END__')
$lines | Write-Host
if ($lines | ? { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
{
break
}
$lines | Write-Host
$count = ($lines | measure-object).Count
if ($count -eq 0)
{
sleep 1

View file

@ -82,6 +82,15 @@ Provides logical grouping of It blocks within a single Describe block. Any Mocks
#### It
The It block is intended to be used inside of a Describe or Context Block. If you are familiar with the AAA pattern (Arrange-Act-Assert), the body of the It block is the appropriate location for an assert. The convention is to assert a single expectation for each It block. The code inside of the It block should throw a terminating error if the expectation of the test is not met and thus cause the test to fail. The name of the It block should expressively state the expectation of the test.
### Admin privileges in tests
Tests that require admin privileges **on windows** should be additionally marked with 'RequireAdminOnWindows' Pester tag.
In the AppVeyor CI, we run two different passes:
- The pass with exclusion of tests with 'RequireAdminOnWindows' tag
- The pass where we run only 'RequireAdminOnWindows' tests
In each case, tests are executed with appropriate privileges.
### Selected Features
#### Test Drive

View file

@ -173,48 +173,63 @@ function Invoke-AppVeyorTest
$env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish -Configuration $buildConfiguration))
Write-Host -Foreground Green 'Run CoreCLR tests'
$testResultsFile = "$pwd\TestsResults.xml"
$testResultsNonAdminFile = "$pwd\TestsResultsNonAdmin.xml"
$testResultsAdminFile = "$pwd\TestsResultsAdmin.xml"
$testResultsFileFullCLR = "$pwd\TestsResults.FullCLR.xml"
if(!(Test-Path "$env:CoreOutput\powershell.exe"))
{
throw "CoreCLR PowerShell.exe was not built"
}
$coreClrTestParams = @{
Tag = @('CI')
ExcludeTag = @('Slow')
Tag = @()
ExcludeTag = @()
Unelevate = $true
}
if(Test-DailyBuild)
if(-not (Test-DailyBuild))
{
Write-Host -Foreground Green 'Running all CorCLR tests..'
$coreClrTestParams.Tag = $null
$coreClrTestParams.ExcludeTag = $null
# Pester doesn't allow Invoke-Pester -TagAll@('CI', 'RequireAdminOnWindows') currently
# https://github.com/pester/Pester/issues/608
# To work-around it, we exlude all categories, but 'CI' from the list
$coreClrTestParams.ExcludeTag += @('Slow', 'Feature', 'Scenario')
Write-Host -Foreground Green 'Running "CI" CoreCLR tests..'
}
else
{
Write-Host -Foreground Green 'Running "CI" CorCLR tests..'
Write-Host -Foreground Green 'Running all CoreCLR tests..'
}
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsFile @coreClrTestParams
Write-Host -Foreground Green 'Upload CoreCLR test results'
Update-AppVeyorTestResults -resultsFile $testResultsFile
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsNonAdminFile @coreClrTestParams
Write-Host -Foreground Green 'Upload CoreCLR Non-Admin test results'
Update-AppVeyorTestResults -resultsFile $testResultsNonAdminFile
$coreClrTestParams.Tag += 'RequireAdminOnWindows'
$coreClrTestParams.Unelevate = $false
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsAdminFile @coreClrTestParams
Write-Host -Foreground Green 'Upload CoreCLR Admin test results'
Update-AppVeyorTestResults -resultsFile $testResultsAdminFile
#
# FullCLR
$env:FullOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -FullCLR))
Write-Host -Foreground Green 'Run FullCLR tests'
$testResultsFileFullCLR = "$pwd\TestsResults.FullCLR.xml"
Start-PSPester -FullCLR -bindir $env:FullOutput -outputFile $testResultsFileFullCLR -Tag $null -path 'test/fullCLR'
Write-Host -Foreground Green 'Upload FullCLR test results'
Update-AppVeyorTestResults -resultsFile $testResultsFileFullCLR
#
# Fail the build, if tests failed
Test-PSPesterResults -TestResultsFile $testResultsFile
@(
$testResultsNonAdminFile,
$testResultsAdminFile,
$testResultsFileFullCLR
) | % {
Test-PSPesterResults -TestResultsFile $_
}
Test-PSPesterResults -TestResultsFile $testResultsFileFullCLR
Set-BuildVariable -Name TestPassed -Value True
}